Fix pools dominance chart
This commit is contained in:
parent
520e79aec4
commit
bbb0aea0d1
@ -11,6 +11,13 @@ import { MiningService } from '../../services/mining.service';
|
|||||||
import { download } from '../../shared/graphs.utils';
|
import { download } from '../../shared/graphs.utils';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
|
||||||
|
interface Hashrate {
|
||||||
|
timestamp: number;
|
||||||
|
avgHashRate: number;
|
||||||
|
share: number;
|
||||||
|
poolName: string;
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-hashrate-chart-pools',
|
selector: 'app-hashrate-chart-pools',
|
||||||
templateUrl: './hashrate-chart-pools.component.html',
|
templateUrl: './hashrate-chart-pools.component.html',
|
||||||
@ -32,6 +39,7 @@ export class HashrateChartPoolsComponent implements OnInit {
|
|||||||
miningWindowPreference: string;
|
miningWindowPreference: string;
|
||||||
radioGroupForm: UntypedFormGroup;
|
radioGroupForm: UntypedFormGroup;
|
||||||
|
|
||||||
|
hashrates: Hashrate[];
|
||||||
chartOptions: EChartsOption = {};
|
chartOptions: EChartsOption = {};
|
||||||
chartInitOptions = {
|
chartInitOptions = {
|
||||||
renderer: 'svg',
|
renderer: 'svg',
|
||||||
@ -87,26 +95,58 @@ export class HashrateChartPoolsComponent implements OnInit {
|
|||||||
return this.apiService.getHistoricalPoolsHashrate$(timespan)
|
return this.apiService.getHistoricalPoolsHashrate$(timespan)
|
||||||
.pipe(
|
.pipe(
|
||||||
tap((response) => {
|
tap((response) => {
|
||||||
const hashrates = response.body;
|
this.hashrates = response.body;
|
||||||
// Prepare series (group all hashrates data point by pool)
|
// Prepare series (group all hashrates data point by pool)
|
||||||
const grouped = {};
|
const series = this.applyHashrates();
|
||||||
for (const hashrate of hashrates) {
|
if (series.length === 0) {
|
||||||
if (!grouped.hasOwnProperty(hashrate.poolName)) {
|
this.cd.markForCheck();
|
||||||
grouped[hashrate.poolName] = [];
|
throw new Error();
|
||||||
}
|
}
|
||||||
grouped[hashrate.poolName].push(hashrate);
|
}),
|
||||||
|
map((response) => {
|
||||||
|
return {
|
||||||
|
blockCount: parseInt(response.headers.get('x-total-count'), 10),
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
retryWhen((errors) => errors.pipe(
|
||||||
|
delay(60000)
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
share()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
applyHashrates(): any[] {
|
||||||
|
const times: { [time: number]: { hashrates: { [pool: string]: Hashrate } } } = {};
|
||||||
|
const pools = {};
|
||||||
|
for (const hashrate of this.hashrates) {
|
||||||
|
if (!times[hashrate.timestamp]) {
|
||||||
|
times[hashrate.timestamp] = { hashrates: {} };
|
||||||
|
}
|
||||||
|
times[hashrate.timestamp].hashrates[hashrate.poolName] = hashrate;
|
||||||
|
if (!pools[hashrate.poolName]) {
|
||||||
|
pools[hashrate.poolName] = 0;
|
||||||
|
}
|
||||||
|
pools[hashrate.poolName] += hashrate.share;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortedTimes = Object.keys(times).sort((a,b) => parseInt(a) - parseInt(b)).map(time => ({ time: parseInt(time), hashrates: times[time].hashrates }));
|
||||||
|
const sortedPools = Object.keys(pools).sort((a,b) => pools[b] - pools[a]);
|
||||||
|
|
||||||
const series = [];
|
const series = [];
|
||||||
const legends = [];
|
const legends = [];
|
||||||
for (const name in grouped) {
|
for (const name of sortedPools) {
|
||||||
|
const data = sortedTimes.map(({ time, hashrates }) => {
|
||||||
|
return [time * 1000, (hashrates[name]?.share || 0) * 100];
|
||||||
|
});
|
||||||
series.push({
|
series.push({
|
||||||
zlevel: 0,
|
zlevel: 0,
|
||||||
stack: 'Total',
|
stack: 'Total',
|
||||||
name: name,
|
name: name,
|
||||||
showSymbol: false,
|
showSymbol: false,
|
||||||
symbol: 'none',
|
symbol: 'none',
|
||||||
data: grouped[name].map((val) => [val.timestamp * 1000, val.share * 100]),
|
data,
|
||||||
type: 'line',
|
type: 'line',
|
||||||
lineStyle: { width: 0 },
|
lineStyle: { width: 0 },
|
||||||
areaStyle: { opacity: 1 },
|
areaStyle: { opacity: 1 },
|
||||||
@ -137,23 +177,7 @@ export class HashrateChartPoolsComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
|
||||||
if (series.length === 0) {
|
return series;
|
||||||
this.cd.markForCheck();
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
map((response) => {
|
|
||||||
return {
|
|
||||||
blockCount: parseInt(response.headers.get('x-total-count'), 10),
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
retryWhen((errors) => errors.pipe(
|
|
||||||
delay(60000)
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
share()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareChartOptions(data) {
|
prepareChartOptions(data) {
|
||||||
@ -256,6 +280,7 @@ export class HashrateChartPoolsComponent implements OnInit {
|
|||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
this.cd.markForCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
onChartInit(ec) {
|
onChartInit(ec) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user