From 7dc0736b777917bb535799ed224fff1a8853d398 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Wed, 5 Jun 2013 17:22:47 +0200 Subject: [PATCH 1/7] 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} From 52d079eaed514b30240bd768d1b734a6b8593bc8 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Jun 2013 10:45:37 +0200 Subject: [PATCH 2/7] do not include archive table for hashrates, better formatting --- public/include/classes/statistics.class.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 87969707..be101068 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -302,22 +302,15 @@ class Statistics { if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; $stmt = $this->mysqli->prepare(" SELECT - ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ")/3600/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 - WHERE time < NOW() - INTERVAL 1 HOUR AND time > NOW() - INTERVAL 25 HOUR + 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, " . $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 From 232e79f7ad6aeeac574d1ee83e0255f15b4e59d6 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Jun 2013 11:01:04 +0200 Subject: [PATCH 3/7] do not pass two arguments to SQL --- public/include/classes/statistics.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index be101068..edbc24a0 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -311,7 +311,7 @@ class Statistics { 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()) + if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result()) return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_all(MYSQLI_ASSOC), 3600); // Catchall $this->debug->append("Failed to fetch hourly hashrate: " . $this->mysqli->error); From 1bf2e7cf181ca5b9e38c3a6a1a6ba2c24e79b8ef Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Jun 2013 11:47:20 +0200 Subject: [PATCH 4/7] Pre-sort SQL data in array for easy time access This allows us to access the array key as the time. This way the template can properly render the time axis according to current time. --- public/include/classes/statistics.class.php | 8 +++++-- public/include/pages/statistics/user.inc.php | 1 - .../mmcFE/statistics/user/default.tpl | 22 ++++++++++++++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index edbc24a0..a85cb145 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -311,8 +311,12 @@ class Statistics { AND a.id = ? GROUP BY HOUR(time) "); - if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result()) - return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_all(MYSQLI_ASSOC), 3600); + if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result()) { + while ($row = $result->fetch_assoc()) { + $aData[$row['hour']] = $row['hashrate']; + } + return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData, 3600); + } // Catchall $this->debug->append("Failed to fetch hourly hashrate: " . $this->mysqli->error); return false; diff --git a/public/include/pages/statistics/user.inc.php b/public/include/pages/statistics/user.inc.php index 2a713925..2b0b0ed9 100644 --- a/public/include/pages/statistics/user.inc.php +++ b/public/include/pages/statistics/user.inc.php @@ -8,7 +8,6 @@ $aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA' // Propagate content our template $smarty->assign("YOURHASHRATES", $aHourlyHashRates); -$smarty->assign("DIFFICULTY", $dDifficulty); if ($_SESSION['AUTHENTICATED']) { $smarty->assign("CONTENT", "default.tpl"); diff --git a/public/templates/mmcFE/statistics/user/default.tpl b/public/templates/mmcFE/statistics/user/default.tpl index dee8180e..201c783c 100644 --- a/public/templates/mmcFE/statistics/user/default.tpl +++ b/public/templates/mmcFE/statistics/user/default.tpl @@ -1,23 +1,33 @@ {include file="global/block_header.tpl" BLOCK_HEADER="Your Average Hourly Hash Rate" BUTTONS=array(mine,pool,both)} +{if is_array($YOURHASHRATES)}
-{section hashrate $YOURHASHRATES} - -{/section} +{for $i=date('G', time() + 60 * 60) to 23} + +{/for} +{for $i=0 to date('G')} + +{/for} -{section hashrate $YOURHASHRATES} - -{/section} +{for $i=date('G', time() + 60 * 60) to 23} + +{/for} +{for $i=0 to date('G')} + +{/for}
Your Hashrate 
{$YOURHASHRATES[hashrate].hour}{$i}{$i}
{$GLOBAL.USERDATA.username}{$YOURHASHRATES[hashrate].hashrate}{$YOURHASHRATES.$i|default:"0"}{$YOURHASHRATES.$i|default:"0"}
+{else} +

  • No shares available to start calculations
  • +{/if} {include file="global/block_footer.tpl"} From 8fccc8fe3a960a26ce07e541ead21c678ed9e7ea Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Jun 2013 11:57:46 +0200 Subject: [PATCH 5/7] proper time range --- public/templates/mmcFE/statistics/user/default.tpl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/templates/mmcFE/statistics/user/default.tpl b/public/templates/mmcFE/statistics/user/default.tpl index 201c783c..aec27d29 100644 --- a/public/templates/mmcFE/statistics/user/default.tpl +++ b/public/templates/mmcFE/statistics/user/default.tpl @@ -6,21 +6,21 @@ -{for $i=date('G', time() + 60 * 60) to 23} - {$i} +{for $i=date('G') to 23} + {$i}:00 {/for} -{for $i=0 to date('G')} - {$i} +{for $i=0 to date('G', time () - 60 * 60)} + {$i}:00 {/for} {$GLOBAL.USERDATA.username} -{for $i=date('G', time() + 60 * 60) to 23} +{for $i=date('G') to 23} {$YOURHASHRATES.$i|default:"0"} {/for} -{for $i=0 to date('G')} +{for $i=0 to date('G', time() - 60 * 60)} {$YOURHASHRATES.$i|default:"0"} {/for} From aebb97a1d86786568717baaeef77eaa0fb65e2eb Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Jun 2013 12:01:06 +0200 Subject: [PATCH 6/7] use default cashing times --- public/include/classes/statistics.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index a85cb145..4ed74bb4 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -315,7 +315,7 @@ class Statistics { while ($row = $result->fetch_assoc()) { $aData[$row['hour']] = $row['hashrate']; } - return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData, 3600); + return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData); } // Catchall $this->debug->append("Failed to fetch hourly hashrate: " . $this->mysqli->error); From 7e76bb4a63110ffff83d3d2dc4d9ed86c2a4549a Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 6 Jun 2013 12:02:58 +0200 Subject: [PATCH 7/7] properly display username in graph --- public/templates/mmcFE/statistics/user/default.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/templates/mmcFE/statistics/user/default.tpl b/public/templates/mmcFE/statistics/user/default.tpl index aec27d29..dc285321 100644 --- a/public/templates/mmcFE/statistics/user/default.tpl +++ b/public/templates/mmcFE/statistics/user/default.tpl @@ -16,7 +16,7 @@ - {$GLOBAL.USERDATA.username} + {$smarty.session.USERDATA.username} {for $i=date('G') to 23} {$YOURHASHRATES.$i|default:"0"} {/for}