From 720c2b88078adb0acade9c1f24e315ecbbb6ca8a Mon Sep 17 00:00:00 2001 From: nymkappa <1612910616@pm.me> Date: Thu, 16 Mar 2023 17:03:32 +0900 Subject: [PATCH 1/2] Block prediction -> Block health - Fix wrong chart download name --- backend/src/api/mining/mining-routes.ts | 10 +++---- backend/src/api/mining/mining.ts | 7 ++--- .../repositories/BlocksAuditsRepository.ts | 8 +++--- .../block-health-graph.component.html} | 22 +++++++-------- .../block-health-graph.component.scss} | 0 .../block-health-graph.component.ts} | 28 +++++++++---------- .../components/graphs/graphs.component.html | 2 +- frontend/src/app/graphs/graphs.module.ts | 4 +-- .../src/app/graphs/graphs.routing.module.ts | 6 ++-- .../node-fee-chart.component.ts | 16 ----------- .../node-statistics-chart.component.ts | 17 ----------- .../nodes-networks-chart.component.ts | 2 +- frontend/src/app/services/api.service.ts | 2 +- 13 files changed, 45 insertions(+), 79 deletions(-) rename frontend/src/app/components/{block-prediction-graph/block-prediction-graph.component.html => block-health-graph/block-health-graph.component.html} (75%) rename frontend/src/app/components/{block-prediction-graph/block-prediction-graph.component.scss => block-health-graph/block-health-graph.component.scss} (100%) rename frontend/src/app/components/{block-prediction-graph/block-prediction-graph.component.ts => block-health-graph/block-health-graph.component.ts} (92%) diff --git a/backend/src/api/mining/mining-routes.ts b/backend/src/api/mining/mining-routes.ts index 0198f9ab4..1c9a0de30 100644 --- a/backend/src/api/mining/mining-routes.ts +++ b/backend/src/api/mining/mining-routes.ts @@ -26,7 +26,7 @@ class MiningRoutes { .get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/fee-rates/:interval', this.$getHistoricalBlockFeeRates) .get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/sizes-weights/:interval', this.$getHistoricalBlockSizeAndWeight) .get(config.MEMPOOL.API_URL_PREFIX + 'mining/difficulty-adjustments/:interval', this.$getDifficultyAdjustments) - .get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/predictions/:interval', this.$getHistoricalBlockPrediction) + .get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/predictions/:interval', this.$getHistoricalBlocksHealth) .get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/audit/scores', this.$getBlockAuditScores) .get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/audit/scores/:height', this.$getBlockAuditScores) .get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/audit/score/:hash', this.$getBlockAuditScore) @@ -244,15 +244,15 @@ class MiningRoutes { } } - private async $getHistoricalBlockPrediction(req: Request, res: Response) { + private async $getHistoricalBlocksHealth(req: Request, res: Response) { try { - const blockPredictions = await mining.$getBlockPredictionsHistory(req.params.interval); - const blockCount = await BlocksAuditsRepository.$getPredictionsCount(); + const blocksHealth = await mining.$getBlocksHealthHistory(req.params.interval); + const blockCount = await BlocksAuditsRepository.$getBlocksHealthCount(); res.header('Pragma', 'public'); res.header('Cache-control', 'public'); res.header('X-total-count', blockCount.toString()); res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString()); - res.json(blockPredictions.map(prediction => [prediction.time, prediction.height, prediction.match_rate])); + res.json(blocksHealth.map(health => [health.time, health.height, health.match_rate])); } catch (e) { res.status(500).send(e instanceof Error ? e.message : e); } diff --git a/backend/src/api/mining/mining.ts b/backend/src/api/mining/mining.ts index 27ac426bd..20da92de3 100644 --- a/backend/src/api/mining/mining.ts +++ b/backend/src/api/mining/mining.ts @@ -13,7 +13,6 @@ import BlocksAuditsRepository from '../../repositories/BlocksAuditsRepository'; import PricesRepository from '../../repositories/PricesRepository'; import { bitcoinCoreApi } from '../bitcoin/bitcoin-api-factory'; import { IEsploraApi } from '../bitcoin/esplora-api.interface'; -import database from '../../database'; class Mining { private blocksPriceIndexingRunning = false; @@ -21,10 +20,10 @@ class Mining { public lastWeeklyHashrateIndexingDate: number | null = null; /** - * Get historical block predictions match rate + * Get historical blocks health */ - public async $getBlockPredictionsHistory(interval: string | null = null): Promise { - return await BlocksAuditsRepository.$getBlockPredictionsHistory( + public async $getBlocksHealthHistory(interval: string | null = null): Promise { + return await BlocksAuditsRepository.$getBlocksHealthHistory( this.getTimeRange(interval), Common.getSqlInterval(interval) ); diff --git a/backend/src/repositories/BlocksAuditsRepository.ts b/backend/src/repositories/BlocksAuditsRepository.ts index c6156334b..70565a1c8 100644 --- a/backend/src/repositories/BlocksAuditsRepository.ts +++ b/backend/src/repositories/BlocksAuditsRepository.ts @@ -19,7 +19,7 @@ class BlocksAuditRepositories { } } - public async $getBlockPredictionsHistory(div: number, interval: string | null): Promise { + public async $getBlocksHealthHistory(div: number, interval: string | null): Promise { try { let query = `SELECT UNIX_TIMESTAMP(time) as time, height, match_rate FROM blocks_audits`; @@ -32,17 +32,17 @@ class BlocksAuditRepositories { const [rows] = await DB.query(query); return rows; } catch (e: any) { - logger.err(`Cannot fetch block prediction history. Reason: ` + (e instanceof Error ? e.message : e)); + logger.err(`Cannot fetch blocks health history. Reason: ` + (e instanceof Error ? e.message : e)); throw e; } } - public async $getPredictionsCount(): Promise { + public async $getBlocksHealthCount(): Promise { try { const [rows] = await DB.query(`SELECT count(hash) as count FROM blocks_audits`); return rows[0].count; } catch (e: any) { - logger.err(`Cannot fetch block prediction history. Reason: ` + (e instanceof Error ? e.message : e)); + logger.err(`Cannot fetch blocks health count. Reason: ` + (e instanceof Error ? e.message : e)); throw e; } } diff --git a/frontend/src/app/components/block-prediction-graph/block-prediction-graph.component.html b/frontend/src/app/components/block-health-graph/block-health-graph.component.html similarity index 75% rename from frontend/src/app/components/block-prediction-graph/block-prediction-graph.component.html rename to frontend/src/app/components/block-health-graph/block-health-graph.component.html index 7dcd81c69..4cd10f2dd 100644 --- a/frontend/src/app/components/block-prediction-graph/block-prediction-graph.component.html +++ b/frontend/src/app/components/block-health-graph/block-health-graph.component.html @@ -3,7 +3,7 @@
- Block Prediction Accuracy + Block Health @@ -12,34 +12,34 @@
diff --git a/frontend/src/app/components/block-prediction-graph/block-prediction-graph.component.scss b/frontend/src/app/components/block-health-graph/block-health-graph.component.scss similarity index 100% rename from frontend/src/app/components/block-prediction-graph/block-prediction-graph.component.scss rename to frontend/src/app/components/block-health-graph/block-health-graph.component.scss diff --git a/frontend/src/app/components/block-prediction-graph/block-prediction-graph.component.ts b/frontend/src/app/components/block-health-graph/block-health-graph.component.ts similarity index 92% rename from frontend/src/app/components/block-prediction-graph/block-prediction-graph.component.ts rename to frontend/src/app/components/block-health-graph/block-health-graph.component.ts index e04565751..46aebdd6e 100644 --- a/frontend/src/app/components/block-prediction-graph/block-prediction-graph.component.ts +++ b/frontend/src/app/components/block-health-graph/block-health-graph.component.ts @@ -13,9 +13,9 @@ import { RelativeUrlPipe } from '../../shared/pipes/relative-url/relative-url.pi import { StateService } from '../../services/state.service'; @Component({ - selector: 'app-block-prediction-graph', - templateUrl: './block-prediction-graph.component.html', - styleUrls: ['./block-prediction-graph.component.scss'], + selector: 'app-block-health-graph', + templateUrl: './block-health-graph.component.html', + styleUrls: ['./block-health-graph.component.scss'], styles: [` .loadingGraphs { position: absolute; @@ -26,7 +26,7 @@ import { StateService } from '../../services/state.service'; `], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class BlockPredictionGraphComponent implements OnInit { +export class BlockHealthGraphComponent implements OnInit { @Input() right: number | string = 45; @Input() left: number | string = 75; @@ -60,7 +60,7 @@ export class BlockPredictionGraphComponent implements OnInit { } ngOnInit(): void { - this.seoService.setTitle($localize`:@@d7d5fcf50179ad70c938491c517efb82de2c8146:Block Prediction Accuracy`); + this.seoService.setTitle($localize`:@@d7d5fcf50179ad70c938491c517efb82de2c8146:Block Health`); this.miningWindowPreference = '24h';//this.miningService.getDefaultTimespan('24h'); this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); @@ -80,7 +80,7 @@ export class BlockPredictionGraphComponent implements OnInit { this.storageService.setValue('miningWindowPreference', timespan); this.timespan = timespan; this.isLoading = true; - return this.apiService.getHistoricalBlockPrediction$(timespan) + return this.apiService.getHistoricalBlocksHealth$(timespan) .pipe( tap((response) => { this.prepareChartOptions(response.body); @@ -163,7 +163,7 @@ export class BlockPredictionGraphComponent implements OnInit { hideOverlap: true, padding: [0, 5], }, - data: data.map(prediction => prediction[0]) + data: data.map(health => health[0]) }, yAxis: data.length === 0 ? undefined : [ { @@ -186,12 +186,12 @@ export class BlockPredictionGraphComponent implements OnInit { series: data.length === 0 ? undefined : [ { zlevel: 0, - name: $localize`Match rate`, - data: data.map(prediction => ({ - value: prediction[2], - block: prediction[1], + name: $localize`Health`, + data: data.map(health => ({ + value: health[2], + block: health[1], itemStyle: { - color: this.getPredictionColor(prediction[2]) + color: this.getHealthColor(health[2]) } })), type: 'bar', @@ -257,7 +257,7 @@ export class BlockPredictionGraphComponent implements OnInit { return 'rgb(' + gradient.red + ',' + gradient.green + ',' + gradient.blue + ')'; } - getPredictionColor(matchRate) { + getHealthColor(matchRate) { return this.colorGradient( Math.pow((100 - matchRate) / 100, 0.5), {red: 67, green: 171, blue: 71}, @@ -294,7 +294,7 @@ export class BlockPredictionGraphComponent implements OnInit { download(this.chartInstance.getDataURL({ pixelRatio: 2, excludeComponents: ['dataZoom'], - }), `block-fees-${this.timespan}-${Math.round(now.getTime() / 1000)}.svg`); + }), `block-health-${this.timespan}-${Math.round(now.getTime() / 1000)}.svg`); // @ts-ignore this.chartOptions.grid.bottom = prevBottom; this.chartOptions.backgroundColor = 'none'; diff --git a/frontend/src/app/components/graphs/graphs.component.html b/frontend/src/app/components/graphs/graphs.component.html index 105c6cbf2..c3053427e 100644 --- a/frontend/src/app/components/graphs/graphs.component.html +++ b/frontend/src/app/components/graphs/graphs.component.html @@ -22,7 +22,7 @@ Block Sizes and Weights Block Prediction Accuracy + [routerLink]="['/graphs/mining/block-health' | relativeUrl]" i18n="mining.blocks-health">Blocks Health
diff --git a/frontend/src/app/graphs/graphs.module.ts b/frontend/src/app/graphs/graphs.module.ts index a4e4f5bfc..87e8a620b 100644 --- a/frontend/src/app/graphs/graphs.module.ts +++ b/frontend/src/app/graphs/graphs.module.ts @@ -21,7 +21,7 @@ import { DashboardComponent } from '../dashboard/dashboard.component'; import { MiningDashboardComponent } from '../components/mining-dashboard/mining-dashboard.component'; import { HashrateChartComponent } from '../components/hashrate-chart/hashrate-chart.component'; import { HashrateChartPoolsComponent } from '../components/hashrates-chart-pools/hashrate-chart-pools.component'; -import { BlockPredictionGraphComponent } from '../components/block-prediction-graph/block-prediction-graph.component'; +import { BlockHealthGraphComponent } from '../components/block-health-graph/block-health-graph.component'; import { CommonModule } from '@angular/common'; @NgModule({ @@ -46,7 +46,7 @@ import { CommonModule } from '@angular/common'; LbtcPegsGraphComponent, HashrateChartComponent, HashrateChartPoolsComponent, - BlockPredictionGraphComponent, + BlockHealthGraphComponent, ], imports: [ CommonModule, diff --git a/frontend/src/app/graphs/graphs.routing.module.ts b/frontend/src/app/graphs/graphs.routing.module.ts index a31f3a30a..03800dcfc 100644 --- a/frontend/src/app/graphs/graphs.routing.module.ts +++ b/frontend/src/app/graphs/graphs.routing.module.ts @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { BlockPredictionGraphComponent } from '../components/block-prediction-graph/block-prediction-graph.component'; +import { BlockHealthGraphComponent } from '../components/block-health-graph/block-health-graph.component'; import { BlockFeeRatesGraphComponent } from '../components/block-fee-rates-graph/block-fee-rates-graph.component'; import { BlockFeesGraphComponent } from '../components/block-fees-graph/block-fees-graph.component'; import { BlockRewardsGraphComponent } from '../components/block-rewards-graph/block-rewards-graph.component'; @@ -143,9 +143,9 @@ const routes: Routes = [ redirectTo: 'mempool', }, { - path: 'mining/block-prediction', + path: 'mining/block-health', data: { networks: ['bitcoin'] }, - component: BlockPredictionGraphComponent, + component: BlockHealthGraphComponent, }, ] }, diff --git a/frontend/src/app/lightning/node-fee-chart/node-fee-chart.component.ts b/frontend/src/app/lightning/node-fee-chart/node-fee-chart.component.ts index 97268226d..f20142e47 100644 --- a/frontend/src/app/lightning/node-fee-chart/node-fee-chart.component.ts +++ b/frontend/src/app/lightning/node-fee-chart/node-fee-chart.component.ts @@ -253,20 +253,4 @@ export class NodeFeeChartComponent implements OnInit { isMobile() { return (window.innerWidth <= 767.98); } - - onSaveChart() { - // @ts-ignore - const prevBottom = this.chartOptions.grid.bottom; - // @ts-ignore - this.chartOptions.grid.bottom = 40; - this.chartOptions.backgroundColor = '#11131f'; - this.chartInstance.setOption(this.chartOptions); - download(this.chartInstance.getDataURL({ - pixelRatio: 2, - }), `node-fee-chart.svg`); - // @ts-ignore - this.chartOptions.grid.bottom = prevBottom; - this.chartOptions.backgroundColor = 'none'; - this.chartInstance.setOption(this.chartOptions); - } } diff --git a/frontend/src/app/lightning/node-statistics-chart/node-statistics-chart.component.ts b/frontend/src/app/lightning/node-statistics-chart/node-statistics-chart.component.ts index 21e3fc2c5..9b10152b5 100644 --- a/frontend/src/app/lightning/node-statistics-chart/node-statistics-chart.component.ts +++ b/frontend/src/app/lightning/node-statistics-chart/node-statistics-chart.component.ts @@ -252,21 +252,4 @@ export class NodeStatisticsChartComponent implements OnInit { isMobile() { return (window.innerWidth <= 767.98); } - - onSaveChart() { - // @ts-ignore - const prevBottom = this.chartOptions.grid.bottom; - const now = new Date(); - // @ts-ignore - this.chartOptions.grid.bottom = 40; - this.chartOptions.backgroundColor = '#11131f'; - this.chartInstance.setOption(this.chartOptions); - download(this.chartInstance.getDataURL({ - pixelRatio: 2, - }), `block-sizes-weights-${this.timespan}-${Math.round(now.getTime() / 1000)}.svg`); - // @ts-ignore - this.chartOptions.grid.bottom = prevBottom; - this.chartOptions.backgroundColor = 'none'; - this.chartInstance.setOption(this.chartOptions); - } } diff --git a/frontend/src/app/lightning/nodes-networks-chart/nodes-networks-chart.component.ts b/frontend/src/app/lightning/nodes-networks-chart/nodes-networks-chart.component.ts index 603f6d714..db04e9e00 100644 --- a/frontend/src/app/lightning/nodes-networks-chart/nodes-networks-chart.component.ts +++ b/frontend/src/app/lightning/nodes-networks-chart/nodes-networks-chart.component.ts @@ -442,7 +442,7 @@ export class NodesNetworksChartComponent implements OnInit { download(this.chartInstance.getDataURL({ pixelRatio: 2, excludeComponents: ['dataZoom'], - }), `block-sizes-weights-${this.timespan}-${Math.round(now.getTime() / 1000)}.svg`); + }), `lightning-nodes-per-network-${Math.round(now.getTime() / 1000)}.svg`); // @ts-ignore this.chartOptions.grid.bottom = prevBottom; this.chartOptions.backgroundColor = 'none'; diff --git a/frontend/src/app/services/api.service.ts b/frontend/src/app/services/api.service.ts index 64bf080f9..8521ddc83 100644 --- a/frontend/src/app/services/api.service.ts +++ b/frontend/src/app/services/api.service.ts @@ -238,7 +238,7 @@ export class ApiService { ); } - getHistoricalBlockPrediction$(interval: string | undefined) : Observable { + getHistoricalBlocksHealth$(interval: string | undefined) : Observable { return this.httpClient.get( this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/blocks/predictions` + (interval !== undefined ? `/${interval}` : ''), { observe: 'response' } From 4dec152df018ae795c3b176a19346c06db2c4c7c Mon Sep 17 00:00:00 2001 From: nymkappa <1612910616@pm.me> Date: Sat, 1 Apr 2023 19:26:34 +0900 Subject: [PATCH 2/2] Blocks Health -> Block Health --- frontend/src/app/components/graphs/graphs.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/components/graphs/graphs.component.html b/frontend/src/app/components/graphs/graphs.component.html index c3053427e..8468deb82 100644 --- a/frontend/src/app/components/graphs/graphs.component.html +++ b/frontend/src/app/components/graphs/graphs.component.html @@ -22,7 +22,7 @@ Block Sizes and Weights Blocks Health + [routerLink]="['/graphs/mining/block-health' | relativeUrl]" i18n="mining.block-health">Block Health