Fix home graph hashrate calculation (around restarts)

This commit is contained in:
Benjamin Wilson
2025-01-02 23:34:43 -05:00
parent ae7ed021a3
commit 220a1d1558
+7 -2
View File
@@ -68,16 +68,21 @@ export class AppService implements OnModuleInit {
console.log('Updating Chart'); console.log('Updating Chart');
const latestGraphUpdate = await this.homeGraphService.getLatestTime(); const latestGraphUpdate = await this.homeGraphService.getLatestTime();
const latestGraphUpdateMilliseconds = latestGraphUpdate.getTime();
const now = new Date();
const diffInMilliseconds = now.getTime() - latestGraphUpdateMilliseconds;
const latestGraphUpdateSeconds = Math.floor(diffInMilliseconds / 1000); // Convert milliseconds to seconds
const data = await this.dataSource.query(` const data = await this.dataSource.query(`
SELECT SELECT
time AS label, time AS label,
ROUND(((SUM(shares) * 4294967296) / 600)) AS data ROUND(((SUM(shares) * 4294967296) / ${latestGraphUpdateSeconds})) AS data
FROM FROM
client_statistics_entity AS entry client_statistics_entity AS entry
WHERE WHERE
entry.time > ${latestGraphUpdate.getTime()} entry.time > ${latestGraphUpdateMilliseconds}
GROUP BY GROUP BY
time time
ORDER BY ORDER BY