From ef2c9b2c971582f95f3fcd3b1f85a4bb6386224c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 14 May 2013 16:31:18 +0200 Subject: [PATCH] adding archive table for hashrate calculations and added getCurrentShareRate for shares/minute --- public/include/classes/statistics.class.php | 25 ++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 2737c7f8..7ddbf57d 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -38,10 +38,33 @@ class Statistics { } public function getCurrentHashrate() { - $stmt = $this->mysqli->prepare("SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); + $stmt = $this->mysqli->prepare(" + SELECT SUM(hashrate) AS hashrate FROM + ( + SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) AS hashrate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + UNION + SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + ) AS sum + "); if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) { return $result->fetch_object()->hashrate; } + return false; + } + + public function getCurrentShareRate() { + $stmt = $this->mysqli->prepare(" + SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM + ( + SELECT COUNT(id) AS sharerate FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + UNION ALL + SELECT COUNT(id) AS sharerate FROM " . $this->share->getArchiveTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + ) AS sum + "); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() ) { + return $result->fetch_object()->sharerate; + } + return false; } private function checkStmt($bState) {