diff --git a/backend/src/api/statistics.ts b/backend/src/api/statistics.ts index 521e1536d..31b9f7127 100644 --- a/backend/src/api/statistics.ts +++ b/backend/src/api/statistics.ts @@ -9,7 +9,7 @@ class Statistics { protected newStatisticsEntryCallback: ((stats: OptimizedStatistic) => void) | undefined; protected queryTimeout = 120000; protected cache: { [date: string]: OptimizedStatistic[] } = { - '24h': [], '1w': [], '1m': [], '3m': [], '6m': [], '1y': [], + '24h': [], '1w': [], '1m': [], '3m': [], '6m': [], '1y': [], '2y': [], '3y': [] }; public setNewStatisticsEntryCallback(fn: (stats: OptimizedStatistic) => void) { @@ -48,6 +48,8 @@ class Statistics { this.cache['3m'] = await this.$list3M(); this.cache['6m'] = await this.$list6M(); this.cache['1y'] = await this.$list1Y(); + this.cache['2y'] = await this.$list2Y(); + this.cache['3y'] = await this.$list3Y(); logger.debug('Statistics cache created'); } @@ -403,10 +405,37 @@ class Statistics { connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { - logger.err('$list6M() error' + (e instanceof Error ? e.message : e)); + logger.err('$list1Y() error' + (e instanceof Error ? e.message : e)); return []; } } + + public async $list2Y(): Promise { + try { + const connection = await DB.pool.getConnection(); + const query = this.getQueryForDays(120960); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); + connection.release(); + return this.mapStatisticToOptimizedStatistic(rows); + } catch (e) { + logger.err('$list2Y() error' + (e instanceof Error ? e.message : e)); + return []; + } + } + + public async $list3Y(): Promise { + try { + const connection = await DB.pool.getConnection(); + const query = this.getQueryForDays(181440); + const [rows] = await connection.query({ sql: query, timeout: this.queryTimeout }); + connection.release(); + return this.mapStatisticToOptimizedStatistic(rows); + } catch (e) { + logger.err('$list3Y() error' + (e instanceof Error ? e.message : e)); + return []; + } + } + private mapStatisticToOptimizedStatistic(statistic: Statistic[]): OptimizedStatistic[] { return statistic.map((s) => { return { diff --git a/backend/src/index.ts b/backend/src/index.ts index 6b1f14efb..971b00908 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -217,6 +217,8 @@ class Server { .get(config.MEMPOOL.API_URL_PREFIX + 'statistics/3m', routes.get3MStatistics.bind(routes)) .get(config.MEMPOOL.API_URL_PREFIX + 'statistics/6m', routes.get6MStatistics.bind(routes)) .get(config.MEMPOOL.API_URL_PREFIX + 'statistics/1y', routes.get1YStatistics.bind(routes)) + .get(config.MEMPOOL.API_URL_PREFIX + 'statistics/2y', routes.get2YStatistics.bind(routes)) + .get(config.MEMPOOL.API_URL_PREFIX + 'statistics/3y', routes.get3YStatistics.bind(routes)) ; } diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 420f37fee..fd53f4765 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -52,6 +52,14 @@ class Routes { res.json(statistics.getCache()['1y']); } + public get2YStatistics(req: Request, res: Response) { + res.json(statistics.getCache()['2y']); + } + + public get3YStatistics(req: Request, res: Response) { + res.json(statistics.getCache()['3y']); + } + public getInitData(req: Request, res: Response) { try { const result = websocketHandler.getInitData(); diff --git a/frontend/src/app/components/statistics/statistics.component.html b/frontend/src/app/components/statistics/statistics.component.html index e6925a512..e335753ac 100644 --- a/frontend/src/app/components/statistics/statistics.component.html +++ b/frontend/src/app/components/statistics/statistics.component.html @@ -34,6 +34,12 @@ + +
diff --git a/frontend/src/app/components/statistics/statistics.component.ts b/frontend/src/app/components/statistics/statistics.component.ts index a9041d1fe..fb386304d 100644 --- a/frontend/src/app/components/statistics/statistics.component.ts +++ b/frontend/src/app/components/statistics/statistics.component.ts @@ -72,7 +72,7 @@ export class StatisticsComponent implements OnInit { this.route .fragment .subscribe((fragment) => { - if (['2h', '24h', '1w', '1m', '3m', '6m', '1y'].indexOf(fragment) > -1) { + if (['2h', '24h', '1w', '1m', '3m', '6m', '1y', '2y', '3y'].indexOf(fragment) > -1) { this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: false }); } }); @@ -104,7 +104,13 @@ export class StatisticsComponent implements OnInit { if (this.radioGroupForm.controls.dateSpan.value === '6m') { return this.apiService.list6MStatistics$(); } - return this.apiService.list1YStatistics$(); + if (this.radioGroupForm.controls.dateSpan.value === '1y') { + return this.apiService.list1YStatistics$(); + } + if (this.radioGroupForm.controls.dateSpan.value === '2y') { + return this.apiService.list2YStatistics$(); + } + return this.apiService.list3YStatistics$(); }) ) .subscribe((mempoolStats: any) => { diff --git a/frontend/src/app/services/api.service.ts b/frontend/src/app/services/api.service.ts index 306fa9535..9093aad50 100644 --- a/frontend/src/app/services/api.service.ts +++ b/frontend/src/app/services/api.service.ts @@ -57,6 +57,14 @@ export class ApiService { return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/1y'); } + list2YStatistics$(): Observable { + return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/2y'); + } + + list3YStatistics$(): Observable { + return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/3y'); + } + getTransactionTimes$(txIds: string[]): Observable { let params = new HttpParams(); txIds.forEach((txId: string) => {