console: humanize json timestamps + rpc errors report

This commit is contained in:
Tanguy Pruvot 2016-05-04 16:06:43 +02:00
parent f3c65e270c
commit 0eaca9c541
2 changed files with 42 additions and 20 deletions

View file

@ -17,7 +17,21 @@ echo getAdminWalletLinks($coin, $info, 'console').'<br/><br/>';
//////////////////////////////////////////////////////////////////////////////////////
$last_query = htmlentities($query);
function humanizeJson($json)
{
// timestamps like "blocktime": 1462359961,
$res = preg_match_all("#\": ([0-9]{10}),#", $json, $matches, PREG_OFFSET_CAPTURE);
if ($res) foreach($matches[1] as $m) {
$ts = intval($m[0]);
$date = strftime("%Y-%m-%d %T %z", $ts);
$json = str_replace(' '.$m[0].",", ' "'.$date.'",', $json);
}
return $json;
}
//////////////////////////////////////////////////////////////////////////////////////
$last_query = htmlentities(trim($query));
echo <<<end
<script type="text/javascript">
@ -30,6 +44,7 @@ function main_resize() {
<style type="text/css">
div.form { margin-right: 8px; }
pre.rpcerror { color: darkred; background: transparent; padding: 4px; margin-top: 0; margin-bottom: -12px; margin-right: 8px; }
pre.terminal { color: silver; background: black; padding: 4px; min-height: 180px; margin-right: 8px; }
</style>
@ -44,7 +59,7 @@ end;
$result = '';
if (!empty($query)) try {
$params = split(' ', $query);
$params = split(' ', trim($query));
$command = array_shift($params);
$p = array();
@ -72,6 +87,12 @@ if (!empty($query)) try {
case 5:
$result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4]);
break;
case 6:
$result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5]);
break;
case 7:
$result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6]);
break;
default:
$result = 'error: too much parameters';
}
@ -80,8 +101,15 @@ if (!empty($query)) try {
$result = $remote->error;
}
if (!empty($remote->error) && $remote->error != $result) {
$err = $remote->error;
echo '<pre class="rpcerror">';
echo is_string($err) ? htmlentities($err) : htmlentities(json_encode($err, 128));
echo '</pre>';
}
echo '<pre class="terminal">';
echo is_string($result) ? htmlentities($result) : htmlentities(json_encode($result, 128));
echo is_string($result) ? htmlentities($result) : htmlentities(humanizeJson(json_encode($result, 128)));
echo '</pre>';
JavascriptReady("main_resize(); $(window).resize(main_resize); $('.main-text-input:first').focus();");

View file

@ -6,49 +6,47 @@ $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));
$stats = getdbolist('db_hashrate', "time > $t AND algo=:algo ORDER BY time", array(':algo'=>$algo));
$averages = array();
echo '[[';
$json = '';
for($i = 0; $i < 95-count($stats); $i++)
{
$d = date('Y-m-d H:i:s', $t);
echo "[\"$d\",0],";
$json .= "[\"$d\",0],";
$t += $step;
$averages[] = array($d, 0);
}
foreach($stats as $i=>$n)
foreach($stats as $n)
{
$m = $n->price;
if($i) echo ',';
$d = date('Y-m-d H:i:s', $n->time);
echo "[\"$d\",$m]";
$json .= "[\"$d\",$m],";
$averages[] = array($d, $m);
}
echo '[[';
echo rtrim($json, ',');
echo '],[';
$json = '';
$average = $averages[0][1];
foreach($averages as $i=>$n)
foreach($averages as $n)
{
if($i) echo ',';
$average = ($average*(100-$percent) + $n[1]*$percent) / 100;
$m = round($average, 5);
echo "[\"{$n[0]}\",$m]";
$json .= "[\"{$n[0]}\",$m],";
}
// $a = 10;
// foreach($averages as $i=>$n)
// {
// if($i < $a) continue;
// if($i > $a) echo ',';
// $average = 0;
// for($j = $i-$a+1; $j<=$i; $j++)
@ -59,10 +57,6 @@ foreach($averages as $i=>$n)
// echo "[\"{$n[0]}\",$m]";
// }
echo rtrim($json, ',');
echo ']]';