Add avg mining pool block mathrate in pools stats API
This commit is contained in:
parent
e2585da7aa
commit
e3e7271c9d
@ -100,6 +100,7 @@ class Mining {
|
|||||||
rank: rank++,
|
rank: rank++,
|
||||||
emptyBlocks: emptyBlocksCount.length > 0 ? emptyBlocksCount[0]['count'] : 0,
|
emptyBlocks: emptyBlocksCount.length > 0 ? emptyBlocksCount[0]['count'] : 0,
|
||||||
slug: poolInfo.slug,
|
slug: poolInfo.slug,
|
||||||
|
avgMatchRate: Math.round(100 * poolInfo.avgMatchRate) / 100,
|
||||||
};
|
};
|
||||||
poolsStats.push(poolStat);
|
poolsStats.push(poolStat);
|
||||||
});
|
});
|
||||||
|
@ -16,6 +16,7 @@ export interface PoolInfo {
|
|||||||
link: string;
|
link: string;
|
||||||
blockCount: number;
|
blockCount: number;
|
||||||
slug: string;
|
slug: string;
|
||||||
|
avgMatchRate: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PoolStats extends PoolInfo {
|
export interface PoolStats extends PoolInfo {
|
||||||
|
@ -27,16 +27,25 @@ class PoolsRepository {
|
|||||||
public async $getPoolsInfo(interval: string | null = null): Promise<PoolInfo[]> {
|
public async $getPoolsInfo(interval: string | null = null): Promise<PoolInfo[]> {
|
||||||
interval = Common.getSqlInterval(interval);
|
interval = Common.getSqlInterval(interval);
|
||||||
|
|
||||||
let query = `SELECT COUNT(height) as blockCount, pool_id as poolId, pools.name as name, pools.link as link, slug
|
let query = `
|
||||||
|
SELECT
|
||||||
|
COUNT(blocks.height) As blockCount,
|
||||||
|
pool_id AS poolId,
|
||||||
|
pools.name AS name,
|
||||||
|
pools.link AS link,
|
||||||
|
slug,
|
||||||
|
AVG(blocks_audits.match_rate) AS avgMatchRate
|
||||||
FROM blocks
|
FROM blocks
|
||||||
JOIN pools on pools.id = pool_id`;
|
JOIN pools on pools.id = pool_id
|
||||||
|
LEFT JOIN blocks_audits ON blocks_audits.height = blocks.height
|
||||||
|
`;
|
||||||
|
|
||||||
if (interval) {
|
if (interval) {
|
||||||
query += ` WHERE blocks.blockTimestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()`;
|
query += ` WHERE blocks.blockTimestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()`;
|
||||||
}
|
}
|
||||||
|
|
||||||
query += ` GROUP BY pool_id
|
query += ` GROUP BY pool_id
|
||||||
ORDER BY COUNT(height) DESC`;
|
ORDER BY COUNT(blocks.height) DESC`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [rows] = await DB.query(query);
|
const [rows] = await DB.query(query);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user