Index weekly mining pool hashrate only if there are blocks mined
This commit is contained in:
parent
067ee168dd
commit
07cb4a49bc
@ -223,25 +223,27 @@ class Mining {
|
|||||||
|
|
||||||
let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp / 1000, toTimestamp / 1000);
|
let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp / 1000, toTimestamp / 1000);
|
||||||
const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0);
|
const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0);
|
||||||
pools = pools.map((pool: any) => {
|
if (totalBlocks > 0) {
|
||||||
pool.hashrate = (pool.blockCount / totalBlocks) * lastBlockHashrate;
|
pools = pools.map((pool: any) => {
|
||||||
pool.share = (pool.blockCount / totalBlocks);
|
pool.hashrate = (pool.blockCount / totalBlocks) * lastBlockHashrate;
|
||||||
return pool;
|
pool.share = (pool.blockCount / totalBlocks);
|
||||||
});
|
return pool;
|
||||||
|
|
||||||
for (const pool of pools) {
|
|
||||||
hashrates.push({
|
|
||||||
hashrateTimestamp: toTimestamp / 1000,
|
|
||||||
avgHashrate: pool['hashrate'],
|
|
||||||
poolId: pool.poolId,
|
|
||||||
share: pool['share'],
|
|
||||||
type: 'weekly',
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
newlyIndexed += hashrates.length;
|
for (const pool of pools) {
|
||||||
await HashratesRepository.$saveHashrates(hashrates);
|
hashrates.push({
|
||||||
hashrates.length = 0;
|
hashrateTimestamp: toTimestamp / 1000,
|
||||||
|
avgHashrate: pool['hashrate'] ,
|
||||||
|
poolId: pool.poolId,
|
||||||
|
share: pool['share'],
|
||||||
|
type: 'weekly',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
newlyIndexed += hashrates.length;
|
||||||
|
await HashratesRepository.$saveHashrates(hashrates);
|
||||||
|
hashrates.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - timer));
|
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - timer));
|
||||||
if (elapsedSeconds > 1) {
|
if (elapsedSeconds > 1) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { escape } from 'mysql2';
|
import { escape } from 'mysql2';
|
||||||
import { Common } from '../api/common';
|
import { Common } from '../api/common';
|
||||||
import config from '../config';
|
|
||||||
import DB from '../database';
|
import DB from '../database';
|
||||||
import logger from '../logger';
|
import logger from '../logger';
|
||||||
import PoolsRepository from './PoolsRepository';
|
import PoolsRepository from './PoolsRepository';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user