Added hashrate chart
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user