Merge pull request #1285 from nymkappa/feature/pool-hashrate
Create pools hashrate dominance chart
This commit is contained in:
		
						commit
						7228d07b52
					
				| @ -6,7 +6,7 @@ import logger from '../logger'; | |||||||
| const sleep = (ms: number) => new Promise(res => setTimeout(res, ms)); | const sleep = (ms: number) => new Promise(res => setTimeout(res, ms)); | ||||||
| 
 | 
 | ||||||
| class DatabaseMigration { | class DatabaseMigration { | ||||||
|   private static currentVersion = 7; |   private static currentVersion = 8; | ||||||
|   private queryTimeout = 120000; |   private queryTimeout = 120000; | ||||||
|   private statisticsAddedIndexed = false; |   private statisticsAddedIndexed = false; | ||||||
| 
 | 
 | ||||||
| @ -92,11 +92,13 @@ class DatabaseMigration { | |||||||
|         await this.$executeQuery(connection, this.getCreateBlocksTableQuery(), await this.$checkIfTableExists('blocks')); |         await this.$executeQuery(connection, this.getCreateBlocksTableQuery(), await this.$checkIfTableExists('blocks')); | ||||||
|       } |       } | ||||||
|       if (databaseSchemaVersion < 5 && isBitcoin === true) { |       if (databaseSchemaVersion < 5 && isBitcoin === true) { | ||||||
|  |         logger.warn(`'blocks' table has been truncated. Re-indexing from scratch.'`); | ||||||
|         await this.$executeQuery(connection, 'TRUNCATE blocks;'); // Need to re-index
 |         await this.$executeQuery(connection, 'TRUNCATE blocks;'); // Need to re-index
 | ||||||
|         await this.$executeQuery(connection, 'ALTER TABLE blocks ADD `reward` double unsigned NOT NULL DEFAULT "0"'); |         await this.$executeQuery(connection, 'ALTER TABLE blocks ADD `reward` double unsigned NOT NULL DEFAULT "0"'); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (databaseSchemaVersion < 6 && isBitcoin === true) { |       if (databaseSchemaVersion < 6 && isBitcoin === true) { | ||||||
|  |         logger.warn(`'blocks' table has been truncated. Re-indexing from scratch.'`); | ||||||
|         await this.$executeQuery(connection, 'TRUNCATE blocks;');  // Need to re-index
 |         await this.$executeQuery(connection, 'TRUNCATE blocks;');  // Need to re-index
 | ||||||
|         // Cleanup original blocks fields type
 |         // Cleanup original blocks fields type
 | ||||||
|         await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `height` integer unsigned NOT NULL DEFAULT "0"'); |         await this.$executeQuery(connection, 'ALTER TABLE blocks MODIFY `height` integer unsigned NOT NULL DEFAULT "0"'); | ||||||
| @ -122,6 +124,15 @@ class DatabaseMigration { | |||||||
|         await this.$executeQuery(connection, this.getCreateDailyStatsTableQuery(), await this.$checkIfTableExists('hashrates')); |         await this.$executeQuery(connection, this.getCreateDailyStatsTableQuery(), await this.$checkIfTableExists('hashrates')); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|  |       if (databaseSchemaVersion < 8 && isBitcoin === true) { | ||||||
|  |         logger.warn(`'hashrates' table has been truncated. Re-indexing from scratch.'`); | ||||||
|  |         await this.$executeQuery(connection, 'TRUNCATE hashrates;'); // Need to re-index
 | ||||||
|  |         await this.$executeQuery(connection, 'ALTER TABLE `hashrates` DROP INDEX `PRIMARY`'); | ||||||
|  |         await this.$executeQuery(connection, 'ALTER TABLE `hashrates` ADD `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); | ||||||
|  |         await this.$executeQuery(connection, 'ALTER TABLE `hashrates` ADD `share` float NOT NULL DEFAULT "0"'); | ||||||
|  |         await this.$executeQuery(connection, 'ALTER TABLE `hashrates` ADD `type` enum("daily", "weekly") DEFAULT "daily"'); | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|       connection.release(); |       connection.release(); | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       connection.release(); |       connection.release(); | ||||||
|  | |||||||
| @ -83,8 +83,15 @@ class Mining { | |||||||
|   /** |   /** | ||||||
|    * Return the historical hashrates and oldest indexed block timestamp |    * Return the historical hashrates and oldest indexed block timestamp | ||||||
|    */ |    */ | ||||||
|   public async $getHistoricalHashrates(interval: string | null): Promise<object> { |   public async $getNetworkHistoricalHashrates(interval: string | null): Promise<object> { | ||||||
|     return await HashratesRepository.$get(interval); |     return await HashratesRepository.$getNetworkDailyHashrate(interval); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Return the historical hashrates and oldest indexed block timestamp for one or all pools | ||||||
|  |    */ | ||||||
|  |    public async $getPoolsHistoricalHashrates(interval: string | null, poolId: number): Promise<object> { | ||||||
|  |     return await HashratesRepository.$getPoolsWeeklyHashrate(interval); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
| @ -106,7 +113,7 @@ class Mining { | |||||||
|     logger.info(`Indexing hashrates`); |     logger.info(`Indexing hashrates`); | ||||||
| 
 | 
 | ||||||
|     const totalDayIndexed = (await BlocksRepository.$blockCount(null, null)) / 144; |     const totalDayIndexed = (await BlocksRepository.$blockCount(null, null)) / 144; | ||||||
|     const indexedTimestamp = (await HashratesRepository.$get(null)).map(hashrate => hashrate.timestamp); |     const indexedTimestamp = (await HashratesRepository.$getNetworkDailyHashrate(null)).map(hashrate => hashrate.timestamp); | ||||||
|     let startedAt = new Date().getTime() / 1000; |     let startedAt = new Date().getTime() / 1000; | ||||||
|     const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
 |     const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
 | ||||||
|     const lastMidnight = new Date(); |     const lastMidnight = new Date(); | ||||||
| @ -135,38 +142,62 @@ class Mining { | |||||||
|       lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount, |       lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount, | ||||||
|         blockStats.lastBlockHeight); |         blockStats.lastBlockHeight); | ||||||
| 
 | 
 | ||||||
|       const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt)); |       if (totalIndexed % 7 === 0 && !indexedTimestamp.includes(fromTimestamp + 1)) { // Save weekly pools hashrate
 | ||||||
|       if (elapsedSeconds > 10) { |         logger.debug("Indexing weekly hashrates for mining pools"); | ||||||
|         const daysPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds)); |         let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp - 604800, fromTimestamp); | ||||||
|         const formattedDate = new Date(fromTimestamp * 1000).toUTCString(); |         const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0); | ||||||
|         const daysLeft = Math.round(totalDayIndexed - totalIndexed); |         pools = pools.map((pool: any) => { | ||||||
|         logger.debug(`Getting hashrate for ${formattedDate} | ~${daysPerSeconds} days/sec | ~${daysLeft} days left to index`); |           pool.hashrate = (pool.blockCount / totalBlocks) * lastBlockHashrate; | ||||||
|         startedAt = new Date().getTime() / 1000; |           pool.share = (pool.blockCount / totalBlocks); | ||||||
|         indexedThisRun = 0; |           return pool; | ||||||
|  |         }); | ||||||
|  |    | ||||||
|  |         for (const pool of pools) { | ||||||
|  |           hashrates.push({ | ||||||
|  |             hashrateTimestamp: fromTimestamp + 1, | ||||||
|  |             avgHashrate: pool['hashrate'], | ||||||
|  |             poolId: pool.poolId, | ||||||
|  |             share: pool['share'], | ||||||
|  |             type: 'weekly', | ||||||
|  |           }); | ||||||
|  |         } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       hashrates.push({ |       hashrates.push({ | ||||||
|         hashrateTimestamp: fromTimestamp, |         hashrateTimestamp: fromTimestamp, | ||||||
|         avgHashrate: lastBlockHashrate, |         avgHashrate: lastBlockHashrate, | ||||||
|         poolId: null, |         poolId: null, | ||||||
|  |         share: 1, | ||||||
|  |         type: 'daily', | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|       if (hashrates.length > 100) { |       if (hashrates.length > 10) { | ||||||
|         await HashratesRepository.$saveHashrates(hashrates); |         await HashratesRepository.$saveHashrates(hashrates); | ||||||
|         hashrates.length = 0; |         hashrates.length = 0; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|  |       const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt)); | ||||||
|  |       if (elapsedSeconds > 5) { | ||||||
|  |         const daysPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2); | ||||||
|  |         const formattedDate = new Date(fromTimestamp * 1000).toUTCString(); | ||||||
|  |         const daysLeft = Math.round(totalDayIndexed - totalIndexed); | ||||||
|  |         logger.debug(`Getting hashrate for ${formattedDate} | ~${daysPerSeconds} days/sec | ~${daysLeft} days left to index`); | ||||||
|  |         startedAt = new Date().getTime() / 1000; | ||||||
|  |         indexedThisRun = 0; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|       toTimestamp -= 86400; |       toTimestamp -= 86400; | ||||||
|       ++indexedThisRun; |       ++indexedThisRun; | ||||||
|       ++totalIndexed; |       ++totalIndexed; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Add genesis block manually
 |     // Add genesis block manually
 | ||||||
|     if (!indexedTimestamp.includes(genesisTimestamp)) { |     if (toTimestamp <= genesisTimestamp && !indexedTimestamp.includes(genesisTimestamp)) { | ||||||
|       hashrates.push({ |       hashrates.push({ | ||||||
|         hashrateTimestamp: genesisTimestamp, |         hashrateTimestamp: genesisTimestamp, | ||||||
|         avgHashrate: await bitcoinClient.getNetworkHashPs(1, 1), |         avgHashrate: await bitcoinClient.getNetworkHashPs(1, 1), | ||||||
|         poolId: null |         poolId: null, | ||||||
|  |         type: 'daily', | ||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -27,6 +27,7 @@ import syncAssets from './sync-assets'; | |||||||
| import icons from './api/liquid/icons'; | import icons from './api/liquid/icons'; | ||||||
| import { Common } from './api/common'; | import { Common } from './api/common'; | ||||||
| import mining from './api/mining'; | import mining from './api/mining'; | ||||||
|  | import HashratesRepository from './repositories/HashratesRepository'; | ||||||
| 
 | 
 | ||||||
| class Server { | class Server { | ||||||
|   private wss: WebSocket.Server | undefined; |   private wss: WebSocket.Server | undefined; | ||||||
| @ -95,6 +96,7 @@ class Server { | |||||||
|           await Common.sleep(5000); |           await Common.sleep(5000); | ||||||
|           await databaseMigration.$truncateIndexedData(tables); |           await databaseMigration.$truncateIndexedData(tables); | ||||||
|         } |         } | ||||||
|  |         await this.$resetHashratesIndexingState(); | ||||||
|         await databaseMigration.$initializeOrMigrateDatabase(); |         await databaseMigration.$initializeOrMigrateDatabase(); | ||||||
|         await poolsParser.migratePoolsJson(); |         await poolsParser.migratePoolsJson(); | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
| @ -145,7 +147,7 @@ class Server { | |||||||
|       } |       } | ||||||
|       await blocks.$updateBlocks(); |       await blocks.$updateBlocks(); | ||||||
|       await memPool.$updateMempool(); |       await memPool.$updateMempool(); | ||||||
|       this.runIndexingWhenReady(); |       this.$runIndexingWhenReady(); | ||||||
| 
 | 
 | ||||||
|       setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS); |       setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS); | ||||||
|       this.currentBackendRetryInterval = 5; |       this.currentBackendRetryInterval = 5; | ||||||
| @ -164,7 +166,11 @@ class Server { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async runIndexingWhenReady() { |   async $resetHashratesIndexingState() { | ||||||
|  |     return await HashratesRepository.$setLatestRunTimestamp(0);     | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   async $runIndexingWhenReady() { | ||||||
|     if (!Common.indexingEnabled() || mempool.hasPriority()) { |     if (!Common.indexingEnabled() || mempool.hasPriority()) { | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
| @ -297,8 +303,11 @@ class Server { | |||||||
|         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId/:interval', routes.$getPool) |         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId/:interval', routes.$getPool) | ||||||
|         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/difficulty', routes.$getHistoricalDifficulty) |         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/difficulty', routes.$getHistoricalDifficulty) | ||||||
|         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/difficulty/:interval', routes.$getHistoricalDifficulty) |         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/difficulty/:interval', routes.$getHistoricalDifficulty) | ||||||
|  |         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/hashrate/pools', routes.$getPoolsHistoricalHashrate) | ||||||
|  |         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/hashrate/pools/:interval', routes.$getPoolsHistoricalHashrate) | ||||||
|         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/hashrate', routes.$getHistoricalHashrate) |         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/hashrate', routes.$getHistoricalHashrate) | ||||||
|         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/hashrate/:interval', routes.$getHistoricalHashrate); |         .get(config.MEMPOOL.API_URL_PREFIX + 'mining/hashrate/:interval', routes.$getHistoricalHashrate) | ||||||
|  |       ; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (config.BISQ.ENABLED) { |     if (config.BISQ.ENABLED) { | ||||||
|  | |||||||
| @ -173,7 +173,7 @@ class BlocksRepository { | |||||||
|     } else { |     } else { | ||||||
|       query += ` WHERE`; |       query += ` WHERE`; | ||||||
|     } |     } | ||||||
|     query += ` UNIX_TIMESTAMP(blockTimestamp) BETWEEN '${from}' AND '${to}'`; |     query += ` blockTimestamp BETWEEN FROM_UNIXTIME('${from}') AND FROM_UNIXTIME('${to}')`; | ||||||
| 
 | 
 | ||||||
|     // logger.debug(query);
 |     // logger.debug(query);
 | ||||||
|     const connection = await DB.pool.getConnection(); |     const connection = await DB.pool.getConnection(); | ||||||
| @ -300,6 +300,10 @@ class BlocksRepository { | |||||||
|     const [rows]: any[] = await connection.query(query); |     const [rows]: any[] = await connection.query(query); | ||||||
|     connection.release(); |     connection.release(); | ||||||
| 
 | 
 | ||||||
|  |     for (let row of rows) { | ||||||
|  |       delete row['rn']; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return rows; |     return rows; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| import { Common } from '../api/common'; | import { Common } from '../api/common'; | ||||||
| import { DB } from '../database'; | import { DB } from '../database'; | ||||||
| import logger from '../logger'; | import logger from '../logger'; | ||||||
|  | import PoolsRepository from './PoolsRepository'; | ||||||
| 
 | 
 | ||||||
| class HashratesRepository { | class HashratesRepository { | ||||||
|   /** |   /** | ||||||
| @ -8,10 +9,10 @@ class HashratesRepository { | |||||||
|    */ |    */ | ||||||
|   public async $saveHashrates(hashrates: any) { |   public async $saveHashrates(hashrates: any) { | ||||||
|     let query = `INSERT INTO
 |     let query = `INSERT INTO
 | ||||||
|       hashrates(hashrate_timestamp, avg_hashrate, pool_id) VALUES`;
 |       hashrates(hashrate_timestamp, avg_hashrate, pool_id, share, type) VALUES`;
 | ||||||
| 
 | 
 | ||||||
|     for (const hashrate of hashrates) { |     for (const hashrate of hashrates) { | ||||||
|       query += ` (FROM_UNIXTIME(${hashrate.hashrateTimestamp}), ${hashrate.avgHashrate}, ${hashrate.poolId}),`; |       query += ` (FROM_UNIXTIME(${hashrate.hashrateTimestamp}), ${hashrate.avgHashrate}, ${hashrate.poolId}, ${hashrate.share}, "${hashrate.type}"),`; | ||||||
|     } |     } | ||||||
|     query = query.slice(0, -1); |     query = query.slice(0, -1); | ||||||
| 
 | 
 | ||||||
| @ -26,10 +27,7 @@ class HashratesRepository { | |||||||
|     connection.release(); |     connection.release(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |   public async $getNetworkDailyHashrate(interval: string | null): Promise<any[]> { | ||||||
|    * Returns an array of all timestamp we've already indexed |  | ||||||
|    */ |  | ||||||
|   public async $get(interval: string | null): Promise<any[]> { |  | ||||||
|     interval = Common.getSqlInterval(interval); |     interval = Common.getSqlInterval(interval); | ||||||
| 
 | 
 | ||||||
|     const connection = await DB.pool.getConnection(); |     const connection = await DB.pool.getConnection(); | ||||||
| @ -38,7 +36,12 @@ class HashratesRepository { | |||||||
|       FROM hashrates`;
 |       FROM hashrates`;
 | ||||||
| 
 | 
 | ||||||
|     if (interval) { |     if (interval) { | ||||||
|       query += ` WHERE hashrate_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()`; |       query += ` WHERE hashrate_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()
 | ||||||
|  |         AND hashrates.type = 'daily' | ||||||
|  |         AND pool_id IS NULL`;
 | ||||||
|  |     } else { | ||||||
|  |       query += ` WHERE hashrates.type = 'daily'
 | ||||||
|  |         AND pool_id IS NULL`;
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     query += ` ORDER by hashrate_timestamp`; |     query += ` ORDER by hashrate_timestamp`; | ||||||
| @ -49,10 +52,41 @@ class HashratesRepository { | |||||||
|     return rows; |     return rows; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public async $setLatestRunTimestamp() { |   /** | ||||||
|  |    * Returns the current biggest pool hashrate history | ||||||
|  |    */ | ||||||
|  |   public async $getPoolsWeeklyHashrate(interval: string | null): Promise<any[]> { | ||||||
|  |     interval = Common.getSqlInterval(interval); | ||||||
|  | 
 | ||||||
|  |     const connection = await DB.pool.getConnection(); | ||||||
|  |     const topPoolsId = (await PoolsRepository.$getPoolsInfo('1w')).map((pool) => pool.poolId); | ||||||
|  | 
 | ||||||
|  |     let query = `SELECT UNIX_TIMESTAMP(hashrate_timestamp) as timestamp, avg_hashrate as avgHashrate, share, pools.name as poolName
 | ||||||
|  |       FROM hashrates | ||||||
|  |       JOIN pools on pools.id = pool_id`;
 | ||||||
|  | 
 | ||||||
|  |     if (interval) { | ||||||
|  |       query += ` WHERE hashrate_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()
 | ||||||
|  |         AND hashrates.type = 'weekly' | ||||||
|  |         AND pool_id IN (${topPoolsId})`;
 | ||||||
|  |     } else { | ||||||
|  |       query += ` WHERE hashrates.type = 'weekly'
 | ||||||
|  |         AND pool_id IN (${topPoolsId})`;
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     query += ` ORDER by hashrate_timestamp, FIELD(pool_id, ${topPoolsId})`; | ||||||
|  | 
 | ||||||
|  |     const [rows]: any[] = await connection.query(query); | ||||||
|  |     connection.release(); | ||||||
|  | 
 | ||||||
|  |     return rows; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   public async $setLatestRunTimestamp(val: any = null) { | ||||||
|     const connection = await DB.pool.getConnection(); |     const connection = await DB.pool.getConnection(); | ||||||
|     const query = `UPDATE state SET number = ? WHERE name = 'last_hashrates_indexing'`; |     const query = `UPDATE state SET number = ? WHERE name = 'last_hashrates_indexing'`; | ||||||
|     await connection.query<any>(query, [Math.round(new Date().getTime() / 1000)]); | 
 | ||||||
|  |     await connection.query<any>(query, (val === null) ? [Math.round(new Date().getTime() / 1000)] : [val]); | ||||||
|     connection.release(); |     connection.release(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -49,6 +49,22 @@ class PoolsRepository { | |||||||
|     return <PoolInfo[]>rows; |     return <PoolInfo[]>rows; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   /** | ||||||
|  |    * Get basic pool info and block count between two timestamp | ||||||
|  |    */ | ||||||
|  |    public async $getPoolsInfoBetween(from: number, to: number): Promise<PoolInfo[]> { | ||||||
|  |     let query = `SELECT COUNT(height) as blockCount, pools.id as poolId, pools.name as poolName
 | ||||||
|  |       FROM pools | ||||||
|  |       LEFT JOIN blocks on pools.id = blocks.pool_id AND blocks.blockTimestamp BETWEEN FROM_UNIXTIME(?) AND FROM_UNIXTIME(?) | ||||||
|  |       GROUP BY pools.id`;
 | ||||||
|  | 
 | ||||||
|  |     const connection = await DB.pool.getConnection(); | ||||||
|  |     const [rows] = await connection.query(query, [from, to]); | ||||||
|  |     connection.release(); | ||||||
|  | 
 | ||||||
|  |     return <PoolInfo[]>rows; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   /** |   /** | ||||||
|    * Get mining pool statistics for one pool |    * Get mining pool statistics for one pool | ||||||
|    */ |    */ | ||||||
|  | |||||||
| @ -586,9 +586,25 @@ class Routes { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   public async $getPoolsHistoricalHashrate(req: Request, res: Response) { | ||||||
|  |     try { | ||||||
|  |       const hashrates = await mining.$getPoolsHistoricalHashrates(req.params.interval ?? null, parseInt(req.params.poolId, 10)); | ||||||
|  |       const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp(); | ||||||
|  |       res.header('Pragma', 'public'); | ||||||
|  |       res.header('Cache-control', 'public'); | ||||||
|  |       res.setHeader('Expires', new Date(Date.now() + 1000 * 300).toUTCString()); | ||||||
|  |       res.json({ | ||||||
|  |         oldestIndexedBlockTimestamp: oldestIndexedBlockTimestamp, | ||||||
|  |         hashrates: hashrates, | ||||||
|  |       }); | ||||||
|  |     } catch (e) { | ||||||
|  |       res.status(500).send(e instanceof Error ? e.message : e); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   public async $getHistoricalHashrate(req: Request, res: Response) { |   public async $getHistoricalHashrate(req: Request, res: Response) { | ||||||
|     try { |     try { | ||||||
|       const hashrates = await mining.$getHistoricalHashrates(req.params.interval ?? null); |       const hashrates = await mining.$getNetworkHistoricalHashrates(req.params.interval ?? null); | ||||||
|       const difficulty = await mining.$getHistoricalDifficulty(req.params.interval ?? null); |       const difficulty = await mining.$getHistoricalDifficulty(req.params.interval ?? null); | ||||||
|       const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp(); |       const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp(); | ||||||
|       res.header('Pragma', 'public'); |       res.header('Pragma', 'public'); | ||||||
|  | |||||||
| @ -29,6 +29,7 @@ import { AssetsComponent } from './components/assets/assets.component'; | |||||||
| import { PoolComponent } from './components/pool/pool.component'; | import { PoolComponent } from './components/pool/pool.component'; | ||||||
| import { MiningDashboardComponent } from './components/mining-dashboard/mining-dashboard.component'; | import { MiningDashboardComponent } from './components/mining-dashboard/mining-dashboard.component'; | ||||||
| import { HashrateChartComponent } from './components/hashrate-chart/hashrate-chart.component'; | import { HashrateChartComponent } from './components/hashrate-chart/hashrate-chart.component'; | ||||||
|  | import { HashrateChartPoolsComponent } from './components/hashrates-chart-pools/hashrate-chart-pools.component'; | ||||||
| import { MiningStartComponent } from './components/mining-start/mining-start.component'; | import { MiningStartComponent } from './components/mining-start/mining-start.component'; | ||||||
| 
 | 
 | ||||||
| let routes: Routes = [ | let routes: Routes = [ | ||||||
| @ -78,6 +79,10 @@ let routes: Routes = [ | |||||||
|             path: 'hashrate', |             path: 'hashrate', | ||||||
|             component: HashrateChartComponent, |             component: HashrateChartComponent, | ||||||
|           }, |           }, | ||||||
|  |           { | ||||||
|  |             path: 'hashrate/pools', | ||||||
|  |             component: HashrateChartPoolsComponent, | ||||||
|  |           }, | ||||||
|           { |           { | ||||||
|             path: 'pools', |             path: 'pools', | ||||||
|             component: PoolRankingComponent, |             component: PoolRankingComponent, | ||||||
| @ -89,10 +94,6 @@ let routes: Routes = [ | |||||||
|                 path: ':poolId', |                 path: ':poolId', | ||||||
|                 component: PoolComponent, |                 component: PoolComponent, | ||||||
|               }, |               }, | ||||||
|               { |  | ||||||
|                 path: ':poolId/hashrate', |  | ||||||
|                 component: HashrateChartComponent, |  | ||||||
|               }, |  | ||||||
|             ] |             ] | ||||||
|           }, |           }, | ||||||
|         ] |         ] | ||||||
| @ -193,6 +194,10 @@ let routes: Routes = [ | |||||||
|                 path: 'hashrate', |                 path: 'hashrate', | ||||||
|                 component: HashrateChartComponent, |                 component: HashrateChartComponent, | ||||||
|               }, |               }, | ||||||
|  |               { | ||||||
|  |                 path: 'hashrate/pools', | ||||||
|  |                 component: HashrateChartPoolsComponent, | ||||||
|  |               }, | ||||||
|               { |               { | ||||||
|                 path: 'pools', |                 path: 'pools', | ||||||
|                 component: PoolRankingComponent, |                 component: PoolRankingComponent, | ||||||
| @ -204,10 +209,6 @@ let routes: Routes = [ | |||||||
|                     path: ':poolId', |                     path: ':poolId', | ||||||
|                     component: PoolComponent, |                     component: PoolComponent, | ||||||
|                   }, |                   }, | ||||||
|                   { |  | ||||||
|                     path: ':poolId/hashrate', |  | ||||||
|                     component: HashrateChartComponent, |  | ||||||
|                   }, |  | ||||||
|                 ] |                 ] | ||||||
|               }, |               }, | ||||||
|             ] |             ] | ||||||
| @ -302,6 +303,10 @@ let routes: Routes = [ | |||||||
|                 path: 'hashrate', |                 path: 'hashrate', | ||||||
|                 component: HashrateChartComponent, |                 component: HashrateChartComponent, | ||||||
|               }, |               }, | ||||||
|  |               { | ||||||
|  |                 path: 'hashrate/pools', | ||||||
|  |                 component: HashrateChartPoolsComponent, | ||||||
|  |               }, | ||||||
|               { |               { | ||||||
|                 path: 'pools', |                 path: 'pools', | ||||||
|                 component: PoolRankingComponent, |                 component: PoolRankingComponent, | ||||||
| @ -313,10 +318,6 @@ let routes: Routes = [ | |||||||
|                     path: ':poolId', |                     path: ':poolId', | ||||||
|                     component: PoolComponent, |                     component: PoolComponent, | ||||||
|                   }, |                   }, | ||||||
|                   { |  | ||||||
|                     path: ':poolId/hashrate', |  | ||||||
|                     component: HashrateChartComponent, |  | ||||||
|                   }, |  | ||||||
|                 ] |                 ] | ||||||
|               }, |               }, | ||||||
|             ] |             ] | ||||||
|  | |||||||
| @ -71,6 +71,22 @@ export const chartColors = [ | |||||||
|   "#263238", |   "#263238", | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
|  | export const poolsColor = { | ||||||
|  |    'foundryusa': '#D81B60', | ||||||
|  |    'antpool': '#8E24AA', | ||||||
|  |    'f2pool': '#5E35B1', | ||||||
|  |    'poolin': '#3949AB', | ||||||
|  |    'binancepool': '#1E88E5', | ||||||
|  |    'viabtc': '#039BE5', | ||||||
|  |    'btccom': '#00897B', | ||||||
|  |    'slushpool': '#00ACC1', | ||||||
|  |    'sbicrypto': '#43A047', | ||||||
|  |    'marapool': '#7CB342', | ||||||
|  |    'luxor': '#C0CA33', | ||||||
|  |    'unknown': '#FDD835', | ||||||
|  |    'okkong': '#FFB300', | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  export const feeLevels = [1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, |  export const feeLevels = [1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, | ||||||
|   250, 300, 350, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000]; |   250, 300, 350, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000]; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -71,6 +71,7 @@ import { AssetGroupComponent } from './components/assets/asset-group/asset-group | |||||||
| import { AssetCirculationComponent } from './components/asset-circulation/asset-circulation.component'; | import { AssetCirculationComponent } from './components/asset-circulation/asset-circulation.component'; | ||||||
| import { MiningDashboardComponent } from './components/mining-dashboard/mining-dashboard.component'; | import { MiningDashboardComponent } from './components/mining-dashboard/mining-dashboard.component'; | ||||||
| import { HashrateChartComponent } from './components/hashrate-chart/hashrate-chart.component'; | import { HashrateChartComponent } from './components/hashrate-chart/hashrate-chart.component'; | ||||||
|  | import { HashrateChartPoolsComponent } from './components/hashrates-chart-pools/hashrate-chart-pools.component'; | ||||||
| import { MiningStartComponent } from './components/mining-start/mining-start.component'; | import { MiningStartComponent } from './components/mining-start/mining-start.component'; | ||||||
| import { AmountShortenerPipe } from './shared/pipes/amount-shortener.pipe'; | import { AmountShortenerPipe } from './shared/pipes/amount-shortener.pipe'; | ||||||
| 
 | 
 | ||||||
| @ -126,6 +127,7 @@ import { AmountShortenerPipe } from './shared/pipes/amount-shortener.pipe'; | |||||||
|     AssetCirculationComponent, |     AssetCirculationComponent, | ||||||
|     MiningDashboardComponent, |     MiningDashboardComponent, | ||||||
|     HashrateChartComponent, |     HashrateChartComponent, | ||||||
|  |     HashrateChartPoolsComponent, | ||||||
|     MiningStartComponent, |     MiningStartComponent, | ||||||
|     AmountShortenerPipe, |     AmountShortenerPipe, | ||||||
|   ], |   ], | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| <div [class]="widget === false ? 'full-container' : ''"> | <div [class]="widget === false ? 'full-container' : ''"> | ||||||
| 
 | 
 | ||||||
|   <div class="card-header mb-0 mb-lg-4" [style]="widget ? 'display:none' : ''"> |   <div class="card-header mb-0 mb-md-4" [style]="widget ? 'display:none' : ''"> | ||||||
|     <form [formGroup]="radioGroupForm" class="formRadioGroup" *ngIf="(hashrateObservable$ | async) as hashrates"> |     <form [formGroup]="radioGroupForm" class="formRadioGroup" *ngIf="(hashrateObservable$ | async) as hashrates"> | ||||||
|       <div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" formControlName="dateSpan"> |       <div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" formControlName="dateSpan"> | ||||||
|         <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="hashrates.availableTimespanDay >= 90"> |         <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="hashrates.availableTimespanDay >= 90"> | ||||||
| @ -31,7 +31,7 @@ | |||||||
|     <div class="spinner-border text-light"></div> |     <div class="spinner-border text-light"></div> | ||||||
|   </div> |   </div> | ||||||
|    |    | ||||||
|   <div class="mt-3" *ngIf="!widget"> |   <!-- <div class="mt-3" *ngIf="!widget"> | ||||||
|     <table class="table table-borderless table-sm text-center"> |     <table class="table table-borderless table-sm text-center"> | ||||||
|       <thead> |       <thead> | ||||||
|         <tr> |         <tr> | ||||||
| @ -53,6 +53,6 @@ | |||||||
|         </tr> |         </tr> | ||||||
|       </tbody> |       </tbody> | ||||||
|     </table> |     </table> | ||||||
|   </div> |   </div> --> | ||||||
| 
 | 
 | ||||||
| </div> | </div> | ||||||
|  | |||||||
| @ -45,12 +45,15 @@ export class HashrateChartComponent implements OnInit { | |||||||
|     private apiService: ApiService, |     private apiService: ApiService, | ||||||
|     private formBuilder: FormBuilder, |     private formBuilder: FormBuilder, | ||||||
|   ) { |   ) { | ||||||
|     this.seoService.setTitle($localize`:@@mining.hashrate-difficulty:Hashrate and Difficulty`); |  | ||||||
|     this.radioGroupForm = this.formBuilder.group({ dateSpan: '1y' }); |     this.radioGroupForm = this.formBuilder.group({ dateSpan: '1y' }); | ||||||
|     this.radioGroupForm.controls.dateSpan.setValue('1y'); |     this.radioGroupForm.controls.dateSpan.setValue('1y'); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   ngOnInit(): void { |   ngOnInit(): void { | ||||||
|  |     if (!this.widget) { | ||||||
|  |       this.seoService.setTitle($localize`:@@mining.hashrate-difficulty:Hashrate and Difficulty`); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     this.hashrateObservable$ = this.radioGroupForm.get('dateSpan').valueChanges |     this.hashrateObservable$ = this.radioGroupForm.get('dateSpan').valueChanges | ||||||
|       .pipe( |       .pipe( | ||||||
|         startWith('1y'), |         startWith('1y'), | ||||||
| @ -172,7 +175,7 @@ export class HashrateChartComponent implements OnInit { | |||||||
|       }, |       }, | ||||||
|       xAxis: { |       xAxis: { | ||||||
|         type: 'time', |         type: 'time', | ||||||
|         splitNumber: this.isMobile() ? 5 : 10, |         splitNumber: (this.isMobile() || this.widget) ? 5 : 10, | ||||||
|       }, |       }, | ||||||
|       legend: { |       legend: { | ||||||
|         data: [ |         data: [ | ||||||
| @ -243,6 +246,7 @@ export class HashrateChartComponent implements OnInit { | |||||||
|         { |         { | ||||||
|           name: 'Hashrate', |           name: 'Hashrate', | ||||||
|           showSymbol: false, |           showSymbol: false, | ||||||
|  |           symbol: 'none', | ||||||
|           data: data.hashrates, |           data: data.hashrates, | ||||||
|           type: 'line', |           type: 'line', | ||||||
|           lineStyle: { |           lineStyle: { | ||||||
| @ -253,6 +257,7 @@ export class HashrateChartComponent implements OnInit { | |||||||
|           yAxisIndex: 1, |           yAxisIndex: 1, | ||||||
|           name: 'Difficulty', |           name: 'Difficulty', | ||||||
|           showSymbol: false, |           showSymbol: false, | ||||||
|  |           symbol: 'none', | ||||||
|           data: data.difficulty, |           data: data.difficulty, | ||||||
|           type: 'line', |           type: 'line', | ||||||
|           lineStyle: { |           lineStyle: { | ||||||
|  | |||||||
| @ -0,0 +1,34 @@ | |||||||
|  | <div [class]="widget === false ? 'full-container' : ''"> | ||||||
|  | 
 | ||||||
|  |   <div class="card-header mb-0 mb-md-4" [style]="widget ? 'display:none' : ''"> | ||||||
|  |     <form [formGroup]="radioGroupForm" class="formRadioGroup" *ngIf="(hashrateObservable$ | async) as hashrates"> | ||||||
|  |       <div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" formControlName="dateSpan"> | ||||||
|  |         <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="hashrates.availableTimespanDay >= 90"> | ||||||
|  |           <input ngbButton type="radio" [value]="'3m'"> 3M | ||||||
|  |         </label> | ||||||
|  |         <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="hashrates.availableTimespanDay >= 180"> | ||||||
|  |           <input ngbButton type="radio" [value]="'6m'"> 6M | ||||||
|  |         </label> | ||||||
|  |         <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="hashrates.availableTimespanDay >= 365"> | ||||||
|  |           <input ngbButton type="radio" [value]="'1y'"> 1Y | ||||||
|  |         </label> | ||||||
|  |         <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="hashrates.availableTimespanDay >= 730"> | ||||||
|  |           <input ngbButton type="radio" [value]="'2y'"> 2Y | ||||||
|  |         </label> | ||||||
|  |         <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="hashrates.availableTimespanDay >= 1095"> | ||||||
|  |           <input ngbButton type="radio" [value]="'3y'"> 3Y | ||||||
|  |         </label> | ||||||
|  |         <label ngbButtonLabel class="btn-primary btn-sm"> | ||||||
|  |           <input ngbButton type="radio" [value]="'all'"> ALL | ||||||
|  |         </label> | ||||||
|  |       </div> | ||||||
|  |     </form> | ||||||
|  |   </div> | ||||||
|  | 
 | ||||||
|  |   <div *ngIf="hashrateObservable$ | async" [class]="!widget ? 'chart' : 'chart-widget'" | ||||||
|  |     echarts [initOpts]="chartInitOptions" [options]="chartOptions"></div> | ||||||
|  |   <div class="text-center loadingGraphs" *ngIf="isLoading"> | ||||||
|  |     <div class="spinner-border text-light"></div> | ||||||
|  |   </div> | ||||||
|  | 
 | ||||||
|  | </div> | ||||||
| @ -0,0 +1,50 @@ | |||||||
|  | .main-title { | ||||||
|  |   position: relative; | ||||||
|  |   color: #ffffff91; | ||||||
|  |   margin-top: -13px; | ||||||
|  |   font-size: 10px; | ||||||
|  |   text-transform: uppercase; | ||||||
|  |   font-weight: 500; | ||||||
|  |   text-align: center; | ||||||
|  |   padding-bottom: 3px; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .full-container { | ||||||
|  |   width: 100%; | ||||||
|  |   height: calc(100% - 100px); | ||||||
|  |   @media (max-width: 992px) { | ||||||
|  |     height: calc(100% - 140px); | ||||||
|  |   }; | ||||||
|  |   @media (max-width: 576px) { | ||||||
|  |     height: calc(100% - 180px); | ||||||
|  |   }; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .chart { | ||||||
|  |   width: 100%; | ||||||
|  |   height: 100%; | ||||||
|  |   padding-bottom: 20px; | ||||||
|  |   padding-right: 20px; | ||||||
|  | } | ||||||
|  | .chart-widget { | ||||||
|  |   width: 100%; | ||||||
|  |   height: 100%; | ||||||
|  |   max-height: 275px; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .formRadioGroup { | ||||||
|  |   margin-top: 6px; | ||||||
|  |   display: flex; | ||||||
|  |   flex-direction: column; | ||||||
|  |   @media (min-width: 830px) { | ||||||
|  |     flex-direction: row; | ||||||
|  |     float: right; | ||||||
|  |     margin-top: 0px; | ||||||
|  |   } | ||||||
|  |   .btn-sm { | ||||||
|  |     font-size: 9px; | ||||||
|  |     @media (min-width: 830px) { | ||||||
|  |       font-size: 14px; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -0,0 +1,185 @@ | |||||||
|  | import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core'; | ||||||
|  | import { EChartsOption } from 'echarts'; | ||||||
|  | import { Observable } from 'rxjs'; | ||||||
|  | import { map, share, startWith, switchMap, tap } from 'rxjs/operators'; | ||||||
|  | import { ApiService } from 'src/app/services/api.service'; | ||||||
|  | import { SeoService } from 'src/app/services/seo.service'; | ||||||
|  | import { FormBuilder, FormGroup } from '@angular/forms'; | ||||||
|  | import { poolsColor } from 'src/app/app.constants'; | ||||||
|  | 
 | ||||||
|  | @Component({ | ||||||
|  |   selector: 'app-hashrate-chart-pools', | ||||||
|  |   templateUrl: './hashrate-chart-pools.component.html', | ||||||
|  |   styleUrls: ['./hashrate-chart-pools.component.scss'], | ||||||
|  |   styles: [` | ||||||
|  |     .loadingGraphs { | ||||||
|  |       position: absolute; | ||||||
|  |       top: 50%; | ||||||
|  |       left: calc(50% - 15px); | ||||||
|  |       z-index: 100; | ||||||
|  |     } | ||||||
|  |   `],
 | ||||||
|  |   changeDetection: ChangeDetectionStrategy.OnPush, | ||||||
|  | }) | ||||||
|  | export class HashrateChartPoolsComponent implements OnInit { | ||||||
|  |   @Input() widget: boolean = false; | ||||||
|  |   @Input() right: number | string = 40; | ||||||
|  |   @Input() left: number | string = 25; | ||||||
|  | 
 | ||||||
|  |   radioGroupForm: FormGroup; | ||||||
|  | 
 | ||||||
|  |   chartOptions: EChartsOption = {}; | ||||||
|  |   chartInitOptions = { | ||||||
|  |     renderer: 'svg', | ||||||
|  |     width: 'auto', | ||||||
|  |     height: 'auto', | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   hashrateObservable$: Observable<any>; | ||||||
|  |   isLoading = true; | ||||||
|  | 
 | ||||||
|  |   constructor( | ||||||
|  |     @Inject(LOCALE_ID) public locale: string, | ||||||
|  |     private seoService: SeoService, | ||||||
|  |     private apiService: ApiService, | ||||||
|  |     private formBuilder: FormBuilder, | ||||||
|  |   ) { | ||||||
|  |     this.radioGroupForm = this.formBuilder.group({ dateSpan: '1y' }); | ||||||
|  |     this.radioGroupForm.controls.dateSpan.setValue('1y'); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   ngOnInit(): void { | ||||||
|  |     if (!this.widget) { | ||||||
|  |       this.seoService.setTitle($localize`:@@mining.pools-historical-dominance:Pools Historical Dominance`); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     this.hashrateObservable$ = this.radioGroupForm.get('dateSpan').valueChanges | ||||||
|  |       .pipe( | ||||||
|  |         startWith('1y'), | ||||||
|  |         switchMap((timespan) => { | ||||||
|  |           this.isLoading = true; | ||||||
|  |           return this.apiService.getHistoricalPoolsHashrate$(timespan) | ||||||
|  |             .pipe( | ||||||
|  |               tap((data: any) => { | ||||||
|  |                 // Prepare series (group all hashrates data point by pool)
 | ||||||
|  |                 const grouped = {}; | ||||||
|  |                 for (const hashrate of data.hashrates) { | ||||||
|  |                   if (!grouped.hasOwnProperty(hashrate.poolName)) { | ||||||
|  |                     grouped[hashrate.poolName] = []; | ||||||
|  |                   } | ||||||
|  |                   grouped[hashrate.poolName].push(hashrate); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 const series = []; | ||||||
|  |                 const legends = []; | ||||||
|  |                 for (const name in grouped) { | ||||||
|  |                   series.push({ | ||||||
|  |                     stack: 'Total', | ||||||
|  |                     name: name, | ||||||
|  |                     showSymbol: false, | ||||||
|  |                     symbol: 'none', | ||||||
|  |                     data: grouped[name].map((val) => [val.timestamp * 1000, (val.share * 100).toFixed(2)]), | ||||||
|  |                     type: 'line', | ||||||
|  |                     lineStyle: { width: 0 }, | ||||||
|  |                     areaStyle: { opacity: 1 }, | ||||||
|  |                     smooth: true, | ||||||
|  |                     color: poolsColor[name.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()], | ||||||
|  |                     emphasis: { | ||||||
|  |                       disabled: true, | ||||||
|  |                       scale: false, | ||||||
|  |                     }, | ||||||
|  |                   }); | ||||||
|  | 
 | ||||||
|  |                   legends.push({ | ||||||
|  |                     name: name, | ||||||
|  |                     inactiveColor: 'rgb(110, 112, 121)', | ||||||
|  |                     textStyle: { | ||||||
|  |                       color: 'white', | ||||||
|  |                     }, | ||||||
|  |                     icon: 'roundRect', | ||||||
|  |                     itemStyle: { | ||||||
|  |                       color: poolsColor[name.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()], | ||||||
|  |                     }, | ||||||
|  |                   }); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 this.prepareChartOptions({ | ||||||
|  |                   legends: legends, | ||||||
|  |                   series: series | ||||||
|  |                 }); | ||||||
|  |                 this.isLoading = false; | ||||||
|  |               }), | ||||||
|  |               map((data: any) => { | ||||||
|  |                 const availableTimespanDay = ( | ||||||
|  |                   (new Date().getTime() / 1000) - (data.oldestIndexedBlockTimestamp) | ||||||
|  |                 ) / 3600 / 24; | ||||||
|  |                 return { | ||||||
|  |                   availableTimespanDay: availableTimespanDay, | ||||||
|  |                 }; | ||||||
|  |               }), | ||||||
|  |             ); | ||||||
|  |         }), | ||||||
|  |         share() | ||||||
|  |       ); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   prepareChartOptions(data) { | ||||||
|  |     this.chartOptions = { | ||||||
|  |       grid: { | ||||||
|  |         right: this.right, | ||||||
|  |         left: this.left, | ||||||
|  |         bottom: this.widget ? 30 : 20, | ||||||
|  |         top: this.widget ? 10 : 40, | ||||||
|  |       }, | ||||||
|  |       tooltip: { | ||||||
|  |         trigger: 'axis', | ||||||
|  |         axisPointer: { | ||||||
|  |           type: 'line' | ||||||
|  |         }, | ||||||
|  |         backgroundColor: 'rgba(17, 19, 31, 1)', | ||||||
|  |         borderRadius: 4, | ||||||
|  |         shadowColor: 'rgba(0, 0, 0, 0.5)', | ||||||
|  |         textStyle: { | ||||||
|  |           color: '#b1b1b1', | ||||||
|  |           align: 'left', | ||||||
|  |         }, | ||||||
|  |         borderColor: '#000', | ||||||
|  |         formatter: function (data) { | ||||||
|  |           let tooltip = `<b style="color: white; margin-left: 18px">${data[0].axisValueLabel}</b><br>`; | ||||||
|  |           data.sort((a, b) => b.data[1] - a.data[1]); | ||||||
|  |           for (const pool of data) { | ||||||
|  |             if (pool.data[1] > 0) { | ||||||
|  |               tooltip += `${pool.marker} ${pool.seriesName}: ${pool.data[1]}%<br>` | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |           return tooltip; | ||||||
|  |         }.bind(this) | ||||||
|  |       }, | ||||||
|  |       xAxis: { | ||||||
|  |         type: 'time', | ||||||
|  |         splitNumber: (this.isMobile() || this.widget) ? 5 : 10, | ||||||
|  |       }, | ||||||
|  |       legend: (this.isMobile() || this.widget) ? undefined : { | ||||||
|  |         data: data.legends | ||||||
|  |       }, | ||||||
|  |       yAxis: { | ||||||
|  |         position: 'right', | ||||||
|  |         axisLabel: { | ||||||
|  |           color: 'rgb(110, 112, 121)', | ||||||
|  |           formatter: (val) => `${val}%`, | ||||||
|  |         }, | ||||||
|  |         splitLine: { | ||||||
|  |           show: false, | ||||||
|  |         }, | ||||||
|  |         type: 'value', | ||||||
|  |         max: 100, | ||||||
|  |         min: 0, | ||||||
|  |       }, | ||||||
|  |       series: data.series, | ||||||
|  |     }; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   isMobile() { | ||||||
|  |     return (window.innerWidth <= 767.98); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -160,6 +160,7 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges { | |||||||
|           type: 'line', |           type: 'line', | ||||||
|           smooth: false, |           smooth: false, | ||||||
|           showSymbol: false, |           showSymbol: false, | ||||||
|  |           symbol: 'none', | ||||||
|           lineStyle: { |           lineStyle: { | ||||||
|             width: 3, |             width: 3, | ||||||
|           }, |           }, | ||||||
|  | |||||||
| @ -2,16 +2,16 @@ | |||||||
|    |    | ||||||
|   <div class="row row-cols-1 row-cols-md-2"> |   <div class="row row-cols-1 row-cols-md-2"> | ||||||
| 
 | 
 | ||||||
|     <!-- pool distribution --> |     <!-- pools hashrate --> | ||||||
|     <div class="col"> |     <div class="col"> | ||||||
|       <div class="card"> |       <div class="card"> | ||||||
|         <div class="card-body pool-ranking"> |         <div class="card-body"> | ||||||
|           <h5 class="card-title"> |           <h5 class="card-title"> | ||||||
|             <a href="" [routerLink]="['/mining/pools' | relativeUrl]" i18n="mining.pool-share"> |             <a class="link" href="" [routerLink]="['/mining/hashrate/pools' | relativeUrl]" i18n="mining.pools-hashrate"> | ||||||
|               Mining Pools Share (1w) |               Mining Pools Dominance (1y) | ||||||
|             </a> |             </a> | ||||||
|           </h5> |           </h5> | ||||||
|           <app-pool-ranking [widget]=true></app-pool-ranking> |           <app-hashrate-chart-pools [widget]=true></app-hashrate-chart-pools> | ||||||
|         </div> |         </div> | ||||||
|       </div> |       </div> | ||||||
|     </div> |     </div> | ||||||
| @ -30,5 +30,19 @@ | |||||||
|       </div> |       </div> | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|  |     <!-- pool distribution --> | ||||||
|  |     <div class="col"> | ||||||
|  |       <div class="card"> | ||||||
|  |         <div class="card-body pool-ranking"> | ||||||
|  |           <h5 class="card-title"> | ||||||
|  |             <a href="" [routerLink]="['/mining/pools' | relativeUrl]" i18n="mining.pool-share"> | ||||||
|  |               Mining Pools Share (1w) | ||||||
|  |             </a> | ||||||
|  |           </h5> | ||||||
|  |           <app-pool-ranking [widget]=true></app-pool-ranking> | ||||||
|  |         </div> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|  | 
 | ||||||
|   </div> |   </div> | ||||||
| </div> | </div> | ||||||
| @ -12,7 +12,7 @@ | |||||||
| 
 | 
 | ||||||
| .card { | .card { | ||||||
|   background-color: #1d1f31; |   background-color: #1d1f31; | ||||||
|   height: 100%; |   height: 340px; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .card-title { | .card-title { | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | ||||||
|  | import { SeoService } from 'src/app/services/seo.service'; | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: 'app-mining-dashboard', |   selector: 'app-mining-dashboard', | ||||||
| @ -8,7 +9,9 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | |||||||
| }) | }) | ||||||
| export class MiningDashboardComponent implements OnInit { | export class MiningDashboardComponent implements OnInit { | ||||||
| 
 | 
 | ||||||
|   constructor() { } |   constructor(private seoService: SeoService) { | ||||||
|  |     this.seoService.setTitle($localize`:@@mining.mining-dashboard:Mining Dashboard`); | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   ngOnInit(): void { |   ngOnInit(): void { | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| import { Component, Input, OnInit } from '@angular/core'; | import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; | ||||||
| import { FormBuilder, FormGroup } from '@angular/forms'; | import { FormBuilder, FormGroup } from '@angular/forms'; | ||||||
| import { Router } from '@angular/router'; | import { Router } from '@angular/router'; | ||||||
| import { EChartsOption, PieSeriesOption } from 'echarts'; | import { EChartsOption, PieSeriesOption } from 'echarts'; | ||||||
| @ -9,7 +9,7 @@ import { SeoService } from 'src/app/services/seo.service'; | |||||||
| import { StorageService } from '../..//services/storage.service'; | import { StorageService } from '../..//services/storage.service'; | ||||||
| import { MiningService, MiningStats } from '../../services/mining.service'; | import { MiningService, MiningStats } from '../../services/mining.service'; | ||||||
| import { StateService } from '../../services/state.service'; | import { StateService } from '../../services/state.service'; | ||||||
| import { chartColors } from 'src/app/app.constants'; | import { chartColors, poolsColor } from 'src/app/app.constants'; | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: 'app-pool-ranking', |   selector: 'app-pool-ranking', | ||||||
| @ -18,11 +18,12 @@ import { chartColors } from 'src/app/app.constants'; | |||||||
|   styles: [` |   styles: [` | ||||||
|     .loadingGraphs { |     .loadingGraphs { | ||||||
|       position: absolute; |       position: absolute; | ||||||
|       top: 38%; |       top: 50%; | ||||||
|       left: calc(50% - 15px); |       left: calc(50% - 15px); | ||||||
|       z-index: 100; |       z-index: 100; | ||||||
|     } |     } | ||||||
|   `],
 |   `],
 | ||||||
|  |   changeDetection: ChangeDetectionStrategy.OnPush, | ||||||
| }) | }) | ||||||
| export class PoolRankingComponent implements OnInit { | export class PoolRankingComponent implements OnInit { | ||||||
|   @Input() widget: boolean = false; |   @Input() widget: boolean = false; | ||||||
| @ -49,13 +50,13 @@ export class PoolRankingComponent implements OnInit { | |||||||
|     private seoService: SeoService, |     private seoService: SeoService, | ||||||
|     private router: Router, |     private router: Router, | ||||||
|   ) { |   ) { | ||||||
|     this.seoService.setTitle($localize`:@@mining.mining-pools:Mining Pools`); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   ngOnInit(): void { |   ngOnInit(): void { | ||||||
|     if (this.widget) { |     if (this.widget) { | ||||||
|       this.poolsWindowPreference = '1w'; |       this.poolsWindowPreference = '1w'; | ||||||
|     } else { |     } else { | ||||||
|  |       this.seoService.setTitle($localize`:@@mining.mining-pools:Mining Pools`); | ||||||
|       this.poolsWindowPreference = this.storageService.getValue('poolsWindowPreference') ? this.storageService.getValue('poolsWindowPreference') : '1w';     |       this.poolsWindowPreference = this.storageService.getValue('poolsWindowPreference') ? this.storageService.getValue('poolsWindowPreference') : '1w';     | ||||||
|     } |     } | ||||||
|     this.radioGroupForm = this.formBuilder.group({ dateSpan: this.poolsWindowPreference }); |     this.radioGroupForm = this.formBuilder.group({ dateSpan: this.poolsWindowPreference }); | ||||||
| @ -120,6 +121,9 @@ export class PoolRankingComponent implements OnInit { | |||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|       data.push({ |       data.push({ | ||||||
|  |         itemStyle: { | ||||||
|  |           color: poolsColor[pool.name.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()], | ||||||
|  |         }, | ||||||
|         value: pool.share, |         value: pool.share, | ||||||
|         name: pool.name + (this.isMobile() ? `` : ` (${pool.share}%)`), |         name: pool.name + (this.isMobile() ? `` : ` (${pool.share}%)`), | ||||||
|         label: { |         label: { | ||||||
| @ -164,6 +168,7 @@ export class PoolRankingComponent implements OnInit { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     this.chartOptions = { |     this.chartOptions = { | ||||||
|  |       color: chartColors, | ||||||
|       title: { |       title: { | ||||||
|         text: this.widget ? '' : $localize`:@@mining.pool-chart-title:${network}:NETWORK: mining pools share`, |         text: this.widget ? '' : $localize`:@@mining.pool-chart-title:${network}:NETWORK: mining pools share`, | ||||||
|         left: 'center', |         left: 'center', | ||||||
| @ -216,7 +221,6 @@ export class PoolRankingComponent implements OnInit { | |||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       ], |       ], | ||||||
|       color: chartColors |  | ||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -163,4 +163,11 @@ export class ApiService { | |||||||
|         (interval !== undefined ? `/${interval}` : '') |         (interval !== undefined ? `/${interval}` : '') | ||||||
|       ); |       ); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   getHistoricalPoolsHashrate$(interval: string | undefined): Observable<any> { | ||||||
|  |     return this.httpClient.get<any[]>( | ||||||
|  |         this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/hashrate/pools` + | ||||||
|  |         (interval !== undefined ? `/${interval}` : '') | ||||||
|  |       ); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -27,6 +27,12 @@ do for url in / \ | |||||||
| 	'/api/v1/mining/hashrate/2y' \ | 	'/api/v1/mining/hashrate/2y' \ | ||||||
| 	'/api/v1/mining/hashrate/3y' \ | 	'/api/v1/mining/hashrate/3y' \ | ||||||
| 	'/api/v1/mining/hashrate/all' \ | 	'/api/v1/mining/hashrate/all' \ | ||||||
|  | 	'/api/v1/mining/hashrate/pools/3m' \ | ||||||
|  | 	'/api/v1/mining/hashrate/pools/6m' \ | ||||||
|  | 	'/api/v1/mining/hashrate/pools/1y' \ | ||||||
|  | 	'/api/v1/mining/hashrate/pools/2y' \ | ||||||
|  | 	'/api/v1/mining/hashrate/pools/3y' \ | ||||||
|  | 	'/api/v1/mining/hashrate/pools/all' \ | ||||||
| 
 | 
 | ||||||
| 	do | 	do | ||||||
| 		curl -s "https://${hostname}${url}" >/dev/null | 		curl -s "https://${hostname}${url}" >/dev/null | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user