From 8cfc43eacad3fe93c6873096cb9e61a57648d6da Mon Sep 17 00:00:00 2001 From: R4SAS Date: Fri, 11 May 2018 12:17:33 +0000 Subject: [PATCH] implement low-diff shares counting (#2718 #2726) --- include/classes/statistics.class.php | 4 ++-- sql/000_base_structure.sql | 8 ++++---- .../bootstrap/statistics/round/pplns_transactions.tpl | 4 ++-- .../bootstrap/statistics/round/round_transactions.tpl | 2 +- upgrade/definitions/1.0.2_to_1.0.3.inc.php | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/classes/statistics.class.php b/include/classes/statistics.class.php index 777fe3200..05c2c2ac8 100644 --- a/include/classes/statistics.class.php +++ b/include/classes/statistics.class.php @@ -203,7 +203,7 @@ public function getBlocksSolvedbyWorker($account_id, $limit=25) { public function updateShareStatistics($aStats, $iBlockId) { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)"); - if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true; + if ($this->checkStmt($stmt) && $stmt->bind_param('iddi', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true; return $this->sqlError(); } @@ -213,7 +213,7 @@ public function updateShareStatistics($aStats, $iBlockId) { public function insertPPLNSStatistics($aStats, $iBlockId) { $this->debug->append("STA " . __METHOD__, 4); $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, pplns_valid, pplns_invalid, block_id) VALUES (?, ?, ?, ?, ?, ?)"); - if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $aStats['pplns_valid'], $aStats['pplns_invalid'], $iBlockId) && $stmt->execute()) return true; + if ($this->checkStmt($stmt) && $stmt->bind_param('iddddi', $aStats['id'], $aStats['valid'], $aStats['invalid'], $aStats['pplns_valid'], $aStats['pplns_invalid'], $iBlockId) && $stmt->execute()) return true; return $this->sqlError(); } diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index 88101fce2..a5c55b10d 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -182,10 +182,10 @@ CREATE TABLE IF NOT EXISTS `statistics_shares` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `account_id` int(10) unsigned NOT NULL, `block_id` int(10) unsigned NOT NULL, - `valid` bigint(20) NOT NULL DEFAULT '0', - `invalid` bigint(20) NOT NULL DEFAULT '0', - `pplns_valid` bigint(20) NOT NULL DEFAULT '0', - `pplns_invalid` bigint(20) NOT NULL DEFAULT '0', + `valid` float NOT NULL DEFAULT '0', + `invalid` float NOT NULL DEFAULT '0', + `pplns_valid` float NOT NULL DEFAULT '0', + `pplns_invalid` float NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `account_id` (`account_id`), KEY `block_id` (`block_id`) diff --git a/templates/bootstrap/statistics/round/pplns_transactions.tpl b/templates/bootstrap/statistics/round/pplns_transactions.tpl index 4d71e7039..7ab591325 100644 --- a/templates/bootstrap/statistics/round/pplns_transactions.tpl +++ b/templates/bootstrap/statistics/round/pplns_transactions.tpl @@ -23,9 +23,9 @@ {section txs $ROUNDTRANSACTIONS} {if $ROUNDTRANSACTIONS[txs].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$ROUNDTRANSACTIONS[txs].username|default:"unknown"|escape}{/if} - {$ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid|number_format|default:0} + {$ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid|number_format:$GLOBAL.config.sharediffprecision|default:"0"} {if $ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid|default:"0" > 0 }{(( 100 / $BLOCKDETAILS.shares) * $ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid)|number_format:"2"}{else}0.00{/if} - {$PPLNSROUNDSHARES[txs].pplns_valid|number_format|default:"0"} + {$PPLNSROUNDSHARES[txs].pplns_valid|number_format:$GLOBAL.config.sharediffprecision|default:"0"} {if $PPLNSROUNDSHARES[txs].pplns_valid|default:"0" > 0 }{(( 100 / $PPLNSSHARES) * $PPLNSROUNDSHARES[txs].pplns_valid)|number_format:"2"|default:"0"}{else}0{/if} {if $ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid|default:"0" > 0 && $PPLNSROUNDSHARES[txs].pplns_valid|default:"0" > 0}{math assign="percentage1" equation=(100 / ((( 100 / $BLOCKDETAILS.shares) * $ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid) / (( 100 / $PPLNSSHARES) * $PPLNSROUNDSHARES[txs].pplns_valid)))}{else if $PPLNSROUNDSHARES[txs].pplns_valid|default:"0" == 0}{assign var=percentage1 value=0}{else}{assign var=percentage1 value=100}{/if} {$percentage1|number_format:"2"} diff --git a/templates/bootstrap/statistics/round/round_transactions.tpl b/templates/bootstrap/statistics/round/round_transactions.tpl index 5ea4de288..2d0b24a23 100644 --- a/templates/bootstrap/statistics/round/round_transactions.tpl +++ b/templates/bootstrap/statistics/round/round_transactions.tpl @@ -20,7 +20,7 @@ {if $ROUNDTRANSACTIONS[txs].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$ROUNDTRANSACTIONS[txs].username|default:"unknown"|escape}{/if} {$ROUNDTRANSACTIONS[txs].type|default:""} - {$ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid|number_format} + {$ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid|number_format:$GLOBAL.config.sharediffprecision|default:"0"} {(( 100 / $BLOCKDETAILS.shares) * $ROUNDSHARES[$ROUNDTRANSACTIONS[txs].uid].valid)|default:"0"|number_format:"2"} {$ROUNDTRANSACTIONS[txs].amount|default:"0"|number_format:"8"} diff --git a/upgrade/definitions/1.0.2_to_1.0.3.inc.php b/upgrade/definitions/1.0.2_to_1.0.3.inc.php index fddd7a35a..3a90b33f2 100644 --- a/upgrade/definitions/1.0.2_to_1.0.3.inc.php +++ b/upgrade/definitions/1.0.2_to_1.0.3.inc.php @@ -11,7 +11,7 @@ function run_103() { // Upgrade specific variables $aSql[] = "UPDATE `statistics_shares` SET `valid` = '0' WHERE `valid` IS NULL;"; $aSql[] = "UPDATE `statistics_shares` SET `pplns_valid` = '0' WHERE `pplns_valid` IS NULL;"; - $aSql[] = "ALTER TABLE `statistics_shares` CHANGE `valid` `valid` BIGINT(20) NOT NULL DEFAULT '0', CHANGE `pplns_valid` `pplns_valid` BIGINT(20) NOT NULL DEFAULT '0';"; + $aSql[] = "ALTER TABLE `statistics_shares` CHANGE `valid` `valid` FLOAT NOT NULL DEFAULT '0', CHANGE `invalid` `invalid` FLOAT NOT NULL DEFAULT '0', CHANGE `pplns_valid` `pplns_valid` FLOAT NOT NULL DEFAULT '0', CHANGE `pplns_invalid` `pplns_invalid` FLOAT NOT NULL DEFAULT '0';"; $aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '" . $db_version_new . "' WHERE name = 'DB_VERSION';"; if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {