From 4e68de0e5a3be70612576dd481b2eae057f3ba68 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 4 Nov 2013 17:28:03 +0100 Subject: [PATCH 1/2] [FIX] Display issues on SHA coins * [FIX] Estimated shares on various places * [ADDED] Calculate estimated shares based on network diff in stats class * [UPDATED] Themes updated as needed Fixes #819 once merged --- public/include/classes/statistics.class.php | 10 +++++++++- public/include/pages/api/getdashboarddata.inc.php | 2 +- public/include/pages/api/getnavbardata.inc.php | 2 +- public/include/smarty_globals.inc.php | 1 + public/templates/mmcFE/statistics/blocks/default.tpl | 2 +- public/templates/mmcFE/statistics/pool/default.tpl | 2 +- public/templates/mpos/statistics/blocks/default.tpl | 2 +- 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 463c07fa..f3398284 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -759,7 +759,7 @@ class Statistics { SELECT IFNULL(COUNT(id), 0) as count, IFNULL(AVG(difficulty), 0) as average, - IFNULL(ROUND(SUM((difficulty * 65536) / POW(2, (" . $this->config['difficulty'] . " -16))), 0), 0) AS expected, + IFNULL(ROUND(SUM((POW(2, ( 32 - " . $this->config['target_bits'] . " )) * difficulty) / POW(2, (" . $this->config['difficulty'] . " -16))), 0), 0) AS expected, IFNULL(ROUND(SUM(shares)), 0) as shares, IFNULL(SUM(amount), 0) as rewards FROM " . $this->block->getTableName() . " @@ -772,6 +772,14 @@ class Statistics { return false; } + /** + * Caclulate estimated shares based on network difficulty and pool difficulty + * @param dDiff double Network difficulty + * @return shares integer Share count + **/ + public function getEstimatedShares($dDiff) { + return round((POW(2, (32 - $this->config['target_bits'])) * $dDiff) / pow(2, ($this->config['difficulty'] - 16))); + } } diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index 7942092c..35f5eb49 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -80,7 +80,7 @@ $aWorkers = $worker->getWorkers($user_id, $interval); $aPrice = $setting->getValue('price'); // Round progress -$iEstShares = round((65536 * $dDifficulty) / pow(2, ($config['difficulty'] - 16))); +$iEstShares = $statistics->getEstimatedShares($dDifficulty); $dEstPercent = round(100 / $iEstShares * $aRoundShares['valid'], 2); // Output JSON format diff --git a/public/include/pages/api/getnavbardata.inc.php b/public/include/pages/api/getnavbardata.inc.php index 38041737..345dba0d 100644 --- a/public/include/pages/api/getnavbardata.inc.php +++ b/public/include/pages/api/getnavbardata.inc.php @@ -44,7 +44,7 @@ if ($iTotalRoundShares > 0) { } // Round progress -$iEstShares = round((65536 * $dDifficulty) / pow(2, ($config['difficulty'] - 16))); +$iEstShares = $statistics->getEstimatedShares($dDifficulty); $dEstPercent = round(100 / $iEstShares * $aRoundShares['valid'], 2); // Output JSON format diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 630cbed6..42406331 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -65,6 +65,7 @@ $aGlobal = array( 'price' => $setting->getValue('price'), 'disable_mp' => $setting->getValue('disable_mp'), 'config' => array( + 'target_bits' => $config['target_bits'], 'accounts' => $config['accounts'], 'disable_invitations' => $setting->getValue('disable_invitations'), 'disable_notifications' => $setting->getValue('disable_notifications'), diff --git a/public/templates/mmcFE/statistics/blocks/default.tpl b/public/templates/mmcFE/statistics/blocks/default.tpl index 5e80d361..28fdd3d6 100644 --- a/public/templates/mmcFE/statistics/blocks/default.tpl +++ b/public/templates/mmcFE/statistics/blocks/default.tpl @@ -131,7 +131,7 @@ target and network difficulty and assuming a zero variance scenario. {$BLOCKSFOUND[block].shares|number_format} {math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares estshares=$BLOCKSFOUND[block].estshares} - {assign var="totalpercentage" value=$totalpercentage+$percentage} + {assign var="totalpercentage" value=$totalpercentage+$percentage} {$percentage|number_format:"2"} diff --git a/public/templates/mmcFE/statistics/pool/default.tpl b/public/templates/mmcFE/statistics/pool/default.tpl index 9b2f86b3..7cf67f68 100644 --- a/public/templates/mmcFE/statistics/pool/default.tpl +++ b/public/templates/mmcFE/statistics/pool/default.tpl @@ -48,7 +48,7 @@ Est. Shares this Round - {assign var=estshares value=(65536 * $DIFFICULTY) / pow(2, ($GLOBAL.config.targetdiff - 16))} + {assign var=estshares value=(pow(2, (32 - $GLOBAL.config.target_bits)) * $DIFFICULTY) / pow(2, ($GLOBAL.config.targetdiff - 16))} {$estshares|number_format:"0"} (done: {(100 / $estshares * $GLOBAL.roundshares.valid)|number_format:"2"} %) diff --git a/public/templates/mpos/statistics/blocks/default.tpl b/public/templates/mpos/statistics/blocks/default.tpl index 0eae6232..4b9529ef 100644 --- a/public/templates/mpos/statistics/blocks/default.tpl +++ b/public/templates/mpos/statistics/blocks/default.tpl @@ -13,7 +13,7 @@ Expected {section block $BLOCKSFOUND step=-1} - {round(pow(2,32 - $GLOBAL.config.targetdiff) * $BLOCKSFOUND[block].difficulty)} + {$BLOCKSFOUND[block].estshares} {/section} From 2e64c4108d955aacfafe782837ecf13494e7eb85 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 4 Nov 2013 18:30:01 +0100 Subject: [PATCH 2/2] [FIX] Worker Hashrates in Account -> My Worker --- public/include/classes/worker.class.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/public/include/classes/worker.class.php b/public/include/classes/worker.class.php index f468d30c..e2fafcff 100644 --- a/public/include/classes/worker.class.php +++ b/public/include/classes/worker.class.php @@ -67,7 +67,7 @@ class Worker extends Base { * @param id int Worker ID * @return mixed array Worker details **/ - public function getWorker($id) { + public function getWorker($id, $interval=600) { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare(" SELECT id, username, password, monitor, @@ -75,34 +75,35 @@ class Worker extends Base { ( SELECT COUNT(id) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS count_all_archive, ( SELECT - IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000), 0), 0) AS hashrate + IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate FROM " . $this->share->getTableName() . " WHERE username = w.username - AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) + AND time > DATE_SUB(now(), INTERVAL ? SECOND) ) + ( SELECT - IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / 600 / 1000), 0), 0) AS hashrate + IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username - AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) + AND time > DATE_SUB(now(), INTERVAL ? SECOND) ) AS hashrate, ( SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / count_all, 2), 0) FROM " . $this->share->getTableName() . " - WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) + WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND) ) + ( SELECT IFNULL(ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) / count_all_archive, 2), 0) FROM " . $this->share->getArchiveTableName() . " - WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE) + WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND) ) AS difficulty FROM $this->table AS w WHERE id = ? "); - if ($this->checkStmt($stmt) && $stmt->bind_param('i', $id) && $stmt->execute() && $result = $stmt->get_result()) + if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiii', $interval, $interval, $interval, $interval, $interval, $interval, $id) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_assoc(); // Catchall + $this->serErrorMessage('Failed fetching worker details: '. $this->mysqli->error()); return false; } @@ -119,14 +120,14 @@ class Worker extends Base { ( SELECT COUNT(id) FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND)) AS count_all_archive, ( SELECT - IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / ? / 1000), 0), 0) AS hashrate + IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate FROM " . $this->share->getTableName() . " WHERE username = w.username AND time > DATE_SUB(now(), INTERVAL ? SECOND) ) + ( SELECT - IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * 65536 / ? / 1000), 0), 0) AS hashrate + IFNULL(IF(our_result='Y', ROUND(SUM(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)) * POW(2, " . $this->config['target_bits'] . ") / ? / 1000), 0), 0) AS hashrate FROM " . $this->share->getArchiveTableName() . " WHERE username = w.username