diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index 0681fcce..7629cd48 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -156,31 +156,37 @@ class Statistics { return false; } - public function getTopContributors($limit=15) { - $stmt = $this->mysqli->prepare(" - SELECT - ROUND(COUNT(id) / 60 / 10, 2) AS sharesps, - ROUND(COUNT(id) * POW(2," . $this->config['difficulty'] . ")/600/1000,2) AS hashrate, - SUBSTRING_INDEX( username, '.', 1 ) AS account - FROM " . $this->share->getTableName() . " - WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) - GROUP BY account - ORDER BY hashrate DESC LIMIT ?"); - if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $hashrates= $stmt->get_result()) { - $aHashData = $hashrates->fetch_all(MYSQLI_ASSOC); - $stmt->close(); - } else { + public function getTopContributors($type='shares', $limit=15) { + switch ($type) { + case 'shares': + $stmt = $this->mysqli->prepare(" + SELECT + COUNT(id) AS shares, + SUBSTRING_INDEX( username, '.', 1 ) AS account + FROM " . $this->share->getTableName() . " + GROUP BY account + LIMIT ?"); + if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_all(MYSQLI_ASSOC); + $this->debug->append("Fetching shares failed: "); return false; + break; + + case 'hashes': + $stmt = $this->mysqli->prepare(" + SELECT + ROUND(COUNT(id) * POW(2," . $this->config['difficulty'] . ")/600/1000,2) AS hashrate, + SUBSTRING_INDEX( username, '.', 1 ) AS account + FROM " . $this->share->getTableName() . " + WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) + GROUP BY account + ORDER BY hashrate DESC LIMIT ?"); + if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_all(MYSQLI_ASSOC); + $this->debug->append("Fetching shares failed: "); + return false; + break; } - foreach ($aHashData as $key => $aData) { - $stmt = $this->mysqli->prepare("SELECT COUNT(id) FROM " . $this->share->getTableName() . " WHERE SUBSTRING_INDEX( username , '.', 1 ) = ?"); - if ($stmt->bind_param("s", $aData['username']) && $stmt->execute() && $result = $stmt->get_result()) { - $aHashData[$key]['shares'] = $this->getUserShares($this->user->getUserId($aData['account']))['valid']; - } else { - continue; - } - } - return $aHashData; } public function getHourlyHashrateByAccount($account_id) { diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php index 005e167d..74c1d171 100644 --- a/public/include/pages/statistics/pool.inc.php +++ b/public/include/pages/statistics/pool.inc.php @@ -20,11 +20,20 @@ if ($bitcoin->can_connect() === true){ $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to pushpool service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); } -if (!$aHashData = $memcache->get('aHashData')) { - $debug->append('STA Fetching Hashrates from database'); - $aHashData = $statistics->getTopContributors(); - $memcache->set('aHashData', $aHashData, 60); - $debug->append('END Fetching Hashrates from database'); +// Top share contributors +if (!$aContributorsShares = $memcache->get('aContributorsShares')) { + $debug->append('STA Fetching contributor shares from database'); + $aContributorsShares = $statistics->getTopContributors('shares', 15); + $memcache->set('aContributorsShares', $aContributorsShares, 60); + $debug->append('END Fetching contributor shares from database'); +} + +// Top hash contributors +if (!$aContributorsHashes = $memcache->get('aContributorsHashes')) { + $debug->append('STA Fetching contributor hashes from database'); + $aContributorsHashes = $statistics->getTopContributors('hashes', 15); + $memcache->set('aContributorsHashes', $aContributorsHashes, 60); + $debug->append('END Fetching contributor hashes from database'); } // Grab the last 10 blocks found @@ -52,7 +61,8 @@ if (!empty($aBlockData)) { $smarty->assign("ESTTIME", $iEstTime); $smarty->assign("TIMESINCELAST", $dTimeSinceLast); $smarty->assign("BLOCKSFOUND", $aBlocksFoundData); -$smarty->assign("TOPHASHRATES", $aHashData); +$smarty->assign("CONTRIBSHARES", $aContributorsShares); +$smarty->assign("CONTRIBHASHES", $aContributorsHashes); $smarty->assign("CURRENTBLOCK", $iBlock); $smarty->assign("LASTBLOCK", $aBlockData['height']); $smarty->assign("DIFFICULTY", $dDifficulty); diff --git a/public/templates/mmcFE/statistics/pool/authenticated.tpl b/public/templates/mmcFE/statistics/pool/authenticated.tpl index 094493a1..7bddd421 100644 --- a/public/templates/mmcFE/statistics/pool/authenticated.tpl +++ b/public/templates/mmcFE/statistics/pool/authenticated.tpl @@ -1,34 +1,8 @@ {include file="global/block_header.tpl" BLOCK_HEADER="Pool Statistics" BLOCK_STYLE="clear:none;"} -{include file="global/block_header.tpl" BLOCK_HEADER="Top Contributers"} -
- - - - - - - - - - - - -{assign var=rank value=1} -{section hashrate $TOPHASHRATES} - - - - - - - - -{/section} - -
RankUser NameKH/sSharesShares/sŁ/Day (est)
{$rank++}{$TOPHASHRATES[hashrate].account}{$TOPHASHRATES[hashrate].hashrate|number_format}{$TOPHASHRATES[hashrate].shares|number_format}{$TOPHASHRATES[hashrate].sharesps}{math equation="round(reward / ( diff * pow(2,32) / ( hashrate * 1000 ) / 3600 / 24),3)" diff=$DIFFICULTY reward=$REWARD hashrate=$TOPHASHRATES[hashrate].hashrate}
- -
-{include file="global/block_footer.tpl"} + +{include file="statistics/pool/contributors_shares.tpl"} + +{include file="statistics/pool/contributors_hashrate.tpl"} {include file="global/block_header.tpl" BLOCK_HEADER="Server Stats" BLOCK_STYLE="clear:all;" STYLE="padding-left:5px;padding-right:5px;"} diff --git a/public/templates/mmcFE/statistics/pool/contributors_hashrate.tpl b/public/templates/mmcFE/statistics/pool/contributors_hashrate.tpl new file mode 100644 index 00000000..f9f9c27f --- /dev/null +++ b/public/templates/mmcFE/statistics/pool/contributors_hashrate.tpl @@ -0,0 +1,26 @@ +{include file="global/block_header.tpl" ALIGN="left" BLOCK_HEADER="Top Hashrate Contributers"} +
+
+ + + + + + + + + +{assign var=rank value=1} +{section contrib $CONTRIBHASHES} + + + + + + +{/section} + +
RankUser NameKH/sŁ/Day (est)
{$rank++}{$CONTRIBHASHES[contrib].account}{$CONTRIBHASHES[contrib].hashrate|number_format}{math equation="round(reward / ( diff * pow(2,32) / ( hashrate * 1000 ) / 3600 / 24),3)" diff=$DIFFICULTY reward=$REWARD hashrate=$CONTRIBHASHES[contrib].hashrate}
+ + +{include file="global/block_footer.tpl"} diff --git a/public/templates/mmcFE/statistics/pool/contributors_shares.tpl b/public/templates/mmcFE/statistics/pool/contributors_shares.tpl new file mode 100644 index 00000000..1214ef44 --- /dev/null +++ b/public/templates/mmcFE/statistics/pool/contributors_shares.tpl @@ -0,0 +1,24 @@ +{include file="global/block_header.tpl" ALIGN="right" BLOCK_HEADER="Top Share Contributers"} +
+ + + + + + + + + +{assign var=rank value=1} +{section hashrate $CONTRIBSHARES} + + + + + +{/section} + +
RankUser NameShares
{$rank++}{$CONTRIBSHARES[hashrate].account}{$CONTRIBSHARES[hashrate].shares|number_format}
+ +
+{include file="global/block_footer.tpl"}