diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 5c8fe74e..5d8fc276 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -7,6 +7,7 @@ if (!defined('SECURITY')) class Share { private $sError = ''; private $table = 'shares'; + private $tableArchive = 'shares_archive'; private $oUpstream; private $iLastUpstreamId; // This defines each share @@ -26,6 +27,9 @@ class Share { return $this->sError; } + public function getArchiveTableName() { + return $this->tableArchive; + } public function getTableName() { return $this->table; } @@ -93,8 +97,8 @@ class Share { } public function moveArchive($previous_upstream=0, $current_upstream,$block_id) { - $archive_stmt = $this->mysqli->prepare("INSERT INTO shares_archive (share_id, username, our_result, upstream_result, block_id) - SELECT id, username, our_result, upstream_result, ? + $archive_stmt = $this->mysqli->prepare("INSERT INTO $this->tableArchive (share_id, username, our_result, upstream_result, block_id, time) + SELECT id, username, our_result, upstream_result, ?, time FROM $this->table WHERE id BETWEEN ? AND ?"); $delete_stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE id BETWEEN ? AND ?"); 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) { diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 10b97b2b..b707e0d9 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -31,6 +31,7 @@ $aGlobal = array( 'websitename' => $settings->getValue('websitename'), 'ltc_usd' => $settings->getValue('btcesell'), 'hashrate' => $iCurrentPoolHashrate, + 'sharerate' => $statistics->getCurrentShareRate(), 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'statstime' => $settings->getValue('statstime'), diff --git a/public/templates/mmcFE/global/header.tpl b/public/templates/mmcFE/global/header.tpl index 33bc0b85..2d7f1992 100644 --- a/public/templates/mmcFE/global/header.tpl +++ b/public/templates/mmcFE/global/header.tpl @@ -6,6 +6,7 @@