Adjust chart average calculations (#7559)
This commit is contained in:
parent
e3c19457b0
commit
834c076131
@ -68,16 +68,16 @@ function getPoints (details: Detail[], timeAvg: number): ChartInfo {
|
||||
|
||||
blocks.labels.push(blockNumber);
|
||||
blocks.values[0].push(details[i].block.bytes);
|
||||
blocks.values[1].push((blockTotal - details[i].block.bytes) / (details.length - 1));
|
||||
blocks.values[1].push(blockTotal / details.length);
|
||||
|
||||
events.labels.push(blockNumber);
|
||||
events.values[0].push(details[i].events.count);
|
||||
events.values[1].push(details[i].events.system);
|
||||
events.values[2].push((eventTotal - details[i].events.count) / (details.length - 1));
|
||||
events.values[2].push(eventTotal / details.length);
|
||||
|
||||
extrinsics.labels.push(blockNumber);
|
||||
extrinsics.values[0].push(details[i].extrinsics.count);
|
||||
extrinsics.values[1].push((txTotal - details[i].extrinsics.count) / (details.length - 1));
|
||||
extrinsics.values[1].push(txTotal / details.length);
|
||||
}
|
||||
|
||||
const filtered = details.filter(({ delay }) => delay);
|
||||
@ -86,7 +86,7 @@ function getPoints (details: Detail[], timeAvg: number): ChartInfo {
|
||||
for (let i = 0; i < filtered.length; i++) {
|
||||
times.labels.push(formatNumber(filtered[i].block.number));
|
||||
times.values[0].push(filtered[i].delay / 1000);
|
||||
times.values[1].push((avgBase - filtered[i].delay) / (filtered.length - 1) / 1000);
|
||||
times.values[1].push(avgBase / filtered.length / 1000);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@ -17,18 +17,22 @@ function extractPoints (points: DeriveStakerPoints[] = []): ChartInfo {
|
||||
const labels: string[] = [];
|
||||
const avgSet: LineDataEntry = [];
|
||||
const idxSet: LineDataEntry = [];
|
||||
let avgCount = 0;
|
||||
let total = 0;
|
||||
|
||||
points.forEach(({ era, points }): void => {
|
||||
total += points.toNumber();
|
||||
labels.push(era.toHuman());
|
||||
|
||||
const [total, avgCount] = points.reduce(([total, avgCount], { points }) => {
|
||||
if (points.gtn(0)) {
|
||||
total += points.toNumber();
|
||||
avgCount++;
|
||||
}
|
||||
|
||||
avgSet.push((avgCount ? Math.ceil(total * 100 / avgCount) : 0) / 100);
|
||||
return [total, avgCount];
|
||||
}, [0, 0]);
|
||||
|
||||
points.forEach(({ era, points }): void => {
|
||||
const avg = avgCount > 0
|
||||
? Math.ceil(total * 100 / avgCount) / 100
|
||||
: 0;
|
||||
|
||||
labels.push(era.toHuman());
|
||||
avgSet.push(avg);
|
||||
idxSet.push(points);
|
||||
});
|
||||
|
||||
|
||||
@ -19,20 +19,25 @@ function extractPrefs (prefs: DeriveStakerPrefs[] = []): ChartInfo {
|
||||
const labels: string[] = [];
|
||||
const avgSet: LineDataEntry = [];
|
||||
const idxSet: LineDataEntry = [];
|
||||
let avgCount = 0;
|
||||
let total = 0;
|
||||
|
||||
prefs.forEach(({ era, validatorPrefs }): void => {
|
||||
const [total, avgCount] = prefs.reduce(([total, avgCount], { validatorPrefs }) => {
|
||||
const comm = validatorPrefs.commission.unwrap().mul(MULT).div(BN_BILLION).toNumber() / 100;
|
||||
|
||||
total += comm;
|
||||
labels.push(era.toHuman());
|
||||
|
||||
if (comm !== 0) {
|
||||
total += comm;
|
||||
avgCount++;
|
||||
}
|
||||
|
||||
avgSet.push((avgCount ? Math.ceil(total * 100 / avgCount) : 0) / 100);
|
||||
return [total, avgCount];
|
||||
}, [0, 0]);
|
||||
|
||||
prefs.forEach(({ era, validatorPrefs }): void => {
|
||||
const comm = validatorPrefs.commission.unwrap().mul(MULT).div(BN_BILLION).toNumber() / 100;
|
||||
const avg = avgCount > 0
|
||||
? Math.ceil(total * 100 / avgCount) / 100
|
||||
: 0;
|
||||
|
||||
labels.push(era.toHuman());
|
||||
avgSet.push(avg);
|
||||
idxSet.push(comm);
|
||||
});
|
||||
|
||||
|
||||
@ -20,8 +20,19 @@ function extractRewards (erasRewards: DeriveEraRewards[] = [], ownSlashes: Deriv
|
||||
const slashSet: LineDataEntry = [];
|
||||
const rewardSet: LineDataEntry = [];
|
||||
const avgSet: LineDataEntry = [];
|
||||
let avgCount = 0;
|
||||
let total = 0;
|
||||
const [total, avgCount] = erasRewards.reduce(([total, avgCount], { era, eraReward }) => {
|
||||
const points = allPoints.find((points) => points.era.eq(era));
|
||||
const reward = points?.eraPoints.gtn(0)
|
||||
? balanceToNumber(points.points.mul(eraReward).div(points.eraPoints), divisor)
|
||||
: 0;
|
||||
|
||||
if (reward > 0) {
|
||||
total += reward;
|
||||
avgCount++;
|
||||
}
|
||||
|
||||
return [total, avgCount];
|
||||
}, [0, 0]);
|
||||
|
||||
erasRewards.forEach(({ era, eraReward }): void => {
|
||||
const points = allPoints.find((points) => points.era.eq(era));
|
||||
@ -32,16 +43,13 @@ function extractRewards (erasRewards: DeriveEraRewards[] = [], ownSlashes: Deriv
|
||||
const slash = slashed
|
||||
? balanceToNumber(slashed.total, divisor)
|
||||
: 0;
|
||||
|
||||
total += reward;
|
||||
|
||||
if (reward > 0) {
|
||||
avgCount++;
|
||||
}
|
||||
const avg = avgCount > 0
|
||||
? Math.ceil(total * 100 / avgCount) / 100
|
||||
: 0;
|
||||
|
||||
labels.push(era.toHuman());
|
||||
rewardSet.push(reward);
|
||||
avgSet.push((avgCount ? Math.ceil(total * 100 / avgCount) : 0) / 100);
|
||||
avgSet.push(avg);
|
||||
slashSet.push(slash);
|
||||
});
|
||||
|
||||
|
||||
@ -20,22 +20,27 @@ function extractStake (exposures: DeriveOwnExposure[] = [], divisor: BN): ChartI
|
||||
const cliSet: LineDataEntry = [];
|
||||
const expSet: LineDataEntry = [];
|
||||
const avgSet: LineDataEntry = [];
|
||||
let avgCount = 0;
|
||||
let total = 0;
|
||||
const [total, avgCount] = exposures.reduce(([total, avgCount], { clipped }) => {
|
||||
const cli = balanceToNumber(clipped.total?.unwrap(), divisor);
|
||||
|
||||
if (cli > 0) {
|
||||
total += cli;
|
||||
avgCount++;
|
||||
}
|
||||
|
||||
return [total, avgCount];
|
||||
}, [0, 0]);
|
||||
|
||||
exposures.forEach(({ clipped, era, exposure }): void => {
|
||||
// Darwinia Crab doesn't have the total field
|
||||
const cli = balanceToNumber(clipped.total?.unwrap(), divisor);
|
||||
const exp = balanceToNumber(exposure.total?.unwrap(), divisor);
|
||||
const avg = avgCount > 0
|
||||
? Math.ceil(total * 100 / avgCount) / 100
|
||||
: 0;
|
||||
|
||||
total += cli;
|
||||
|
||||
if (cli > 0) {
|
||||
avgCount++;
|
||||
}
|
||||
|
||||
avgSet.push((avgCount ? Math.ceil(total * 100 / avgCount) : 0) / 100);
|
||||
labels.push(era.toHuman());
|
||||
avgSet.push(avg);
|
||||
cliSet.push(cli);
|
||||
expSet.push(exp);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user