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 @@
  • Ł/usd: {$GLOBAL.ltc_usd}    
  • Pool Hashrate: {$GLOBAL.hashrate / 1000} MH/s    
  • +
  • Pool Sharerate: {$GLOBAL.sharerate} Shares/m    
  • Pool Workers: {$GLOBAL.workers}    
  • diff --git a/sql/mmcfe_ng_structure.sql b/sql/mmcfe_ng_structure.sql index 232f1bcf..b224014f 100644 --- a/sql/mmcfe_ng_structure.sql +++ b/sql/mmcfe_ng_structure.sql @@ -3,7 +3,7 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Erstellungszeit: 13. Mai 2013 um 16:03 +-- Erstellungszeit: 14. Mai 2013 um 16:12 -- Server Version: 5.5.31-0ubuntu0.13.04.1 -- PHP-Version: 5.4.9-4ubuntu2 @@ -17,7 +17,7 @@ SET time_zone = "+00:00"; /*!40101 SET NAMES utf8 */; -- --- Datenbank: `mmcfe_ng` +-- Datenbank: `mmcfe_ng_db` -- -- -------------------------------------------------------- @@ -111,8 +111,10 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( `our_result` enum('Y','N') DEFAULT NULL, `upstream_result` enum('Y','N') DEFAULT NULL, `block_id` int(10) unsigned NOT NULL, + `time` datetime NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `share_id` (`share_id`) + UNIQUE KEY `share_id` (`share_id`), + KEY `time` (`time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes'; -- --------------------------------------------------------