From 50f380c25e2716668f7b8a90aa8ca7371e617996 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 15 Aug 2013 09:14:02 +0200 Subject: [PATCH 1/3] first test to fill with data --- public/include/classes/statistics.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 1452db89..70a2e986 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -406,6 +406,17 @@ class Statistics { while ($row = $result->fetch_assoc()) { $aData[$row['hour']] = $row['hashrate']; } + // We have no data, so we fill with 0 + if (empty($aData)) { + for ($i = 0; $i <= 24; $i++) $aData[$i] = 0; + } else { + $count = -1; + foreach ($aData as $hour => $hashrate) { + $count++; + if ($count == $hour) continue; + $aData[$count] = 0; + } + } return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData); } // Catchall From 14c0535b106a8b13bcd5bcd807a5dab0efd8f6a0 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 15 Aug 2013 09:58:33 +0200 Subject: [PATCH 2/3] Fill empty hours with proper data * Properly sort the array prior to sending it back * Sort from current to one hour earlier for proper data display * Adjusted templates to use new sorted arrays Fixes #606 --- public/include/classes/statistics.class.php | 30 +++++++------------ .../mmcFE/statistics/graphs/both.tpl | 27 ++++++----------- .../mmcFE/statistics/graphs/mine.tpl | 18 ++++------- .../mmcFE/statistics/graphs/pool.tpl | 18 ++++------- 4 files changed, 32 insertions(+), 61 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 70a2e986..d61222b0 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -402,21 +402,11 @@ 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()) { - $aData = array(); - while ($row = $result->fetch_assoc()) { - $aData[$row['hour']] = $row['hashrate']; - } - // We have no data, so we fill with 0 - if (empty($aData)) { - for ($i = 0; $i <= 24; $i++) $aData[$i] = 0; - } else { - $count = -1; - foreach ($aData as $hour => $hashrate) { - $count++; - if ($count == $hour) continue; - $aData[$count] = 0; - } - } + $iStartHour = date('G'); + for ($i = $iStartHour; $i <= 24; $i++) $aData[$i] = 0; + while ($row = $result->fetch_assoc()) $aData[$row['hour']] = $row['hashrate']; + // Fill any non-existing hours with 0 hashrate + for ($i = 0; $i <= 24; $i++) if (!array_key_exists($i, $aData)) $aData[$i] = 0; return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData); } // Catchall @@ -449,10 +439,12 @@ class Statistics { AND time > NOW() - INTERVAL 25 HOUR GROUP BY HOUR(time)"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) { - while ($row = $result->fetch_assoc()) { - $aData[$row['hour']] = $row['hashrate']; - } - return $this->memcache->setCache(__FUNCTION__, @$aData); + $iStartHour = date('G'); + for ($i = $iStartHour; $i <= 24; $i++) $aData[$i] = 0; + while ($row = $result->fetch_assoc()) $aData[$row['hour']] = (int) $row['hashrate']; + // Fill any non-existing hours with 0 hashrate + for ($i = 0; $i <= 24; $i++) if (!array_key_exists($i, $aData)) $aData[$i] = 0; + return $this->memcache->setCache(__FUNCTION__, $aData); } // Catchall $this->debug->append("Failed to fetch hourly hashrate: " . $this->mysqli->error); diff --git a/public/templates/mmcFE/statistics/graphs/both.tpl b/public/templates/mmcFE/statistics/graphs/both.tpl index 878a5b4d..a8011e90 100644 --- a/public/templates/mmcFE/statistics/graphs/both.tpl +++ b/public/templates/mmcFE/statistics/graphs/both.tpl @@ -5,32 +5,23 @@ -{for $i=date('G') to 23} - {$i}:00 -{/for} -{for $i=0 to date('G', time () - 60 * 60)} - {$i}:00 -{/for} +{foreach $YOURHASHRATES as $hour=>$hashrate} + {$hour|default:"0"}:00 +{/foreach} {$smarty.session.USERDATA.username} -{for $i=date('G') to 23} - {$YOURHASHRATES.$i|default:"0"} -{/for} -{for $i=0 to date('G', time() - 60 * 60)} - {$YOURHASHRATES.$i|default:"0"} -{/for} +{foreach $YOURHASHRATES as $hour=>$hashrate} + {$hashrate|default:"0"} +{/foreach} Pool -{for $i=date('G') to 23} - {$POOLHASHRATES.$i|default:"0"} -{/for} -{for $i=0 to date('G', time() - 60 * 60)} - {$POOLHASHRATES.$i|default:"0"} -{/for} +{foreach $POOLHASHRATES as $hour=>$hashrate} + {$hashrate|default:"0"} +{/foreach} diff --git a/public/templates/mmcFE/statistics/graphs/mine.tpl b/public/templates/mmcFE/statistics/graphs/mine.tpl index 4d4259f2..05c8e2b1 100644 --- a/public/templates/mmcFE/statistics/graphs/mine.tpl +++ b/public/templates/mmcFE/statistics/graphs/mine.tpl @@ -5,23 +5,17 @@ -{for $i=date('G') to 23} - {$i}:00 -{/for} -{for $i=0 to date('G', time () - 60 * 60)} - {$i}:00 -{/for} +{foreach $YOURHASHRATES as $hour=>$hashrate} + {$hour|default:"0"}:00 +{/foreach} {$smarty.session.USERDATA.username} -{for $i=date('G') to 23} - {$YOURHASHRATES.$i|default:"0"} -{/for} -{for $i=0 to date('G', time() - 60 * 60)} - {$YOURHASHRATES.$i|default:"0"} -{/for} +{foreach $YOURHASHRATES as $hour=>$hashrate} + {$hashrate|default:"0"} +{/foreach} diff --git a/public/templates/mmcFE/statistics/graphs/pool.tpl b/public/templates/mmcFE/statistics/graphs/pool.tpl index f8d118c7..704dd2bf 100644 --- a/public/templates/mmcFE/statistics/graphs/pool.tpl +++ b/public/templates/mmcFE/statistics/graphs/pool.tpl @@ -5,23 +5,17 @@ -{for $i=date('G') to 23} - {$i}:00 -{/for} -{for $i=0 to date('G', time () - 60 * 60)} - {$i}:00 -{/for} +{foreach $POOLHASHRATES as $hour=>$hashrate} + {$hour|default:"0"}:00 +{/foreach} Pool -{for $i=date('G') to 23} - {$POOLHASHRATES.$i|default:"0"} -{/for} -{for $i=0 to date('G', time() - 60 * 60)} - {$POOLHASHRATES.$i|default:"0"} -{/for} +{foreach $POOLHASHRATES as $hour=>$hashrate} + {$hashrate|default:"0"} +{/foreach} From 1708e5d2b5d5077fb6c06b531a78c4946dfa3321 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 15 Aug 2013 10:03:22 +0200 Subject: [PATCH 3/3] Do not add 24th hour, use 0 hour --- public/include/classes/statistics.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index d61222b0..e4e06167 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -403,10 +403,10 @@ class Statistics { GROUP BY HOUR(time)"); if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $account_id) && $stmt->execute() && $result = $stmt->get_result()) { $iStartHour = date('G'); - for ($i = $iStartHour; $i <= 24; $i++) $aData[$i] = 0; + for ($i = $iStartHour; $i < 24; $i++) $aData[$i] = 0; while ($row = $result->fetch_assoc()) $aData[$row['hour']] = $row['hashrate']; // Fill any non-existing hours with 0 hashrate - for ($i = 0; $i <= 24; $i++) if (!array_key_exists($i, $aData)) $aData[$i] = 0; + for ($i = 0; $i < 24; $i++) if (!array_key_exists($i, $aData)) $aData[$i] = 0; return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData); } // Catchall @@ -440,10 +440,10 @@ class Statistics { GROUP BY HOUR(time)"); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) { $iStartHour = date('G'); - for ($i = $iStartHour; $i <= 24; $i++) $aData[$i] = 0; + for ($i = $iStartHour; $i < 24; $i++) $aData[$i] = 0; while ($row = $result->fetch_assoc()) $aData[$row['hour']] = (int) $row['hashrate']; // Fill any non-existing hours with 0 hashrate - for ($i = 0; $i <= 24; $i++) if (!array_key_exists($i, $aData)) $aData[$i] = 0; + for ($i = 0; $i < 24; $i++) if (!array_key_exists($i, $aData)) $aData[$i] = 0; return $this->memcache->setCache(__FUNCTION__, $aData); } // Catchall