Skip to content

Commit 4dcd98d

Browse files
committed
[UPDATE] Use 24h range for account based graphs
1 parent 26802fd commit 4dcd98d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

include/classes/statistics.class.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,13 @@ public function getHashrateByAccount($account_id, $format='array') {
704704
$stmt = $this->mysqli->prepare("
705705
SELECT
706706
timestamp,
707-
FROM_UNIXTIME(timestamp, '%Y-%m-%d %T') AS time,
708-
hashrate
707+
FROM_UNIXTIME(timestamp, '%Y-%m-%d %H:%i') AS time,
708+
AVG(hashrate) AS hashrate
709709
FROM " . $this->getUserStatsTableName() . "
710-
WHERE
711-
account_id = ?");
712-
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) {
710+
WHERE FROM_UNIXTIME(timestamp) >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
711+
AND account_id = ?
712+
GROUP BY HOUR(FROM_UNIXTIME(timestamp))");
713+
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id ) && $stmt->execute() && $result = $stmt->get_result()) {
713714
$aData = $result->fetch_all(MYSQLI_ASSOC);
714715
if ($format == 'json') $aData = json_encode($aData);
715716
return $this->memcache->setCache(__FUNCTION__ . $account_id . $format, $aData);
@@ -729,11 +730,14 @@ public function getHashrateForPool($format='array') {
729730
SELECT
730731
timestamp,
731732
FROM_UNIXTIME(timestamp, '%Y-%m-%d %T') AS time,
732-
SUM(hashrate) AS hashrate
733-
FROM " . $this->getUserStatsTableName() . "
734-
GROUP BY timestamp");
733+
SUM(DISTINCT account_id)
734+
FROM " . $this->getUserStatsTableName() . "
735+
WHERE timestamp >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
736+
GROUP BY HOUR(FROM_UNIXTIME(timestamp))");
735737
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) {
738+
// return json_encode(array(time() * 1000, 1000));
736739
$aData = $result->fetch_all(MYSQLI_ASSOC);
740+
var_dump($aData);
737741
if ($format == 'json') $aData = json_encode($aData);
738742
return $this->memcache->setCache(__FUNCTION__ . $format, $aData);
739743
}

0 commit comments

Comments
 (0)