Generate daily average hashrate data

This commit is contained in:
nymkappa
2022-02-19 20:45:02 +09:00
parent b93fe2ecc8
commit 5a6f9269b1
7 changed files with 156 additions and 8 deletions

View File

@@ -149,6 +149,40 @@ class BlocksRepository {
return <number>rows[0].blockCount;
}
/**
* Get blocks count between two dates
* @param poolId
* @param from - The oldest timestamp
* @param to - The newest timestamp
* @returns
*/
public async $blockCountBetweenTimestamp(poolId: number | null, from: number, to: number): Promise<number> {
const params: any[] = [];
let query = `SELECT
count(height) as blockCount,
max(height) as lastBlockHeight
FROM blocks`;
if (poolId) {
query += ` WHERE pool_id = ?`;
params.push(poolId);
}
if (poolId) {
query += ` AND`;
} else {
query += ` WHERE`;
}
query += ` UNIX_TIMESTAMP(blockTimestamp) BETWEEN '${from}' AND '${to}'`;
// logger.debug(query);
const connection = await DB.pool.getConnection();
const [rows] = await connection.query(query, params);
connection.release();
return <number>rows[0];
}
/**
* Get the oldest indexed block
*/