Added hashrate chart

This commit is contained in:
nymkappa
2022-02-19 22:09:35 +09:00
parent 5a6f9269b1
commit cc2890fd60
8 changed files with 284 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
import { Common } from '../api/common';
import { DB } from '../database';
import logger from '../logger';
@@ -30,12 +31,22 @@ class HashratesRepository {
/**
* Returns an array of all timestamp we've already indexed
*/
public async $getAllTimestamp(): Promise<number[]> {
public async $get(interval: string | null): Promise<any[]> {
interval = Common.getSqlInterval(interval);
const connection = await DB.pool.getConnection();
const [rows]: any[] = await connection.query(`SELECT UNIX_TIMESTAMP(hashrate_timestamp) as timestamp from hashrates`);
let query = `SELECT UNIX_TIMESTAMP(hashrate_timestamp) as timestamp, avg_hashrate as avgHashrate
FROM hashrates`;
if (interval) {
query += ` WHERE hashrate_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()`;
}
const [rows]: any[] = await connection.query(query);
connection.release();
return rows.map(val => val.timestamp);
return rows;
}
}