Moved Calculation of "Expected Time Per Block (Network)" and "Next Difficulty" to Statistics Class and fixed Dashboard-API for Ajax Refresh
This commit is contained in:
parent
8d3efd3801
commit
ed769f9659
@ -800,6 +800,41 @@ class Statistics extends Base {
|
|||||||
public function getEstimatedShares($dDiff) {
|
public function getEstimatedShares($dDiff) {
|
||||||
return round((POW(2, (32 - $this->config['target_bits'])) * $dDiff) / pow(2, ($this->config['difficulty'] - 16)));
|
return round((POW(2, (32 - $this->config['target_bits'])) * $dDiff) / pow(2, ($this->config['difficulty'] - 16)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Expected Time per Block in the whole Network in seconde
|
||||||
|
* @return seconds double Seconds per Block
|
||||||
|
*/
|
||||||
|
public function getNetworkExpectedTimePerBlock(){
|
||||||
|
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||||
|
|
||||||
|
if ($this->bitcoin->can_connect() === true) {
|
||||||
|
$dNetworkHashrate = $this->bitcoin->getnetworkhashps();
|
||||||
|
$dDifficulty = $this->bitcoin->getdifficulty();
|
||||||
|
} else {
|
||||||
|
$dNetworkHashrate = 0;
|
||||||
|
$dDifficulty = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pow(2, 32) * $dDifficulty / $dNetworkHashrate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Expected next Difficulty
|
||||||
|
* @return difficulty double Next difficulty
|
||||||
|
*/
|
||||||
|
public function getExpectedNextDifficulty(){
|
||||||
|
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||||
|
|
||||||
|
if ($this->bitcoin->can_connect() === true) {
|
||||||
|
$dDifficulty = $this->bitcoin->getdifficulty();
|
||||||
|
} else {
|
||||||
|
$dDifficulty = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return round($dDifficulty * $this->config['cointarget'] / $this->getNetworkExpectedTimePerBlock(), 8);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$statistics = new Statistics();
|
$statistics = new Statistics();
|
||||||
@ -810,6 +845,7 @@ $statistics->setUser($user);
|
|||||||
$statistics->setBlock($block);
|
$statistics->setBlock($block);
|
||||||
$statistics->setMemcache($memcache);
|
$statistics->setMemcache($memcache);
|
||||||
$statistics->setConfig($config);
|
$statistics->setConfig($config);
|
||||||
|
$statistics->setBitcoin($bitcoin);
|
||||||
$statistics->setErrorCodes($aErrorCodes);
|
$statistics->setErrorCodes($aErrorCodes);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -104,8 +104,8 @@ if ($iEstShares > 0 && $aRoundShares['valid'] > 0) {
|
|||||||
$dEstPercent = 0;
|
$dEstPercent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dExpectedTimePerBlock = pow(2, $config['target_bits']) * $dDifficulty / $dNetworkHashrate;
|
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
|
||||||
$dEstNextDifficulty = round($dDifficulty * $config['cointarget'] / $dExpectedTimePerBlock, 8);
|
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
|
||||||
|
|
||||||
// Output JSON format
|
// Output JSON format
|
||||||
$data = array(
|
$data = array(
|
||||||
@ -126,7 +126,7 @@ $data = array(
|
|||||||
'target_bits' => $config['difficulty']
|
'target_bits' => $config['difficulty']
|
||||||
),
|
),
|
||||||
'system' => array( 'load' => sys_getloadavg() ),
|
'system' => array( 'load' => sys_getloadavg() ),
|
||||||
'network' => array( 'hashrate' => $dNetworkHashrateAdjusted, 'difficulty' => $dDifficulty, 'block' => $iBlock ),
|
'network' => array( 'hashrate' => $dNetworkHashrateAdjusted, 'difficulty' => $dDifficulty, 'block' => $iBlock, 'esttimeperblock' => round($dExpectedTimePerBlock ,2), 'nextdifficulty' => $dEstNextDifficulty ),
|
||||||
);
|
);
|
||||||
|
|
||||||
echo $api->get_json($data);
|
echo $api->get_json($data);
|
||||||
|
|||||||
@ -35,8 +35,8 @@ if ($user->isAuthenticated()) {
|
|||||||
// Avoid confusion, ensure our nethash isn't higher than poolhash
|
// Avoid confusion, ensure our nethash isn't higher than poolhash
|
||||||
if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate;
|
if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate;
|
||||||
|
|
||||||
$dExpectedTimePerBlock = pow(2, $config['target_bits']) * $dDifficulty / $dNetworkHashrate;
|
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
|
||||||
$dEstNextDifficulty = round($dDifficulty * $config['cointarget'] / $dExpectedTimePerBlock, 8);
|
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
|
||||||
|
|
||||||
// Make it available in Smarty
|
// Make it available in Smarty
|
||||||
$smarty->assign('DISABLED_DASHBOARD', $setting->getValue('disable_dashboard'));
|
$smarty->assign('DISABLED_DASHBOARD', $setting->getValue('disable_dashboard'));
|
||||||
|
|||||||
@ -52,8 +52,8 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
|
|||||||
$dEstPercent = 0;
|
$dEstPercent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dExpectedTimePerBlock = pow(2, $config['target_bits']) * $dDifficulty / $dNetworkHashrate;
|
$dExpectedTimePerBlock = $statistics->getNetworkExpectedTimePerBlock();
|
||||||
$dEstNextDifficulty = round($dDifficulty * $config['cointarget'] / $dExpectedTimePerBlock, 8);
|
$dEstNextDifficulty = $statistics->getExpectedNextDifficulty();
|
||||||
|
|
||||||
// Propagate content our template
|
// Propagate content our template
|
||||||
$smarty->assign("ESTTIME", $iEstTime);
|
$smarty->assign("ESTTIME", $iEstTime);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user