mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 09:27:25 +00:00
stats: rewrite pool graphes data with json_encode
This commit is contained in:
parent
03f25a73ef
commit
02c0191e5e
2 changed files with 25 additions and 77 deletions
|
@ -8,19 +8,16 @@ $factor = yaamp_algo_mBTC_factor($algo); // 1000 sha (GH/s), 1 for normal MH/s
|
|||
|
||||
$step = 15*60;
|
||||
$t = time() - 24*60*60;
|
||||
|
||||
$stats = getdbolist('db_hashrate', "time > $t AND algo=:algo ORDER BY time", array(':algo'=>$algo));
|
||||
$t = intval($t / $step) * $step;
|
||||
$stats = getdbolist('db_hashrate', "time >= $t AND algo=:algo ORDER BY time", array(':algo'=>$algo));
|
||||
$tfirst = empty($stats) ? $t : $stats[0]->time;
|
||||
$averages = array();
|
||||
|
||||
$json = '';
|
||||
|
||||
for($i = 0; $i < 95-count($stats); $i++)
|
||||
{
|
||||
for($i = 0; $i < 95-count($stats); $i++) {
|
||||
$d = date('Y-m-d H:i:s', $t);
|
||||
$json .= "[\"$d\",0],";
|
||||
|
||||
$averages[] = array($d, 0);
|
||||
$t += $step;
|
||||
if ($t >= $tfirst) break;
|
||||
}
|
||||
|
||||
foreach($stats as $n)
|
||||
|
@ -29,43 +26,18 @@ foreach($stats as $n)
|
|||
$m = round($r / $factor, 3);
|
||||
|
||||
$d = date('Y-m-d H:i:s', $n->time);
|
||||
$json .= "[\"$d\",$m],";
|
||||
|
||||
$averages[] = array($d, $m);
|
||||
}
|
||||
|
||||
echo '[['.rtrim($json,',').'],';
|
||||
echo '[';
|
||||
if ($averages[0][1] == 0) $averages[0][1] = $averages[1][1];
|
||||
|
||||
$json = '';
|
||||
$avg2 = array();
|
||||
$average = $averages[0][1];
|
||||
foreach($averages as $n)
|
||||
{
|
||||
foreach($averages as $n) {
|
||||
$average = ($average*(100-$percent) + $n[1]*$percent) / 100;
|
||||
$m = round($average, 3);
|
||||
|
||||
$json .= "[\"{$n[0]}\",$m],";
|
||||
$avg2[] = array($n[0], $m);
|
||||
}
|
||||
|
||||
// $a = 10;
|
||||
// foreach($averages as $i=>$n)
|
||||
// {
|
||||
// if($i < $a) continue;
|
||||
|
||||
// $average = 0;
|
||||
// for($j = $i-$a+1; $j<=$i; $j++)
|
||||
// $average += $averages[$j][1]/$a;
|
||||
|
||||
// $m = round($average, 3);
|
||||
|
||||
// $json .= "[\"{$n[0]}\",$m]";
|
||||
// }
|
||||
|
||||
echo rtrim($json,',');
|
||||
echo ']]';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
echo '['.json_encode($averages).",\n".json_encode($avg2).']';
|
||||
|
|
|
@ -1,62 +1,38 @@
|
|||
<?php
|
||||
|
||||
/* Graph shown in Pool tab, last 24h algo estimates */
|
||||
|
||||
$percent = 16;
|
||||
$algo = user()->getState('yaamp-algo');
|
||||
|
||||
$step = 15*60;
|
||||
$t = time() - 24*60*60;
|
||||
|
||||
$stats = getdbolist('db_hashrate', "time > $t AND algo=:algo ORDER BY time", array(':algo'=>$algo));
|
||||
$t = intval($t / $step) * $step;
|
||||
$stats = getdbolist('db_hashrate', "time >= $t AND algo=:algo ORDER BY time", array(':algo'=>$algo));
|
||||
$tfirst = empty($stats) ? $t : $stats[0]->time;
|
||||
$pfirst = empty($stats) ? 0.0 : (double) altcoinvaluetoa($stats[0]->price);
|
||||
$averages = array();
|
||||
|
||||
$json = '';
|
||||
for($i = 0; $i < 95-count($stats); $i++)
|
||||
{
|
||||
for($i = 0; $i < 95-count($stats); $i++) {
|
||||
$d = date('Y-m-d H:i:s', $t);
|
||||
$json .= "[\"$d\",0],";
|
||||
|
||||
$averages[] = array($d, $pfirst);
|
||||
$t += $step;
|
||||
$averages[] = array($d, 0);
|
||||
if ($t >= $tfirst) break;
|
||||
}
|
||||
|
||||
foreach($stats as $n)
|
||||
{
|
||||
$m = $n->price;
|
||||
|
||||
foreach($stats as $n) {
|
||||
$m = (double) altcoinvaluetoa($n->price);
|
||||
$d = date('Y-m-d H:i:s', $n->time);
|
||||
$json .= "[\"$d\",$m],";
|
||||
|
||||
$averages[] = array($d, $m);
|
||||
}
|
||||
|
||||
echo '[[';
|
||||
echo rtrim($json, ',');
|
||||
echo '],[';
|
||||
|
||||
$json = '';
|
||||
$avg2 = array();
|
||||
$average = $averages[0][1];
|
||||
foreach($averages as $n)
|
||||
{
|
||||
foreach($averages as $n) {
|
||||
$average = ($average*(100-$percent) + $n[1]*$percent) / 100;
|
||||
$m = round($average, 5);
|
||||
|
||||
$json .= "[\"{$n[0]}\",$m],";
|
||||
$avg2[] = array($n[0], $m);
|
||||
}
|
||||
|
||||
// $a = 10;
|
||||
// foreach($averages as $i=>$n)
|
||||
// {
|
||||
// if($i < $a) continue;
|
||||
|
||||
// $average = 0;
|
||||
// for($j = $i-$a+1; $j<=$i; $j++)
|
||||
// $average += $averages[$j][1]/$a;
|
||||
|
||||
// $m = round($average, 3);
|
||||
|
||||
// echo "[\"{$n[0]}\",$m]";
|
||||
// }
|
||||
|
||||
echo rtrim($json, ',');
|
||||
echo ']]';
|
||||
|
||||
echo '['.json_encode($averages).",\n".json_encode($avg2).']';
|
||||
|
|
Loading…
Add table
Reference in a new issue