mirror of
https://github.com/mempool/mempool.git
synced 2024-11-20 02:11:49 +01:00
Merge pull request #3227 from mempool/simon/add-4y
Adding 4 year button to mempool graph
This commit is contained in:
commit
626b395ab7
@ -175,6 +175,7 @@ export class Common {
|
||||
case '1y': return '1 YEAR';
|
||||
case '2y': return '2 YEAR';
|
||||
case '3y': return '3 YEAR';
|
||||
case '4y': return '4 YEAR';
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
@ -568,6 +568,7 @@ class Mining {
|
||||
|
||||
private getTimeRange(interval: string | null, scale = 1): number {
|
||||
switch (interval) {
|
||||
case '4y': return 43200 * scale; // 12h
|
||||
case '3y': return 43200 * scale; // 12h
|
||||
case '2y': return 28800 * scale; // 8h
|
||||
case '1y': return 28800 * scale; // 8h
|
||||
|
@ -375,6 +375,17 @@ class StatisticsApi {
|
||||
}
|
||||
}
|
||||
|
||||
public async $list4Y(): Promise<OptimizedStatistic[]> {
|
||||
try {
|
||||
const query = this.getQueryForDays(43200, '4 YEAR'); // 12h interval
|
||||
const [rows] = await DB.query({ sql: query, timeout: this.queryTimeout });
|
||||
return this.mapStatisticToOptimizedStatistic(rows as Statistic[]);
|
||||
} catch (e) {
|
||||
logger.err('$list4Y() error' + (e instanceof Error ? e.message : e));
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private mapStatisticToOptimizedStatistic(statistic: Statistic[]): OptimizedStatistic[] {
|
||||
return statistic.map((s) => {
|
||||
return {
|
||||
|
@ -14,10 +14,11 @@ class StatisticsRoutes {
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'statistics/1y', this.$getStatisticsByTime.bind(this, '1y'))
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'statistics/2y', this.$getStatisticsByTime.bind(this, '2y'))
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'statistics/3y', this.$getStatisticsByTime.bind(this, '3y'))
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'statistics/4y', this.$getStatisticsByTime.bind(this, '4y'))
|
||||
;
|
||||
}
|
||||
|
||||
private async $getStatisticsByTime(time: '2h' | '24h' | '1w' | '1m' | '3m' | '6m' | '1y' | '2y' | '3y', req: Request, res: Response) {
|
||||
private async $getStatisticsByTime(time: '2h' | '24h' | '1w' | '1m' | '3m' | '6m' | '1y' | '2y' | '3y' | '4y', req: Request, res: Response) {
|
||||
res.header('Pragma', 'public');
|
||||
res.header('Cache-control', 'public');
|
||||
res.setHeader('Expires', new Date(Date.now() + 1000 * 300).toUTCString());
|
||||
@ -54,6 +55,9 @@ class StatisticsRoutes {
|
||||
case '3y':
|
||||
result = await statisticsApi.$list3Y();
|
||||
break;
|
||||
case '4y':
|
||||
result = await statisticsApi.$list4Y();
|
||||
break;
|
||||
default:
|
||||
result = await statisticsApi.$list2H();
|
||||
}
|
||||
|
@ -49,6 +49,9 @@
|
||||
<label class="btn btn-primary btn-sm" [class.active]="radioGroupForm.get('dateSpan').value === '3y'">
|
||||
<input type="radio" [value]="'3y'" [routerLink]="['/graphs' | relativeUrl]" fragment="3y" formControlName="dateSpan"> 3Y
|
||||
</label>
|
||||
<label class="btn btn-primary btn-sm" [class.active]="radioGroupForm.get('dateSpan').value === '4y'">
|
||||
<input type="radio" [value]="'4y'" [routerLink]="['/graphs' | relativeUrl]" fragment="4y" formControlName="dateSpan"> 4Y
|
||||
</label>
|
||||
</div>
|
||||
<div class="small-buttons">
|
||||
<div ngbDropdown #myDrop="ngbDropdown">
|
||||
|
@ -70,7 +70,7 @@ export class StatisticsComponent implements OnInit {
|
||||
this.route
|
||||
.fragment
|
||||
.subscribe((fragment) => {
|
||||
if (['2h', '24h', '1w', '1m', '3m', '6m', '1y', '2y', '3y'].indexOf(fragment) > -1) {
|
||||
if (['2h', '24h', '1w', '1m', '3m', '6m', '1y', '2y', '3y', '4y'].indexOf(fragment) > -1) {
|
||||
this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: false });
|
||||
}
|
||||
});
|
||||
@ -109,7 +109,10 @@ export class StatisticsComponent implements OnInit {
|
||||
if (this.radioGroupForm.controls.dateSpan.value === '2y') {
|
||||
return this.apiService.list2YStatistics$();
|
||||
}
|
||||
return this.apiService.list3YStatistics$();
|
||||
if (this.radioGroupForm.controls.dateSpan.value === '3y') {
|
||||
return this.apiService.list3YStatistics$();
|
||||
}
|
||||
return this.apiService.list4YStatistics$();
|
||||
})
|
||||
)
|
||||
.subscribe((mempoolStats: any) => {
|
||||
@ -181,7 +184,7 @@ export class StatisticsComponent implements OnInit {
|
||||
}
|
||||
|
||||
let capRatio = 10;
|
||||
if (['1m', '3m', '6m', '1y', '2y', '3y'].includes(this.graphWindowPreference)) {
|
||||
if (['1m', '3m', '6m', '1y', '2y', '3y', '4y'].includes(this.graphWindowPreference)) {
|
||||
capRatio = 4;
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,10 @@ export class ApiService {
|
||||
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/3y');
|
||||
}
|
||||
|
||||
list4YStatistics$(): Observable<OptimizedMempoolStats[]> {
|
||||
return this.httpClient.get<OptimizedMempoolStats[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/statistics/4y');
|
||||
}
|
||||
|
||||
getTransactionTimes$(txIds: string[]): Observable<number[]> {
|
||||
let params = new HttpParams();
|
||||
txIds.forEach((txId: string) => {
|
||||
|
@ -21,6 +21,7 @@ export const formatterXAxis = (
|
||||
return date.toLocaleTimeString(locale, { month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' });
|
||||
case '2y':
|
||||
case '3y':
|
||||
case '4y':
|
||||
case 'all':
|
||||
return date.toLocaleDateString(locale, { year: 'numeric', month: 'long', day: 'numeric' });
|
||||
}
|
||||
@ -45,6 +46,7 @@ export const formatterXAxisLabel = (
|
||||
case '1y':
|
||||
case '2y':
|
||||
case '3y':
|
||||
case '4y':
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@ -71,6 +73,7 @@ export const formatterXAxisTimeCategory = (
|
||||
return date.toLocaleDateString(locale, { year: 'numeric', month: 'short', day: 'numeric' });
|
||||
case '2y':
|
||||
case '3y':
|
||||
case '4y':
|
||||
case 'all':
|
||||
return date.toLocaleDateString(locale, { year: 'numeric', month: 'long' });
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ do for url in / \
|
||||
'/api/v1/statistics/1y' \
|
||||
'/api/v1/statistics/2y' \
|
||||
'/api/v1/statistics/3y' \
|
||||
'/api/v1/statistics/4y' \
|
||||
'/api/v1/mining/pools/24h' \
|
||||
'/api/v1/mining/pools/3d' \
|
||||
'/api/v1/mining/pools/1w' \
|
||||
|
Loading…
Reference in New Issue
Block a user