Skip to content

Commit 2c773fc

Browse files
committed
[UPDATE] Overhauled graphing stats
* [REMOVED] Pool/Combined hashrate graph until we have a proper SQL to generate this data. Volunteers? * [ADDED] Worker and share rate statistics over time * [ADDED] Admin setting to change graphing days (default: 1 day) * [ADDED] Purge entries older than admin setting * [REMOVED] Template files that aren't used anymore
1 parent 226d2c8 commit 2c773fc

File tree

8 files changed

+96
-112
lines changed

8 files changed

+96
-112
lines changed

cronjobs/tables_cleanup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
$start = microtime(true);
7878
$status = 'OK';
7979
$message = '';
80-
$affected = $statistics->purgeUserStats();
80+
$affected = $statistics->purgeUserStats($setting->getValue('statistics_graphing_days', 1));
8181
if ($affected === false) {
8282
$message = 'Failed to delete entries: ' . $statistics->getCronError();
8383
$status = 'ERROR';

include/classes/statistics.class.php

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -698,52 +698,28 @@ public function getTopContributors($type='shares', $limit=15) {
698698
* @param $account_id int account id
699699
* @return data array NOT FINISHED YET
700700
**/
701-
public function getHashrateByAccount($account_id, $format='array') {
701+
public function getHourlyMiningStatsByAccount($account_id, $format='array', $days = 1) {
702702
$this->debug->append("STA " . __METHOD__, 4);
703703
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
704704
$stmt = $this->mysqli->prepare("
705705
SELECT
706706
timestamp,
707707
FROM_UNIXTIME(timestamp, '%Y-%m-%d %H:%i') AS time,
708-
AVG(hashrate) AS hashrate
708+
AVG(hashrate) AS hashrate,
709+
AVG(workers) AS workers,
710+
AVG(sharerate) AS sharerate
709711
FROM " . $this->getUserStatsTableName() . "
710-
WHERE FROM_UNIXTIME(timestamp) >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
712+
WHERE FROM_UNIXTIME(timestamp) >= DATE_SUB(NOW(), INTERVAL $days DAY)
711713
AND account_id = ?
712-
GROUP BY HOUR(FROM_UNIXTIME(timestamp))");
713-
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id ) && $stmt->execute() && $result = $stmt->get_result()) {
714+
GROUP BY DAY(FROM_UNIXTIME(timestamp)), HOUR(FROM_UNIXTIME(timestamp))");
715+
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) {
714716
$aData = $result->fetch_all(MYSQLI_ASSOC);
715717
if ($format == 'json') $aData = json_encode($aData);
716718
return $this->memcache->setCache(__FUNCTION__ . $account_id . $format, $aData);
717719
}
718720
return $this->sqlError();
719721
}
720722

721-
/**
722-
* get Hourly hashrate for the pool
723-
* @param none
724-
* @return data array NOT FINISHED YET
725-
**/
726-
public function getHashrateForPool($format='array') {
727-
$this->debug->append("STA " . __METHOD__, 4);
728-
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data;
729-
$stmt = $this->mysqli->prepare("
730-
SELECT
731-
timestamp,
732-
FROM_UNIXTIME(timestamp, '%Y-%m-%d %T') AS time,
733-
SUM(DISTINCT account_id)
734-
FROM " . $this->getUserStatsTableName() . "
735-
WHERE timestamp >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
736-
GROUP BY HOUR(FROM_UNIXTIME(timestamp))");
737-
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) {
738-
// return json_encode(array(time() * 1000, 1000));
739-
$aData = $result->fetch_all(MYSQLI_ASSOC);
740-
var_dump($aData);
741-
if ($format == 'json') $aData = json_encode($aData);
742-
return $this->memcache->setCache(__FUNCTION__ . $format, $aData);
743-
}
744-
return $this->sqlError();
745-
}
746-
747723
/**
748724
* get user estimated payouts based on share counts
749725
* @param value1 mixed Round shares OR share rate
@@ -931,7 +907,7 @@ public function getCountAllActiveUsers($interval=120) {
931907
/**
932908
* Purge older entries from our statistics_users table
933909
**/
934-
public function purgeUserStats($days = 7) {
910+
public function purgeUserStats($days = 1) {
935911
// Fallbacks if unset
936912
$stmt = $this->mysqli->prepare("DELETE FROM " . $this->getUserStatsTableName() . " WHERE FROM_UNIXTIME(timestamp) <= DATE_SUB(NOW(), INTERVAL ? DAY)");
937913
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $days) && $stmt->execute())

include/config/admin_settings.inc.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@
160160
'name' => 'statistics_ajax_data_interval', 'value' => $setting->getValue('statistics_ajax_data_interval'),
161161
'tooltip' => 'Time in minutes, interval for hashrate and sharerate calculations. Higher intervals allow for better accuracy at a higer server load.'
162162
);
163+
$aSettings['statistics'][] = array(
164+
'display' => 'Graphing Days', 'type' => 'text',
165+
'size' => 25,
166+
'default' => 1,
167+
'name' => 'statistics_graphing_days', 'value' => $setting->getValue('statistics_graphing_days'),
168+
'tooltip' => 'How many days to graph out on the statistics -> graphs page.'
169+
);
163170
$aSettings['statistics'][] = array(
164171
'display' => 'Block Statistics Count', 'type' => 'text',
165172
'size' => 25,

include/pages/statistics/graphs.inc.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
55
$debug->append('No cached version available, fetching from backend', 3);
66
if ($user->isAuthenticated()) {
7-
$aHourlyHashRates = $statistics->getHashrateByAccount($_SESSION['USERDATA']['id'], 'json');
8-
$aPoolHourlyHashRates = $statistics->getHashrateForPool('json');
7+
$aHourlyMiningStats = $statistics->getHourlyMiningStatsByAccount($_SESSION['USERDATA']['id'], 'json', $setting->getValue('statistics_graphing_days', 1));
98
}
10-
$smarty->assign("YOURHASHRATES", @$aHourlyHashRates);
11-
$smarty->assign("POOLHASHRATES", @$aPoolHourlyHashRates);
9+
$smarty->assign('YOURMININGSTATS', @$aHourlyMiningStats);
1210
} else {
1311
$debug->append('Using cached page', 3);
1412
}

templates/bootstrap/statistics/graphs/both.tpl

Lines changed: 0 additions & 10 deletions
This file was deleted.

templates/bootstrap/statistics/graphs/default.tpl

Lines changed: 78 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
<script>
22
$(function () {
3+
var hashChart = Morris.Line({
4+
element: 'hashrate-area-chart',
5+
data: {$YOURMININGSTATS},
6+
xkey: 'time',
7+
ykeys: ['hashrate'],
8+
labels: ['Hashrate'],
9+
pointSize: 1,
10+
hideHover: 'auto',
11+
resize: true,
12+
fillOpacity: 1.00,
13+
lineColors: ['#24A665'],
14+
pointFillColors: ['#24A665'],
15+
pointStrokeColors: ['#24A665']
16+
});
317
4-
// needed for automatic activation of first tab
5-
$(function () {
6-
$('#hashrategraph a:first').tab('show')
7-
})
18+
var workersChart = Morris.Line({
19+
element: 'workers-area-chart',
20+
data: {$YOURMININGSTATS},
21+
xkey: 'time',
22+
ykeys: ['workers'],
23+
labels: ['Workers'],
24+
pointSize: 1,
25+
hideHover: 'auto',
26+
resize: true,
27+
fillOpacity: 1.00,
28+
lineColors: ['#24A665'],
29+
pointFillColors: ['#24A665'],
30+
pointStrokeColors: ['#24A665']
31+
});
832
9-
// You can't draw here chart directly, because it's on hidden tab, instead let's do the workaround
10-
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
11-
if ($(e.target).attr('href') == '#mine' && $('#mine-area-chart').html().length == 0) {
12-
var chart = Morris.Line({
13-
// ID of the element in which to draw the chart.
14-
element: 'mine-area-chart',
15-
data: {$YOURHASHRATES},
16-
xkey: 'time',
17-
ykeys: ['hashrate'],
18-
labels: ['Hashrate'],
19-
pointSize: 1,
20-
hideHover: 'auto',
21-
resize: true,
22-
fillOpacity: 1.00,
23-
lineColors: ['#24A665'],
24-
pointFillColors: ['#24A665'],
25-
pointStrokeColors: ['#24A665']
26-
});
27-
}
28-
if ($(e.target).attr('href') == '#pool' && $('#pool-area-chart').html().length == 0) {
29-
var chart = Morris.Line({
30-
// ID of the element in which to draw the chart.
31-
element: 'pool-area-chart',
32-
data: {$POOLHASHRATES},
33-
xkey: 'time',
34-
ykeys: ['hashrate'],
35-
labels: ['Hashrate'],
36-
pointSize: 1,
37-
hideHover: 'auto',
38-
resize: true,
39-
fillOpacity: 1.00,
40-
lineColors: ['#24A665'],
41-
pointFillColors: ['#24A665'],
42-
pointStrokeColors: ['#24A665']
43-
});
44-
}
33+
var shareCharts= Morris.Line({
34+
element: 'sharerate-area-chart',
35+
data: {$YOURMININGSTATS},
36+
xkey: 'time',
37+
ykeys: ['sharerate'],
38+
labels: ['Sharerate'],
39+
pointSize: 1,
40+
hideHover: 'auto',
41+
resize: true,
42+
fillOpacity: 1.00,
43+
lineColors: ['#24A665'],
44+
pointFillColors: ['#24A665'],
45+
pointStrokeColors: ['#24A665']
4546
});
4647
});
4748
</script>
@@ -50,17 +51,45 @@ $(function () {
5051
<div class="col-lg-12">
5152
<div class="panel panel-info">
5253
<div class="panel-heading">
53-
<i class="fa fa-signal fa-fw"></i> Stats
54+
<i class="fa fa-signal fa-fw"></i> Average Hashrate past 24h
55+
</div>
56+
<div class="panel-body">
57+
<div id="hashrate-area-chart"></div>
58+
</div>
59+
<div class="panel-footer">
60+
Your average hashrate per hour, updated every backend cron run.
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
66+
<div class="row">
67+
<div class="col-lg-12">
68+
<div class="panel panel-info">
69+
<div class="panel-heading">
70+
<i class="fa fa-signal fa-fw"></i> Average Workers past 24h
5471
</div>
5572
<div class="panel-body">
56-
<ul class="nav nav-pills" id="hashrategraph">
57-
<li><a href="#mine" data-toggle="tab">Mine</a></li>
58-
<li><a href="#pool" data-toggle="tab">Pool</a></li>
59-
</ul>
60-
<div class="tab-content">
61-
{include file="{$smarty.request.page|escape}/{$smarty.request.action|escape}/mine.tpl"}
62-
{include file="{$smarty.request.page|escape}/{$smarty.request.action|escape}/pool.tpl"}
63-
</div>
73+
<div id="workers-area-chart"></div>
74+
</div>
75+
<div class="panel-footer">
76+
Your average active workers per hour, updated every backend cron run.
77+
</div>
78+
</div>
79+
</div>
80+
</div>
81+
82+
<div class="row">
83+
<div class="col-lg-12">
84+
<div class="panel panel-info">
85+
<div class="panel-heading">
86+
<i class="fa fa-signal fa-fw"></i> Average Sharerate past 24h
87+
</div>
88+
<div class="panel-body">
89+
<div id="sharerate-area-chart"></div>
90+
</div>
91+
<div class="panel-footer">
92+
Your share rate per hour, updated every backend cron run.
6493
</div>
6594
</div>
6695
</div>

templates/bootstrap/statistics/graphs/mine.tpl

Lines changed: 0 additions & 8 deletions
This file was deleted.

templates/bootstrap/statistics/graphs/pool.tpl

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)