[CHANGE] Estimated time per block calculations

This commit is contained in:
Sebastian Grewe 2014-05-15 10:40:28 +02:00
parent fef95b9ace
commit d294e266a4
4 changed files with 15 additions and 8 deletions

View File

@ -815,21 +815,26 @@ class Statistics extends Base {
* Get the Expected Time per Block in the whole Network in seconde
* @return seconds double Seconds per Block
*/
public function getNetworkExpectedTimePerBlock(){
public function getExpectedTimePerBlock($type='network',$hashrate = 0){
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
if ($this->bitcoin->can_connect() === true) {
$dNetworkHashrate = $this->bitcoin->getnetworkhashps();
if ($type == 'network') {
$hashrate = $this->bitcoin->getnetworkhashps();
} else {
// We need hashes/second and expect khash as input
$hashrate = $hashrate * 1000;
}
$dDifficulty = $this->bitcoin->getdifficulty();
} else {
$dNetworkHashrate = 1;
$dDifficulty = 1;
}
if($dNetworkHashrate <= 0){
if($hashrate <= 0){
return $this->memcache->setCache(__FUNCTION__, $this->config['cointarget']);
}
return $this->memcache->setCache(__FUNCTION__, $this->coin->calcNetworkExpectedTimePerBlock($dDifficulty, $dNetworkHashrate));
return $this->memcache->setCache(__FUNCTION__, $this->coin->calcNetworkExpectedTimePerBlock($dDifficulty, $hashrate));
}
/**

View File

@ -78,7 +78,8 @@ $iEstShares = $statistics->getEstimatedShares($dDifficulty);
$iEstShares > 0 && $aRoundShares['valid'] > 0 ? $dEstPercent = round(100 / $iEstShares * $aRoundShares['valid'], 2) : $dEstPercent = 0;
// Some estimates
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
$dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock();
$dPoolExpectedTimePerBlock = $statistics->getExpectedTimePerBlock('pool', $dPoolHashrate);
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
$iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();
@ -105,6 +106,7 @@ $data = array(
'name' => $setting->getValue('website_name'),
'currency' => $config['currency']
),
'esttimeperblock' => round($dPoolExpectedTimePerBlock, 2),
'blocks' => $aLastBlocks,
'workers' => $worker->getCountAllActiveWorkers(), 'hashrate' => $dPoolHashrateAdjusted,
'shares' => array( 'valid' => $aRoundShares['valid'], 'invalid' => $aRoundShares['invalid'], 'invalid_percent' => $dPoolInvalidPercent, 'estimated' => $iEstShares, 'progress' => $dEstPercent ),

View File

@ -33,7 +33,7 @@ if ($user->isAuthenticated()) {
// Avoid confusion, ensure our nethash isn't higher than poolhash
if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate;
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
$dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock('pool', $iCurrentPoolHashrate);
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
$iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();

View File

@ -32,7 +32,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$iCurrentPoolHashrate = $statistics->getCurrentHashrate();
// Time in seconds, not hours, using modifier in smarty to translate
$iCurrentPoolHashrate > 0 ? $iEstTime = $dDifficulty * pow(2,32) / ($iCurrentPoolHashrate * 1000) : $iEstTime = 0;
$iCurrentPoolHashrate > 0 ? $iEstTime = $statistics->getExpectedTimePerBlock('pool', $iCurrentPoolHashrate) : $iEstTime = 0;
// Time since last block
if (!empty($aBlockData)) {
@ -54,7 +54,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$dEstPercent = 0;
}
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
$dExpectedTimePerBlock = $statistics->getExpectedTimePerBlock();
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
$iBlocksUntilDiffChange = $statistics->getBlocksUntilDiffChange();