adding some first statistics including memcache storage, adjusted template. LTC/day not working yet

This commit is contained in:
Sebastian Grewe 2013-05-13 17:56:30 +02:00
parent e4edd63c41
commit d90b496dfd
2 changed files with 49 additions and 20 deletions

View File

@ -4,31 +4,58 @@
if (!defined('SECURITY')) if (!defined('SECURITY'))
die('Hacking attempt'); die('Hacking attempt');
// Use Memcache to store our data
$m = new Memcached();
$m->addServer('localhost', 11211);
// Fetch data from litecoind // Fetch data from litecoind
if ($bitcoin->can_connect() === true){ if ($bitcoin->can_connect() === true){
$dDifficulty = $bitcoin->query('getdifficulty'); if (!$dDifficulty = $m->get('dDifficulty')) {
$iBlock = $bitcoin->query('getblockcount'); $dDifficulty = $bitcoin->query('getdifficulty');
$m->set('dDifficulty', $dDifficulty, 60);
}
if (!$iBlock = $m->get('iBlock')) {
$iBlock = $bitcoin->query('getblockcount');
$m->set('iBlock', $iBlock, 60);
}
} else { } else {
$iDifficulty = 1; $iDifficulty = 1;
$iBlock = 0; $iBlock = 0;
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to pushpool service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to pushpool service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
} }
/** Disabled Stats if (!$aHashData = $m->get('aHashData')) {
// Top 15 hashrate list $debug->append('Hashrates expired in memcache');
$stmt = $mysqli->prepare("SELECT username, id, hashrate FROM accounts WHERE hashrate != '0' ORDER BY hashrate DESC LIMIT 15"); // Top 15 hashrate list
$stmt->execute(); $stmt = $mysqli->prepare("SELECT
$hashrates= $stmt->get_result(); ROUND(COUNT(id) * POW(2," . $config['difficulty'] . ")/600/1000,2) AS hashrate,
$aHashData = $hashrates->fetch_all(MYSQLI_ASSOC); SUBSTRING_INDEX( `username` , '.', 1 ) AS account
$stmt->close(); FROM shares
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
GROUP BY account
ORDER BY hashrate DESC LIMIT 15");
echo $mysqli->error;
$stmt->execute();
$hashrates= $stmt->get_result();
$aHashData = $hashrates->fetch_all(MYSQLI_ASSOC);
$stmt->close();
$m->set('aHashData', $aHashData, 1);
} else {
$debug->append("Found aHashData in memcache");
}
// Top 15 Contributors
$stmt = $mysqli->prepare("SELECT id, shares_this_round AS shares, username FROM accounts WHERE shares_this_round > 0 ORDER BY shares DESC LIMIT 15"); if (! $aContributerData = $m->get('aContributerData') ) {
$stmt->execute(); // Top 15 Contributers
$contributors = $stmt->get_result(); $stmt = $mysqli->prepare("SELECT count(id) AS shares, SUBSTRING_INDEX( `username` , '.', 1 ) AS account FROM shares GROUP BY account LIMIT 15");
$aContributorData = $contributors->fetch_all(MYSQLI_ASSOC); $stmt->execute();
$stmt->close(); $contributers = $stmt->get_result();
*/ $aContributerData = $contributers->fetch_all(MYSQLI_ASSOC);
$stmt->close();
$m->set('aContributerData', $aContributerData, 60);
} else {
$debug->append("Found aContributerData in memcache");
}
// Grab the last block found // Grab the last block found
$stmt = $mysqli->prepare("SELECT * FROM blocks ORDER BY height DESC LIMIT 1"); $stmt = $mysqli->prepare("SELECT * FROM blocks ORDER BY height DESC LIMIT 1");

View File

@ -8,6 +8,7 @@
<th align="left" scope="col">User Name</th> <th align="left" scope="col">User Name</th>
<th align="left" scope="col">KH/s</th> <th align="left" scope="col">KH/s</th>
<th align="left">Ł/Day<font size="1"> (est)</font></th> <th align="left">Ł/Day<font size="1"> (est)</font></th>
<th align="left">Ł/Day<font size="1"> (est)</font></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -15,9 +16,10 @@
{section hashrate $TOPHASHRATES} {section hashrate $TOPHASHRATES}
<tr class="{cycle values="odd,even"}"> <tr class="{cycle values="odd,even"}">
<td>{$rank++}</td> <td>{$rank++}</td>
<td>{$TOPHASHRATES[hashrate].username}</td> <td>{$TOPHASHRATES[hashrate].account}</td>
<td>{$TOPHASHRATES[hashrate].hashrate|number_format}</td> <td>{$TOPHASHRATES[hashrate].hashrate|number_format}</td>
<td>{math equation="round(( 24 / (((diff * pow(2,targetdiff)) / (hashrate * 1000)) / 3600) * reward ),3)" diff=$DIFFICULTY targetdiff=$TARGETDIFF hashrate=$TOPHASHRATES[hashrate].hashrate reward=$REWARD}</td> <td>{math equation="round(( 24 / (((diff * pow(2,targetdiff)) / hashrate) / 3600) * reward ),3)" diff=$DIFFICULTY targetdiff=$TARGETDIFF hashrate=$TOPHASHRATES[hashrate].hashrate reward=$REWARD}</td>
<td>{$TOPHASHRATES[hashrate].ltcday|number_format}
</tr> </tr>
{/section} {/section}
</tbody> </tbody>
@ -25,7 +27,7 @@
</center> </center>
{include file="global/block_footer.tpl"} {include file="global/block_footer.tpl"}
{include file="global/block_header.tpl" BLOCK_HEADER="Top 15 Contributors" ALIGN="right" BUTTONS=array(More,Less)} {include file="global/block_header.tpl" BLOCK_HEADER="Top 15 Contributers" ALIGN="right" BUTTONS=array(More,Less)}
<center> <center>
<table class="" width="100%" style="font-size:13px;"> <table class="" width="100%" style="font-size:13px;">
<thead> <thead>
@ -36,7 +38,7 @@
{section contributor $CONTRIBUTORS} {section contributor $CONTRIBUTORS}
<tr class="{cycle values="odd,even"}"> <tr class="{cycle values="odd,even"}">
<td>{$rank++}</td> <td>{$rank++}</td>
<td>{$CONTRIBUTORS[contributor].username}</td> <td>{$CONTRIBUTORS[contributor].account}</td>
<td>{$CONTRIBUTORS[contributor].shares|number_format}</td> <td>{$CONTRIBUTORS[contributor].shares|number_format}</td>
</tr> </tr>
{/section} {/section}