mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37: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;
|
$step = 15*60;
|
||||||
$t = time() - 24*60*60;
|
$t = time() - 24*60*60;
|
||||||
|
$t = intval($t / $step) * $step;
|
||||||
$stats = getdbolist('db_hashrate', "time > $t AND algo=:algo ORDER BY time", array(':algo'=>$algo));
|
$stats = getdbolist('db_hashrate', "time >= $t AND algo=:algo ORDER BY time", array(':algo'=>$algo));
|
||||||
|
$tfirst = empty($stats) ? $t : $stats[0]->time;
|
||||||
$averages = array();
|
$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);
|
$d = date('Y-m-d H:i:s', $t);
|
||||||
$json .= "[\"$d\",0],";
|
|
||||||
|
|
||||||
$averages[] = array($d, 0);
|
$averages[] = array($d, 0);
|
||||||
$t += $step;
|
$t += $step;
|
||||||
|
if ($t >= $tfirst) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($stats as $n)
|
foreach($stats as $n)
|
||||||
|
@ -29,43 +26,18 @@ foreach($stats as $n)
|
||||||
$m = round($r / $factor, 3);
|
$m = round($r / $factor, 3);
|
||||||
|
|
||||||
$d = date('Y-m-d H:i:s', $n->time);
|
$d = date('Y-m-d H:i:s', $n->time);
|
||||||
$json .= "[\"$d\",$m],";
|
|
||||||
|
|
||||||
$averages[] = array($d, $m);
|
$averages[] = array($d, $m);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '[['.rtrim($json,',').'],';
|
if ($averages[0][1] == 0) $averages[0][1] = $averages[1][1];
|
||||||
echo '[';
|
|
||||||
|
|
||||||
$json = '';
|
$avg2 = array();
|
||||||
$average = $averages[0][1];
|
$average = $averages[0][1];
|
||||||
foreach($averages as $n)
|
foreach($averages as $n) {
|
||||||
{
|
|
||||||
$average = ($average*(100-$percent) + $n[1]*$percent) / 100;
|
$average = ($average*(100-$percent) + $n[1]*$percent) / 100;
|
||||||
$m = round($average, 3);
|
$m = round($average, 3);
|
||||||
|
$avg2[] = array($n[0], $m);
|
||||||
$json .= "[\"{$n[0]}\",$m],";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// $a = 10;
|
echo '['.json_encode($averages).",\n".json_encode($avg2).']';
|
||||||
// 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 ']]';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,62 +1,38 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/* Graph shown in Pool tab, last 24h algo estimates */
|
||||||
|
|
||||||
$percent = 16;
|
$percent = 16;
|
||||||
$algo = user()->getState('yaamp-algo');
|
$algo = user()->getState('yaamp-algo');
|
||||||
|
|
||||||
$step = 15*60;
|
$step = 15*60;
|
||||||
$t = time() - 24*60*60;
|
$t = time() - 24*60*60;
|
||||||
|
$t = intval($t / $step) * $step;
|
||||||
$stats = getdbolist('db_hashrate', "time > $t AND algo=:algo ORDER BY time", array(':algo'=>$algo));
|
$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();
|
$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);
|
$d = date('Y-m-d H:i:s', $t);
|
||||||
$json .= "[\"$d\",0],";
|
$averages[] = array($d, $pfirst);
|
||||||
|
|
||||||
$t += $step;
|
$t += $step;
|
||||||
$averages[] = array($d, 0);
|
if ($t >= $tfirst) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($stats as $n)
|
foreach($stats as $n) {
|
||||||
{
|
$m = (double) altcoinvaluetoa($n->price);
|
||||||
$m = $n->price;
|
|
||||||
|
|
||||||
$d = date('Y-m-d H:i:s', $n->time);
|
$d = date('Y-m-d H:i:s', $n->time);
|
||||||
$json .= "[\"$d\",$m],";
|
|
||||||
|
|
||||||
$averages[] = array($d, $m);
|
$averages[] = array($d, $m);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '[[';
|
$avg2 = array();
|
||||||
echo rtrim($json, ',');
|
|
||||||
echo '],[';
|
|
||||||
|
|
||||||
$json = '';
|
|
||||||
$average = $averages[0][1];
|
$average = $averages[0][1];
|
||||||
foreach($averages as $n)
|
foreach($averages as $n) {
|
||||||
{
|
|
||||||
$average = ($average*(100-$percent) + $n[1]*$percent) / 100;
|
$average = ($average*(100-$percent) + $n[1]*$percent) / 100;
|
||||||
$m = round($average, 5);
|
$m = round($average, 5);
|
||||||
|
|
||||||
$json .= "[\"{$n[0]}\",$m],";
|
$avg2[] = array($n[0], $m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $a = 10;
|
echo '['.json_encode($averages).",\n".json_encode($avg2).']';
|
||||||
// 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 ']]';
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue