Only show relevant hashrate in the pool page
This commit is contained in:
parent
ad2dcc46e4
commit
2b5d972e8d
@ -58,14 +58,14 @@ class Mining {
|
|||||||
/**
|
/**
|
||||||
* Get all mining pool stats for a pool
|
* Get all mining pool stats for a pool
|
||||||
*/
|
*/
|
||||||
public async $getPoolStat(interval: string | null, poolId: number): Promise<object> {
|
public async $getPoolStat(poolId: number): Promise<object> {
|
||||||
const pool = await PoolsRepository.$getPool(poolId);
|
const pool = await PoolsRepository.$getPool(poolId);
|
||||||
if (!pool) {
|
if (!pool) {
|
||||||
throw new Error(`This mining pool does not exist`);
|
throw new Error(`This mining pool does not exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const blockCount: number = await BlocksRepository.$blockCount(poolId, interval);
|
const blockCount: number = await BlocksRepository.$blockCount(poolId);
|
||||||
const emptyBlocks: EmptyBlocks[] = await BlocksRepository.$getEmptyBlocks(poolId, interval);
|
const emptyBlocks: EmptyBlocks[] = await BlocksRepository.$getEmptyBlocks(poolId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pool: pool,
|
pool: pool,
|
||||||
|
@ -299,7 +299,7 @@ class Server {
|
|||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pools/2y', routes.$getPools.bind(routes, '2y'))
|
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pools/2y', routes.$getPools.bind(routes, '2y'))
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pools/3y', routes.$getPools.bind(routes, '3y'))
|
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pools/3y', routes.$getPools.bind(routes, '3y'))
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pools/all', routes.$getPools.bind(routes, 'all'))
|
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pools/all', routes.$getPools.bind(routes, 'all'))
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId/hashrate/:interval', routes.$getPoolHistoricalHashrate)
|
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId/hashrate', routes.$getPoolHistoricalHashrate)
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId/blocks', routes.$getPoolBlocks)
|
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId/blocks', routes.$getPoolBlocks)
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId/blocks/:height', routes.$getPoolBlocks)
|
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId/blocks/:height', routes.$getPoolBlocks)
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId', routes.$getPool)
|
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/pool/:poolId', routes.$getPool)
|
||||||
|
@ -134,7 +134,7 @@ class BlocksRepository {
|
|||||||
/**
|
/**
|
||||||
* Get blocks count for a period
|
* Get blocks count for a period
|
||||||
*/
|
*/
|
||||||
public async $blockCount(poolId: number | null, interval: string | null): Promise<number> {
|
public async $blockCount(poolId: number | null, interval: string | null = null): Promise<number> {
|
||||||
interval = Common.getSqlInterval(interval);
|
interval = Common.getSqlInterval(interval);
|
||||||
|
|
||||||
const params: any[] = [];
|
const params: any[] = [];
|
||||||
|
@ -119,28 +119,39 @@ class HashratesRepository {
|
|||||||
/**
|
/**
|
||||||
* Returns a pool hashrate history
|
* Returns a pool hashrate history
|
||||||
*/
|
*/
|
||||||
public async $getPoolWeeklyHashrate(interval: string | null, poolId: number): Promise<any[]> {
|
public async $getPoolWeeklyHashrate(poolId: number): Promise<any[]> {
|
||||||
interval = Common.getSqlInterval(interval);
|
|
||||||
|
|
||||||
const connection = await DB.pool.getConnection();
|
const connection = await DB.pool.getConnection();
|
||||||
|
|
||||||
let query = `SELECT UNIX_TIMESTAMP(hashrate_timestamp) as timestamp, avg_hashrate as avgHashrate, share, pools.name as poolName
|
// Find hashrate boundaries
|
||||||
FROM hashrates
|
let query = `SELECT MIN(hashrate_timestamp) as firstTimestamp, MAX(hashrate_timestamp) as lastTimestamp
|
||||||
JOIN pools on pools.id = pool_id`;
|
FROM hashrates
|
||||||
|
JOIN pools on pools.id = pool_id
|
||||||
if (interval) {
|
WHERE hashrates.type = 'weekly' AND pool_id = ${poolId} AND avg_hashrate != 0
|
||||||
query += ` WHERE hashrate_timestamp BETWEEN DATE_SUB(NOW(), INTERVAL ${interval}) AND NOW()
|
ORDER by hashrate_timestamp LIMIT 1`
|
||||||
AND hashrates.type = 'weekly'
|
|
||||||
AND pool_id = ${poolId}`;
|
|
||||||
} else {
|
|
||||||
query += ` WHERE hashrates.type = 'weekly'
|
|
||||||
AND pool_id = ${poolId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
query += ` ORDER by hashrate_timestamp`;
|
|
||||||
|
|
||||||
|
let boundaries = {
|
||||||
|
firstTimestamp: '1970-01-01',
|
||||||
|
lastTimestamp: '9999-01-01'
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
const [rows]: any[] = await connection.query(query);
|
const [rows]: any[] = await connection.query(query);
|
||||||
|
boundaries = rows[0];
|
||||||
|
connection.release();
|
||||||
|
} catch (e) {
|
||||||
|
connection.release();
|
||||||
|
logger.err('$getPoolWeeklyHashrate() error' + (e instanceof Error ? e.message : e));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get hashrates entries between boundaries
|
||||||
|
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
|
||||||
|
WHERE hashrates.type = 'weekly' AND hashrate_timestamp BETWEEN ? AND ?
|
||||||
|
AND pool_id = ${poolId}
|
||||||
|
ORDER by hashrate_timestamp`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [rows]: any[] = await connection.query(query, [boundaries.firstTimestamp, boundaries.lastTimestamp]);
|
||||||
connection.release();
|
connection.release();
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
|
@ -538,7 +538,7 @@ class Routes {
|
|||||||
|
|
||||||
public async $getPool(req: Request, res: Response) {
|
public async $getPool(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const stats = await mining.$getPoolStat(req.params.interval ?? null, parseInt(req.params.poolId, 10));
|
const stats = await mining.$getPoolStat(parseInt(req.params.poolId, 10));
|
||||||
res.header('Pragma', 'public');
|
res.header('Pragma', 'public');
|
||||||
res.header('Cache-control', 'public');
|
res.header('Cache-control', 'public');
|
||||||
res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString());
|
res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString());
|
||||||
@ -605,7 +605,7 @@ class Routes {
|
|||||||
|
|
||||||
public async $getPoolHistoricalHashrate(req: Request, res: Response) {
|
public async $getPoolHistoricalHashrate(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const hashrates = await HashratesRepository.$getPoolWeeklyHashrate(req.params.interval ?? null, parseInt(req.params.poolId, 10));
|
const hashrates = await HashratesRepository.$getPoolWeeklyHashrate(parseInt(req.params.poolId, 10));
|
||||||
const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp();
|
const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp();
|
||||||
res.header('Pragma', 'public');
|
res.header('Pragma', 'public');
|
||||||
res.header('Cache-control', 'public');
|
res.header('Cache-control', 'public');
|
||||||
|
@ -1,36 +1,11 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<div *ngIf="poolStats$ | async as poolStats">
|
<div *ngIf="poolStats$ | async as poolStats">
|
||||||
<div style="display: flex; justify-content: space-between; flex-wrap: wrap;">
|
<h1 class="m-0">
|
||||||
<h1 class="m-0">
|
<img width="50" src="{{ poolStats['logo'] }}" onError="this.src = './resources/mining-pools/default.svg'"
|
||||||
<img width="50" src="{{ poolStats['logo'] }}" onError="this.src = './resources/mining-pools/default.svg'"
|
class="mr-3">
|
||||||
class="mr-3">
|
{{ poolStats.pool.name }}
|
||||||
{{ poolStats.pool.name }}
|
</h1>
|
||||||
</h1>
|
|
||||||
<div class="pl-0 bg-transparent">
|
|
||||||
<div class="card-header mb-0 mb-lg-4 pr-0 pl-0">
|
|
||||||
<form [formGroup]="radioGroupForm" class="formRadioGroup ml-0">
|
|
||||||
<div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" formControlName="dateSpan">
|
|
||||||
<label ngbButtonLabel class="btn-primary btn-sm">
|
|
||||||
<input ngbButton type="radio" [value]="'6m'"> 6M
|
|
||||||
</label>
|
|
||||||
<label ngbButtonLabel class="btn-primary btn-sm">
|
|
||||||
<input ngbButton type="radio" [value]="'1y'"> 1Y
|
|
||||||
</label>
|
|
||||||
<label ngbButtonLabel class="btn-primary btn-sm">
|
|
||||||
<input ngbButton type="radio" [value]="'2y'"> 2Y
|
|
||||||
</label>
|
|
||||||
<label ngbButtonLabel class="btn-primary btn-sm">
|
|
||||||
<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>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, Inject, Input, LOCALE_ID, OnInit } from '@angular/core';
|
||||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import { EChartsOption, graphic } from 'echarts';
|
import { EChartsOption, graphic } from 'echarts';
|
||||||
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
import { distinctUntilChanged, map, startWith, switchMap, tap, toArray } from 'rxjs/operators';
|
import { distinctUntilChanged, map, switchMap, tap, toArray } from 'rxjs/operators';
|
||||||
import { BlockExtended, PoolStat } from 'src/app/interfaces/node-api.interface';
|
import { BlockExtended, PoolStat } from 'src/app/interfaces/node-api.interface';
|
||||||
import { ApiService } from 'src/app/services/api.service';
|
import { ApiService } from 'src/app/services/api.service';
|
||||||
import { StateService } from 'src/app/services/state.service';
|
import { StateService } from 'src/app/services/state.service';
|
||||||
@ -24,8 +23,6 @@ export class PoolComponent implements OnInit {
|
|||||||
blocks$: Observable<BlockExtended[]>;
|
blocks$: Observable<BlockExtended[]>;
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
|
|
||||||
radioGroupForm: FormGroup;
|
|
||||||
|
|
||||||
chartOptions: EChartsOption = {};
|
chartOptions: EChartsOption = {};
|
||||||
chartInitOptions = {
|
chartInitOptions = {
|
||||||
renderer: 'svg',
|
renderer: 'svg',
|
||||||
@ -44,34 +41,27 @@ export class PoolComponent implements OnInit {
|
|||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
public stateService: StateService,
|
public stateService: StateService,
|
||||||
private formBuilder: FormBuilder,
|
|
||||||
) {
|
) {
|
||||||
this.radioGroupForm = this.formBuilder.group({ dateSpan: 'all' });
|
|
||||||
this.radioGroupForm.controls.dateSpan.setValue('all');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.poolStats$ = combineLatest([
|
this.poolStats$ = this.route.params.pipe(map((params) => params.poolId))
|
||||||
this.route.params.pipe(map((params) => params.poolId)),
|
|
||||||
this.radioGroupForm.get('dateSpan').valueChanges.pipe(startWith('all')),
|
|
||||||
])
|
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((params: any) => {
|
switchMap((poolId: any) => {
|
||||||
this.poolId = params[0];
|
this.poolId = poolId;
|
||||||
return this.apiService.getPoolHashrate$(this.poolId, params[1] ?? 'all')
|
return this.apiService.getPoolHashrate$(this.poolId)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((data) => {
|
switchMap((data) => {
|
||||||
this.prepareChartOptions(data.hashrates.map(val => [val.timestamp * 1000, val.avgHashrate]));
|
this.prepareChartOptions(data.hashrates.map(val => [val.timestamp * 1000, val.avgHashrate]));
|
||||||
return params;
|
return poolId;
|
||||||
}),
|
}),
|
||||||
toArray(),
|
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
switchMap((params: any) => {
|
switchMap(() => {
|
||||||
if (this.blocks.length === 0) {
|
if (this.blocks.length === 0) {
|
||||||
this.fromHeightSubject.next(undefined);
|
this.fromHeightSubject.next(undefined);
|
||||||
}
|
}
|
||||||
return this.apiService.getPoolStats$(this.poolId, params[1] ?? '1w');
|
return this.apiService.getPoolStats$(this.poolId);
|
||||||
}),
|
}),
|
||||||
map((poolStats) => {
|
map((poolStats) => {
|
||||||
let regexes = '"';
|
let regexes = '"';
|
||||||
|
@ -136,15 +136,12 @@ export class ApiService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPoolStats$(poolId: number, interval: string | undefined): Observable<PoolStat> {
|
getPoolStats$(poolId: number): Observable<PoolStat> {
|
||||||
return this.httpClient.get<PoolStat>(
|
return this.httpClient.get<PoolStat>(this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/pool/${poolId}`);
|
||||||
this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/pool/${poolId}` +
|
|
||||||
(interval !== undefined ? `/${interval}` : '')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPoolHashrate$(poolId: number, interval: string | undefined): Observable<any> {
|
getPoolHashrate$(poolId: number): Observable<any> {
|
||||||
return this.httpClient.get<any>(this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/pool/${poolId}/hashrate/${interval}`);
|
return this.httpClient.get<any>(this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/pool/${poolId}/hashrate`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPoolBlocks$(poolId: number, fromHeight: number): Observable<BlockExtended[]> {
|
getPoolBlocks$(poolId: number, fromHeight: number): Observable<BlockExtended[]> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user