24 hour pool statistics

This commit is contained in:
obigal 2013-10-29 22:25:45 -04:00
parent 4f3503bbb1
commit c0756d39df
4 changed files with 90 additions and 3 deletions

View File

@ -731,6 +731,32 @@ class Statistics {
}
return $aEstimates;
}
/**
* Get pool stats last 24 hours
* @param limit int Last number of hours
* @return array
**/
public function getPoolStatsHours($hour=24) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $hour)) return $data;
$stmt = $this->mysqli->prepare("
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(shares)), 0) as shares,
IFNULL(SUM(amount), 0) as rewards
FROM " . $this->block->getTableName() . "
WHERE FROM_UNIXTIME(time) > DATE_SUB(now(), INTERVAL ? HOUR)
AND confirmations >= 1");
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $hour) && $stmt->execute() && $result = $stmt->get_result())
return $this->memcache->setCache(__FUNCTION__ . $hour, $result->fetch_assoc());
// Catchall
$this->debug->append("Failed to get pool statistics:" . $this->mysqli->error);
return false;
}
}

View File

@ -68,11 +68,15 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
}
}
}
//var_dump($aBlocksFoundData);
$iHours = 24;
$aPoolStatistics = $statistics->getPoolStatsHours($iHours);
// Propagate content our template
$smarty->assign("BLOCKSFOUND", $aBlocksFoundData);
$smarty->assign("BLOCKLIMIT", $iLimit);
$smarty->assign("USEBLOCKAVERAGE", $use_average);
$smarty->assign("POOLSTATS", $aPoolStatistics);
} else {
$debug->append('Using cached page', 3);
}

View File

@ -40,6 +40,35 @@
The graph above illustrates N shares to find a block vs. E Shares expected to find a block based on
target and network difficulty and assuming a zero variance scenario.
</p>
<table width="100%" style="font-size:13px;">
<thead>
<tr>
<th class="center" colspan="6">Last 24 hour totals</th>
</tr>
<tr style="background-color:#B6DAFF;">
<th class="center">Blocks Found</th>
<th class="center">Rewards</th>
<th class="center">Avg Difficulty</th>
<th class="center">Expected Shares</th>
<th class="center">Actual Shares</th>
<th class="center">Percentage</th>
</tr>
</thead>
<tbody>
{assign var=percentage1 value=0}
<tr>
<td class="center">{$POOLSTATS.count|number_format:"0"}</td>
<td class="center">{$POOLSTATS.rewards|number_format:"4"}</td>
<td class="center">{$POOLSTATS.average|number_format:"4"}</td>
<td class="center">{$POOLSTATS.expected|number_format:"0"}</td>
<td class="center">{$POOLSTATS.shares|number_format:"0"}</td>
<td class="center">{if $POOLSTATS.shares > 0}{math assign="percentage1" equation="shares1 / estshares1 * 100" shares1=$POOLSTATS.shares estshares1=$POOLSTATS.expected}{/if}
<font color="{if ($percentage1 <= 100)}green{else}red{/if}">{$percentage1|number_format:"2"}</font></b></td>
</tr>
</tbody>
</table>
<table align="left" width="100%" border="0" style="font-size:13px;">
<tbody>
<tr>

View File

@ -36,6 +36,36 @@
</tr>{/if}
</tbody>
</table>
<br>
<table class="tablesorter">
<thead>
<tr>
<th align="center" colspan="6">Last 24 hour totals</th>
</tr>
<tr style="background-color:#B6DAFF;">
<th align="center">Blocks Found</th>
<th align="center">Rewards</th>
<th align="center">Avg Difficulty</th>
<th align="center">Expected Shares</th>
<th align="center">Actual Shares</th>
<th align="center" style="padding-right: 25px;">Percentage</th>
</tr>
</thead>
<tbody>
{assign var=percentage1 value=0}
<tr>
<td align="center">{$POOLSTATS.count|number_format:"0"}</td>
<td align="center">{$POOLSTATS.rewards|number_format:"4"}</td>
<td align="center">{$POOLSTATS.average|number_format:"4"}</td>
<td align="center">{$POOLSTATS.expected|number_format:"0"}</td>
<td align="center">{$POOLSTATS.shares|number_format:"0"}</td>
<td align="center" style="padding-right: 25px;">{if $POOLSTATS.shares > 0}{math assign="percentage1" equation="shares1 / estshares1 * 100" shares1=$POOLSTATS.shares estshares1=$POOLSTATS.expected}{/if}
<font color="{if ($percentage1 <= 100)}green{else}red{/if}">{$percentage1|number_format:"2"}</font></b></td>
</tr>
</tbody>
</table>
<table class="tablesorter">
<tbody>
<tr>
@ -77,7 +107,6 @@
{assign var=count value=0}
{assign var=totalexpectedshares value=0}
{assign var=totalshares value=0}
{assign var=totalpercentage value=0}
{assign var=pplnsshares value=0}
{section block $BLOCKSFOUND}
{assign var="totalshares" value=$totalshares+$BLOCKSFOUND[block].shares}
@ -110,7 +139,6 @@
<td align="right">{$BLOCKSFOUND[block].shares|number_format}</td>
<td align="right" style="padding-right: 25px;">
{math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares estshares=$BLOCKSFOUND[block].estshares}
{assign var="totalpercentage" value=$totalpercentage+$percentage}
<font color="{if ($percentage <= 100)}green{else}red{/if}">{$percentage|number_format:"2"}</font>
</td>
</tr>