diff --git a/web/yaamp/modules/site/results/graph_hashrate_results.php b/web/yaamp/modules/site/results/graph_hashrate_results.php index 1741dd9..b585fb0 100644 --- a/web/yaamp/modules/site/results/graph_hashrate_results.php +++ b/web/yaamp/modules/site/results/graph_hashrate_results.php @@ -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).']'; diff --git a/web/yaamp/modules/site/results/graph_price_results.php b/web/yaamp/modules/site/results/graph_price_results.php index 50536c5..77873cb 100644 --- a/web/yaamp/modules/site/results/graph_price_results.php +++ b/web/yaamp/modules/site/results/graph_price_results.php @@ -1,62 +1,38 @@ 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).']';