From 2c773fca4285e07c30a3eab0003512d31177fca6 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 17 Jul 2014 08:13:31 +0200 Subject: [PATCH] [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 --- cronjobs/tables_cleanup.php | 2 +- include/classes/statistics.class.php | 40 ++---- include/config/admin_settings.inc.php | 7 + include/pages/statistics/graphs.inc.php | 6 +- .../bootstrap/statistics/graphs/both.tpl | 10 -- .../bootstrap/statistics/graphs/default.tpl | 127 +++++++++++------- .../bootstrap/statistics/graphs/mine.tpl | 8 -- .../bootstrap/statistics/graphs/pool.tpl | 8 -- 8 files changed, 96 insertions(+), 112 deletions(-) delete mode 100644 templates/bootstrap/statistics/graphs/both.tpl delete mode 100644 templates/bootstrap/statistics/graphs/mine.tpl delete mode 100644 templates/bootstrap/statistics/graphs/pool.tpl diff --git a/cronjobs/tables_cleanup.php b/cronjobs/tables_cleanup.php index 231de9be..42189f2f 100755 --- a/cronjobs/tables_cleanup.php +++ b/cronjobs/tables_cleanup.php @@ -77,7 +77,7 @@ $log->logInfo(sprintf($strLogMask, 'purgeArchive', $affected, number_format(micr $start = microtime(true); $status = 'OK'; $message = ''; -$affected = $statistics->purgeUserStats(); +$affected = $statistics->purgeUserStats($setting->getValue('statistics_graphing_days', 1)); if ($affected === false) { $message = 'Failed to delete entries: ' . $statistics->getCronError(); $status = 'ERROR'; diff --git a/include/classes/statistics.class.php b/include/classes/statistics.class.php index 21623142..923d8cfa 100644 --- a/include/classes/statistics.class.php +++ b/include/classes/statistics.class.php @@ -698,19 +698,21 @@ class Statistics extends Base { * @param $account_id int account id * @return data array NOT FINISHED YET **/ - public function getHashrateByAccount($account_id, $format='array') { + public function getHourlyMiningStatsByAccount($account_id, $format='array', $days = 1) { $this->debug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT timestamp, FROM_UNIXTIME(timestamp, '%Y-%m-%d %H:%i') AS time, - AVG(hashrate) AS hashrate + AVG(hashrate) AS hashrate, + AVG(workers) AS workers, + AVG(sharerate) AS sharerate FROM " . $this->getUserStatsTableName() . " - WHERE FROM_UNIXTIME(timestamp) >= DATE_SUB(NOW(), INTERVAL 24 HOUR) + WHERE FROM_UNIXTIME(timestamp) >= DATE_SUB(NOW(), INTERVAL $days DAY) AND account_id = ? - GROUP BY HOUR(FROM_UNIXTIME(timestamp))"); - if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id ) && $stmt->execute() && $result = $stmt->get_result()) { + GROUP BY DAY(FROM_UNIXTIME(timestamp)), HOUR(FROM_UNIXTIME(timestamp))"); + if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) { $aData = $result->fetch_all(MYSQLI_ASSOC); if ($format == 'json') $aData = json_encode($aData); return $this->memcache->setCache(__FUNCTION__ . $account_id . $format, $aData); @@ -718,32 +720,6 @@ class Statistics extends Base { return $this->sqlError(); } - /** - * get Hourly hashrate for the pool - * @param none - * @return data array NOT FINISHED YET - **/ - public function getHashrateForPool($format='array') { - $this->debug->append("STA " . __METHOD__, 4); - if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data; - $stmt = $this->mysqli->prepare(" - SELECT - timestamp, - FROM_UNIXTIME(timestamp, '%Y-%m-%d %T') AS time, - SUM(DISTINCT account_id) - FROM " . $this->getUserStatsTableName() . " - WHERE timestamp >= DATE_SUB(NOW(), INTERVAL 24 HOUR) - GROUP BY HOUR(FROM_UNIXTIME(timestamp))"); - if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) { - // return json_encode(array(time() * 1000, 1000)); - $aData = $result->fetch_all(MYSQLI_ASSOC); - var_dump($aData); - if ($format == 'json') $aData = json_encode($aData); - return $this->memcache->setCache(__FUNCTION__ . $format, $aData); - } - return $this->sqlError(); - } - /** * get user estimated payouts based on share counts * @param value1 mixed Round shares OR share rate @@ -931,7 +907,7 @@ class Statistics extends Base { /** * Purge older entries from our statistics_users table **/ - public function purgeUserStats($days = 7) { + public function purgeUserStats($days = 1) { // Fallbacks if unset $stmt = $this->mysqli->prepare("DELETE FROM " . $this->getUserStatsTableName() . " WHERE FROM_UNIXTIME(timestamp) <= DATE_SUB(NOW(), INTERVAL ? DAY)"); if ($this->checkStmt($stmt) && $stmt->bind_param('i', $days) && $stmt->execute()) diff --git a/include/config/admin_settings.inc.php b/include/config/admin_settings.inc.php index 4f861830..2ae6716e 100644 --- a/include/config/admin_settings.inc.php +++ b/include/config/admin_settings.inc.php @@ -160,6 +160,13 @@ $aSettings['statistics'][] = array( 'name' => 'statistics_ajax_data_interval', 'value' => $setting->getValue('statistics_ajax_data_interval'), 'tooltip' => 'Time in minutes, interval for hashrate and sharerate calculations. Higher intervals allow for better accuracy at a higer server load.' ); +$aSettings['statistics'][] = array( + 'display' => 'Graphing Days', 'type' => 'text', + 'size' => 25, + 'default' => 1, + 'name' => 'statistics_graphing_days', 'value' => $setting->getValue('statistics_graphing_days'), + 'tooltip' => 'How many days to graph out on the statistics -> graphs page.' +); $aSettings['statistics'][] = array( 'display' => 'Block Statistics Count', 'type' => 'text', 'size' => 25, diff --git a/include/pages/statistics/graphs.inc.php b/include/pages/statistics/graphs.inc.php index c970b8d8..a212e941 100644 --- a/include/pages/statistics/graphs.inc.php +++ b/include/pages/statistics/graphs.inc.php @@ -4,11 +4,9 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); if ($user->isAuthenticated()) { - $aHourlyHashRates = $statistics->getHashrateByAccount($_SESSION['USERDATA']['id'], 'json'); - $aPoolHourlyHashRates = $statistics->getHashrateForPool('json'); + $aHourlyMiningStats = $statistics->getHourlyMiningStatsByAccount($_SESSION['USERDATA']['id'], 'json', $setting->getValue('statistics_graphing_days', 1)); } - $smarty->assign("YOURHASHRATES", @$aHourlyHashRates); - $smarty->assign("POOLHASHRATES", @$aPoolHourlyHashRates); + $smarty->assign('YOURMININGSTATS', @$aHourlyMiningStats); } else { $debug->append('Using cached page', 3); } diff --git a/templates/bootstrap/statistics/graphs/both.tpl b/templates/bootstrap/statistics/graphs/both.tpl deleted file mode 100644 index a4943f85..00000000 --- a/templates/bootstrap/statistics/graphs/both.tpl +++ /dev/null @@ -1,10 +0,0 @@ -{if is_array($YOURHASHRATES) && is_array($POOLHASHRATES)} -
-
- Your vs. Pool Hashrate -
-
-
-
-
-{/if} diff --git a/templates/bootstrap/statistics/graphs/default.tpl b/templates/bootstrap/statistics/graphs/default.tpl index 679b6885..b2007f71 100644 --- a/templates/bootstrap/statistics/graphs/default.tpl +++ b/templates/bootstrap/statistics/graphs/default.tpl @@ -1,47 +1,48 @@ @@ -50,17 +51,45 @@ $(function () {
- Stats + Average Hashrate past 24h
- -
- {include file="{$smarty.request.page|escape}/{$smarty.request.action|escape}/mine.tpl"} - {include file="{$smarty.request.page|escape}/{$smarty.request.action|escape}/pool.tpl"} -
+
+
+ +
+
+ + +
+
+
+
+ Average Workers past 24h +
+
+
+
+ +
+
+
+ +
+
+
+
+ Average Sharerate past 24h +
+
+
+
+
diff --git a/templates/bootstrap/statistics/graphs/mine.tpl b/templates/bootstrap/statistics/graphs/mine.tpl deleted file mode 100644 index 91c8c53a..00000000 --- a/templates/bootstrap/statistics/graphs/mine.tpl +++ /dev/null @@ -1,8 +0,0 @@ -
-
- Your Hashrate -
-
-
-
-
diff --git a/templates/bootstrap/statistics/graphs/pool.tpl b/templates/bootstrap/statistics/graphs/pool.tpl deleted file mode 100644 index 95450674..00000000 --- a/templates/bootstrap/statistics/graphs/pool.tpl +++ /dev/null @@ -1,8 +0,0 @@ -
-
- Pool Hashrate -
-
-
-
-