From 7dc0736b777917bb535799ed224fff1a8853d398 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Wed, 5 Jun 2013 17:22:47 +0200 Subject: [PATCH] First version for new user graphs * Properly calculate hashrate * Remove number formatting, it breaks the graph * Not properly in order based on time but displays correct values Addresses #90 --- public/include/classes/statistics.class.php | 24 +++++++++---------- public/include/pages/statistics/user.inc.php | 10 -------- .../mmcFE/statistics/user/default.tpl | 2 +- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index c261a884..87969707 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -302,22 +302,22 @@ class Statistics { if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(COUNT(s.id) * POW(2, 12)/600/1000) AS hashrate, + ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ")/3600/1000) AS hashrate, HOUR(s.time) AS hour - FROM " . $this->share->getTableName() . " AS s, accounts AS a + FROM " . $this->share->getTableName() . " AS s, accounts AS a WHERE time < NOW() - INTERVAL 1 HOUR AND time > NOW() - INTERVAL 25 HOUR AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) AND a.id = ? - GROUP BY HOUR(time) - UNION ALL - SELECT - ROUND(COUNT(s.id) * POW(2, 12)/600/1000) AS hashrate, - HOUR(s.time) AS hour - FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a - WHERE time < NOW() - INTERVAL 1 HOUR AND time > NOW() - INTERVAL 25 HOUR - AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) - AND a.id = ? - GROUP BY HOUR(time)"); + GROUP BY HOUR(time) + UNION ALL + SELECT + ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ")/3600/1000) AS hashrate, + HOUR(s.time) AS hour + FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a + WHERE time < NOW() - INTERVAL 1 HOUR AND time > NOW() - INTERVAL 25 HOUR + AND a.username = SUBSTRING_INDEX( s.username, '.', 1 ) + AND a.id = ? + GROUP BY HOUR(time)"); if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $account_id, $account_id) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_all(MYSQLI_ASSOC), 3600); // Catchall diff --git a/public/include/pages/statistics/user.inc.php b/public/include/pages/statistics/user.inc.php index 41440b99..2a713925 100644 --- a/public/include/pages/statistics/user.inc.php +++ b/public/include/pages/statistics/user.inc.php @@ -4,16 +4,6 @@ if (!defined('SECURITY')) die('Hacking attempt'); -// Fetch data from litecoind -if ($bitcoin->can_connect() === true){ - $dDifficulty = $bitcoin->getdifficulty(); - $iBlock = $bitcoin->getblockcount(); -} else { - $iDifficulty = 1; - $iBlock = 0; - $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to litecoind RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); -} - $aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']); // Propagate content our template diff --git a/public/templates/mmcFE/statistics/user/default.tpl b/public/templates/mmcFE/statistics/user/default.tpl index ffc5e8c8..dee8180e 100644 --- a/public/templates/mmcFE/statistics/user/default.tpl +++ b/public/templates/mmcFE/statistics/user/default.tpl @@ -14,7 +14,7 @@ {$GLOBAL.USERDATA.username} {section hashrate $YOURHASHRATES} - {$YOURHASHRATES[hashrate].hashrate|number_format} + {$YOURHASHRATES[hashrate].hashrate} {/section}