From 6f858188ad53a743307ece3369644e89b618cbf9 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Thu, 13 Jun 2013 22:59:19 +0200
Subject: [PATCH] Adding pool and combined hashrate graphs
* Moving from My Graph to its own section: Hashrate Graphs
* Adding pool hashrate graph
* Adding combined hashrate graph and piechart
Fixes #187
---
public/include/classes/statistics.class.php | 29 ++++++++++++-
.../{user.inc.php => graphs.inc.php} | 2 +
public/templates/mmcFE/global/navigation.tpl | 2 +-
.../mmcFE/statistics/graphs/both.tpl | 43 +++++++++++++++++++
.../mmcFE/statistics/graphs/default.tpl | 5 +++
.../{user/default.tpl => graphs/mine.tpl} | 2 -
.../mmcFE/statistics/graphs/pool.tpl | 31 +++++++++++++
7 files changed, 110 insertions(+), 4 deletions(-)
rename public/include/pages/statistics/{user.inc.php => graphs.inc.php} (74%)
create mode 100644 public/templates/mmcFE/statistics/graphs/both.tpl
create mode 100644 public/templates/mmcFE/statistics/graphs/default.tpl
rename public/templates/mmcFE/statistics/{user/default.tpl => graphs/mine.tpl} (83%)
create mode 100644 public/templates/mmcFE/statistics/graphs/pool.tpl
diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php
index 3bcebcfb..46ab5cb5 100644
--- a/public/include/classes/statistics.class.php
+++ b/public/include/classes/statistics.class.php
@@ -293,7 +293,6 @@ class Statistics {
/**
* get Hourly hashrate for a user
- * Not working yet since I was not able to solve this via SQL queries
* @param account_id int User ID
* @return data array NOT FINISHED YET
**/
@@ -321,6 +320,34 @@ class Statistics {
$this->debug->append("Failed to fetch hourly hashrate: " . $this->mysqli->error);
return false;
}
+
+ /**
+ * get Hourly hashrate for the pool
+ * @param none
+ * @return data array NOT FINISHED YET
+ **/
+ public function getHourlyHashrateByPool() {
+ $this->debug->append("STA " . __METHOD__, 4);
+ if ($data = $this->memcache->get(__FUNCTION__)) return $data;
+ $stmt = $this->mysqli->prepare("
+ SELECT
+ ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000) AS hashrate,
+ HOUR(s.time) AS hour
+ FROM " . $this->share->getTableName() . " AS s
+ WHERE time < NOW() - INTERVAL 1 HOUR
+ 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);
+ }
+ // Catchall
+ $this->debug->append("Failed to fetch hourly hashrate: " . $this->mysqli->error);
+ return false;
+ }
}
$statistics = new Statistics($debug, $mysqli, $config, $share, $user, $block, $memcache);
diff --git a/public/include/pages/statistics/user.inc.php b/public/include/pages/statistics/graphs.inc.php
similarity index 74%
rename from public/include/pages/statistics/user.inc.php
rename to public/include/pages/statistics/graphs.inc.php
index 13b3ba5b..cf62bddf 100644
--- a/public/include/pages/statistics/user.inc.php
+++ b/public/include/pages/statistics/graphs.inc.php
@@ -6,8 +6,10 @@ if (!defined('SECURITY'))
if ($user->isAuthenticated()) {
$aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']);
+ $aPoolHourlyHashRates = $statistics->getHourlyHashrateByPool();
// Propagate content our template
$smarty->assign("YOURHASHRATES", $aHourlyHashRates);
+ $smarty->assign("POOLHASHRATES", $aPoolHourlyHashRates);
$smarty->assign("CONTENT", "default.tpl");
}
?>
diff --git a/public/templates/mmcFE/global/navigation.tpl b/public/templates/mmcFE/global/navigation.tpl
index 9beb87cb..c53f61c7 100644
--- a/public/templates/mmcFE/global/navigation.tpl
+++ b/public/templates/mmcFE/global/navigation.tpl
@@ -5,7 +5,6 @@
@@ -23,6 +22,7 @@
Getting Started
diff --git a/public/templates/mmcFE/statistics/graphs/both.tpl b/public/templates/mmcFE/statistics/graphs/both.tpl
new file mode 100644
index 00000000..ff760be1
--- /dev/null
+++ b/public/templates/mmcFE/statistics/graphs/both.tpl
@@ -0,0 +1,43 @@
+{if is_array($YOURHASHRATES) && is_array($POOLHASHRATES)}
+
+{foreach from=array('area','pie') item=chartType}
+
+ Your vs Pool Hashrate
+
+
+ |
+{for $i=date('G') to 23}
+ {$i}:00 |
+{/for}
+{for $i=0 to date('G', time () - 60 * 60)}
+ {$i}:00 |
+{/for}
+
+
+
+
+ | {$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}
+
+
+ | 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}
+
+{else}
+No shares available to start calculations
+{/if}
diff --git a/public/templates/mmcFE/statistics/graphs/default.tpl b/public/templates/mmcFE/statistics/graphs/default.tpl
new file mode 100644
index 00000000..c325a4c6
--- /dev/null
+++ b/public/templates/mmcFE/statistics/graphs/default.tpl
@@ -0,0 +1,5 @@
+{include file="global/block_header.tpl" BLOCK_HEADER="24h Hashrate Statistics" BUTTONS=array(mine,pool,both)}
+{include file="{$smarty.request.page}/{$smarty.request.action}/mine.tpl"}
+{include file="{$smarty.request.page}/{$smarty.request.action}/pool.tpl"}
+{include file="{$smarty.request.page}/{$smarty.request.action}/both.tpl"}
+{include file="global/block_footer.tpl"}
diff --git a/public/templates/mmcFE/statistics/user/default.tpl b/public/templates/mmcFE/statistics/graphs/mine.tpl
similarity index 83%
rename from public/templates/mmcFE/statistics/user/default.tpl
rename to public/templates/mmcFE/statistics/graphs/mine.tpl
index debbd23a..fe217f2f 100644
--- a/public/templates/mmcFE/statistics/user/default.tpl
+++ b/public/templates/mmcFE/statistics/graphs/mine.tpl
@@ -1,4 +1,3 @@
-{include file="global/block_header.tpl" BLOCK_HEADER="Your Average Hourly Hash Rate" BUTTONS=array(mine,pool,both)}
{if is_array($YOURHASHRATES)}
@@ -30,4 +29,3 @@
{else}
No shares available to start calculations
{/if}
-{include file="global/block_footer.tpl"}
diff --git a/public/templates/mmcFE/statistics/graphs/pool.tpl b/public/templates/mmcFE/statistics/graphs/pool.tpl
new file mode 100644
index 00000000..ba2ed4e5
--- /dev/null
+++ b/public/templates/mmcFE/statistics/graphs/pool.tpl
@@ -0,0 +1,31 @@
+{if is_array($POOLHASHRATES)}
+
+
+ Pool Hashrate
+
+
+ |
+{for $i=date('G') to 23}
+ {$i}:00 |
+{/for}
+{for $i=0 to date('G', time () - 60 * 60)}
+ {$i}:00 |
+{/for}
+
+
+
+
+ | 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}
+
+
+
+
+{else}
+No shares available to start calculations
+{/if}