history: improve the stacked graph series with missing data

+ optional hack to allow to store decred staking (locked) balance history
This commit is contained in:
Tanguy Pruvot 2016-05-01 12:28:57 +02:00
parent 2300314280
commit 2d1af265fa
3 changed files with 42 additions and 8 deletions

View file

@ -109,6 +109,19 @@ function BackendWatchMarkets($marketname=NULL)
$mh->save();
}
if ($coin->rpcencoding == 'DCR') {
// hack to store the locked balance history as a "stake" market
$remote = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport);
$stake = (double) $remote->getbalance('*',0,'locked');
$info = $remote->getstakeinfo();
if (empty($remote->error) && isset($info['difficulty']))
dborun("UPDATE markets SET balance=0, ontrade=:stake, balancetime=:time,
price=:ticketprice, price2=:live, pricetime=NULL WHERE coinid=:id AND name='stake'", array(
':ticketprice'=>$info['difficulty'], ':live'=>$info['live'], ':stake'=>$stake,
':id'=>$coin->id, ':time'=>time()
));
}
// user watched currencies
$markets = getdbolist('db_markets', "coinid={$coin->id} AND NOT disabled");
foreach($markets as $market) {
@ -116,7 +129,7 @@ function BackendWatchMarkets($marketname=NULL)
if (!empty($market->base_coin)) continue; // todo ?
if (empty($market->price)) continue;
$mh = new db_market_history;
$mh->time = time();
$mh->time = time(); // max(intval($market->balancetime), intval($market->pricetime));
$mh->idcoin = $coin->id;
$mh->idmarket = $market->id;
$mh->price = $market->price;

View file

@ -9,7 +9,7 @@ if (!$coin) return;
$t = time() - 7*24*60*60;
$markets = dbolist("SELECT M.id, M.name, M.priority, MIN(MH.balance) AS min, MAX(MH.balance) AS max
FROM market_history MH LEFT JOIN markets M ON M.id = MH.idmarket
FROM market_history MH INNER JOIN markets M ON M.id = MH.idmarket
WHERE MH.idcoin=$id AND MH.time>$t AND NOT M.disabled
GROUP BY M.id, M.name, M.priority HAVING max > 0
ORDER BY M.priority DESC, M.name");
@ -47,14 +47,35 @@ foreach($stats as $histo) {
$stackedMax += $max;
// Stacked graph specific : seems to require same amount of points :/
$max = 0;
foreach ($series as $serie) {
$max = 0; $seriefull = '';
foreach ($series as $name => $serie) {
if (count($serie) > $max) $seriefull = $name;
$max = max($max, count($serie));
}
foreach ($series as $name => $serie) {
$n = count($serie);
for ($i = count($serie); $i < $max; $i++) {
array_unshift($series[$name], $series[$name][0]);
if ($seriefull && count($serie) < $max) {
$first_dt = $serie[0][0];
$fill_start = ($first_dt > $series[$seriefull][0][0]);
}
for ($i = count($serie), $n = 0; $i < $max; $i++, $n++) {
if ($seriefull == '') {
$dt = $serie[0][0];
array_unshift($series[$name], array($dt, 0));
continue;
}
if ($fill_start) {
if ($series[$seriefull][$n][0] >= $first_dt) {
array_unshift($series[$name], array($dt, 0));
$fill_start = false;
} else {
$dt = $series[$seriefull][$n][0];
array_unshift($series[$name], array($dt, 0));
}
} else {
$dt = $series[$seriefull][$i][0];
$last = end($series[$name]);
$series[$name][] = array($dt, $last[1]);
}
}
}

View file

@ -10,7 +10,7 @@ $t = time() - 7*24*60*60;
$markets = dbolist("SELECT M.id AS id, M.name, M.priority, MIN(MH.price) AS min, MAX(MH.price) AS max
FROM market_history MH LEFT JOIN markets M ON M.id = MH.idmarket
WHERE MH.idcoin=$id AND MH.time>$t AND NOT M.disabled
WHERE MH.idcoin=$id AND MH.time>$t AND NOT M.disabled AND M.name != 'stake'
GROUP BY M.id, M.name, M.priority
ORDER BY M.priority DESC, M.name");