From 12f60a4567b6235ba43b5c050573926c0c04c1b5 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 14 May 2013 16:10:52 +0200 Subject: [PATCH 1/5] adding DATETIME column for archive --- public/include/classes/share.class.php | 4 ++-- sql/mmcfe_ng_structure.sql | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 5c8fe74e..29b93e29 100644 --- a/public/include/classes/share.class.php +++ b/public/include/classes/share.class.php @@ -93,8 +93,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 shares_archive (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/sql/mmcfe_ng_structure.sql b/sql/mmcfe_ng_structure.sql index 232f1bcf..649220d0 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:10 -- 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,6 +111,7 @@ 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`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes'; From b489d77969e5c8b948d385d9878d17aadfb75e65 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 14 May 2013 16:12:36 +0200 Subject: [PATCH 2/5] adding index to datetime field in archives for later time interval searches --- sql/mmcfe_ng_structure.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/mmcfe_ng_structure.sql b/sql/mmcfe_ng_structure.sql index 649220d0..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: 14. Mai 2013 um 16:10 +-- Erstellungszeit: 14. Mai 2013 um 16:12 -- Server Version: 5.5.31-0ubuntu0.13.04.1 -- PHP-Version: 5.4.9-4ubuntu2 @@ -113,7 +113,8 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( `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'; -- -------------------------------------------------------- From 5c72a859eb4752c2dfb28eb95ee789f7e5baf27a Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 14 May 2013 16:30:11 +0200 Subject: [PATCH 3/5] added secondary table related to shares to share class --- public/include/classes/share.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php index 29b93e29..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,7 +97,7 @@ 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, time) + $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 ?"); From ef2c9b2c971582f95f3fcd3b1f85a4bb6386224c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 14 May 2013 16:31:18 +0200 Subject: [PATCH 4/5] 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) { From 7ebba88f04fbe5fad558332533116b8757c83b49 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 14 May 2013 16:31:41 +0200 Subject: [PATCH 5/5] adding new shares/minute to mini stats --- public/include/smarty_globals.inc.php | 1 + public/templates/mmcFE/global/header.tpl | 1 + 2 files changed, 2 insertions(+) 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}