diff --git a/backend/src/api/statistics.ts b/backend/src/api/statistics.ts index 8dbeef423..75274d90c 100644 --- a/backend/src/api/statistics.ts +++ b/backend/src/api/statistics.ts @@ -238,49 +238,48 @@ class Statistics { } } - private getQueryForDays(days: number, groupBy: number) { - + private getQueryForDays(div: number) { return `SELECT id, added, unconfirmed_transactions, - AVG(tx_per_second) AS tx_per_second, - AVG(vbytes_per_second) AS vbytes_per_second, - AVG(vsize_1) AS vsize_1, - AVG(vsize_2) AS vsize_2, - AVG(vsize_3) AS vsize_3, - AVG(vsize_4) AS vsize_4, - AVG(vsize_5) AS vsize_5, - AVG(vsize_6) AS vsize_6, - AVG(vsize_8) AS vsize_8, - AVG(vsize_10) AS vsize_10, - AVG(vsize_12) AS vsize_12, - AVG(vsize_15) AS vsize_15, - AVG(vsize_20) AS vsize_20, - AVG(vsize_30) AS vsize_30, - AVG(vsize_40) AS vsize_40, - AVG(vsize_50) AS vsize_50, - AVG(vsize_60) AS vsize_60, - AVG(vsize_70) AS vsize_70, - AVG(vsize_80) AS vsize_80, - AVG(vsize_90) AS vsize_90, - AVG(vsize_100) AS vsize_100, - AVG(vsize_125) AS vsize_125, - AVG(vsize_150) AS vsize_150, - AVG(vsize_175) AS vsize_175, - AVG(vsize_200) AS vsize_200, - AVG(vsize_250) AS vsize_250, - AVG(vsize_300) AS vsize_300, - AVG(vsize_350) AS vsize_350, - AVG(vsize_400) AS vsize_400, - AVG(vsize_500) AS vsize_500, - AVG(vsize_600) AS vsize_600, - AVG(vsize_700) AS vsize_700, - AVG(vsize_800) AS vsize_800, - AVG(vsize_900) AS vsize_900, - AVG(vsize_1000) AS vsize_1000, - AVG(vsize_1200) AS vsize_1200, - AVG(vsize_1400) AS vsize_1400, - AVG(vsize_1600) AS vsize_1600, - AVG(vsize_1800) AS vsize_1800, - AVG(vsize_2000) AS vsize_2000 FROM statistics GROUP BY UNIX_TIMESTAMP(added) DIV ${groupBy} ORDER BY id DESC LIMIT ${days}`; + tx_per_second, + vbytes_per_second, + vsize_1, + vsize_2, + vsize_3, + vsize_4, + vsize_5, + vsize_6, + vsize_8, + vsize_10, + vsize_12, + vsize_15, + vsize_20, + vsize_30, + vsize_40, + vsize_50, + vsize_60, + vsize_70, + vsize_80, + vsize_90, + vsize_100, + vsize_125, + vsize_150, + vsize_175, + vsize_200, + vsize_250, + vsize_300, + vsize_350, + vsize_400, + vsize_500, + vsize_600, + vsize_700, + vsize_800, + vsize_900, + vsize_1000, + vsize_1200, + vsize_1400, + vsize_1600, + vsize_1800, + vsize_2000 FROM statistics GROUP BY UNIX_TIMESTAMP(added) DIV ${div} ORDER BY id DESC LIMIT 480`; } public async $get(id: number): Promise { @@ -313,7 +312,7 @@ class Statistics { public async $list24H(): Promise { try { const connection = await DB.pool.getConnection(); - const query = this.getQueryForDays(120, 720); + const query = this.getQueryForDays(180); const [rows] = await connection.query(query); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); @@ -325,7 +324,7 @@ class Statistics { public async $list1W(): Promise { try { const connection = await DB.pool.getConnection(); - const query = this.getQueryForDays(120, 5040); + const query = this.getQueryForDays(1260); const [rows] = await connection.query(query); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); @@ -338,7 +337,7 @@ class Statistics { public async $list1M(): Promise { try { const connection = await DB.pool.getConnection(); - const query = this.getQueryForDays(120, 20160); + const query = this.getQueryForDays(5040); const [rows] = await connection.query(query); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); @@ -351,7 +350,7 @@ class Statistics { public async $list3M(): Promise { try { const connection = await DB.pool.getConnection(); - const query = this.getQueryForDays(120, 60480); + const query = this.getQueryForDays(15120); const [rows] = await connection.query(query); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); @@ -364,7 +363,7 @@ class Statistics { public async $list6M(): Promise { try { const connection = await DB.pool.getConnection(); - const query = this.getQueryForDays(120, 120960); + const query = this.getQueryForDays(30240); const [rows] = await connection.query(query); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); @@ -377,7 +376,7 @@ class Statistics { public async $list1Y(): Promise { try { const connection = await DB.pool.getConnection(); - const query = this.getQueryForDays(120, 241920); + const query = this.getQueryForDays(60480); const [rows] = await connection.query(query); connection.release(); return this.mapStatisticToOptimizedStatistic(rows); diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 02ac4ce8e..ee1653e06 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -7,13 +7,15 @@ import mempoolBlocks from './api/mempool-blocks'; import mempool from './api/mempool'; import bisq from './api/bisq/bisq'; import bisqMarket from './api/bisq/markets-api'; -import { RequiredSpec } from './interfaces'; +import { OptimizedStatistic, RequiredSpec } from './interfaces'; import { MarketsApiError } from './api/bisq/interfaces'; import donations from './api/donations'; import logger from './logger'; class Routes { - private cache = {}; + private cache: { [date: string]: OptimizedStatistic[] } = { + '24h': [], '1w': [], '1m': [], '3m': [], '6m': [], '1y': [], + }; constructor() { if (config.DATABASE.ENABLED && config.STATISTICS.ENABLED) { diff --git a/frontend/src/app/components/mempool-graph/mempool-graph.component.ts b/frontend/src/app/components/mempool-graph/mempool-graph.component.ts index d09c130ba..e976eab13 100644 --- a/frontend/src/app/components/mempool-graph/mempool-graph.component.ts +++ b/frontend/src/app/components/mempool-graph/mempool-graph.component.ts @@ -30,9 +30,13 @@ export class MempoolGraphComponent implements OnInit, OnChanges { ngOnInit(): void { const showLegend = !this.isMobile && this.showLegend; - let labelHops = !this.showLegend ? 12 : 6; + let labelHops = !this.showLegend ? 48 : 24; if (this.small) { - labelHops = labelHops * 2; + labelHops = labelHops / 2; + } + + if (this.isMobile) { + labelHops = 96; } const labelInterpolationFnc = (value: any, index: any) => { @@ -65,7 +69,7 @@ export class MempoolGraphComponent implements OnInit, OnChanges { }, axisY: { labelInterpolationFnc: (value: number): any => this.vbytesPipe.transform(value, 2), - offset: showLegend ? 160 : 80, + offset: showLegend ? 160 : 60, }, plugins: [ Chartist.plugins.ctTargetLine({ diff --git a/frontend/src/app/components/statistics/statistics.component.ts b/frontend/src/app/components/statistics/statistics.component.ts index 01f1936c4..cb9e0840f 100644 --- a/frontend/src/app/components/statistics/statistics.component.ts +++ b/frontend/src/app/components/statistics/statistics.component.ts @@ -53,7 +53,11 @@ export class StatisticsComponent implements OnInit { this.seoService.setTitle('Graphs'); this.stateService.networkChanged$.subscribe((network) => this.network = network); const isMobile = window.innerWidth <= 767.98; - const labelHops = isMobile ? 12 : 6; + let labelHops = isMobile ? 48 : 24; + + if (isMobile) { + labelHops = 96; + } const labelInterpolationFnc = (value: any, index: any) => { switch (this.radioGroupForm.controls.dateSpan.value) {