Skip to content

Commit

Permalink
Fixed removing outliers from block times
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvelmer committed Nov 29, 2023
1 parent bacce14 commit c228c92
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/core/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,23 @@ export abstract class ElectionCore extends TransactionCore {
if (typeof dateTime == 'number') dateTime = new Date(dateTime);
else if (!(dateTime instanceof Date)) return null;

const outliers = (arr: number[]): number[] => {
const values = arr.concat();
values.sort((a, b) => a - b);

const q1 = values[Math.floor(values.length / 4)];
const q3 = values[Math.ceil(values.length * (3 / 4))];
const iqr = q3 - q1;
const maxValue = q3 + iqr * 1.5;
const minValue = q1 - iqr * 1.5;

return values.filter((x) => x <= maxValue && x >= minValue);
};

chainData.blockTime = chainData.blockTime.map((part) => {
return outliers(chainData.blockTime).includes(part) ? part : 0;
});

let averageBlockTime = this.VOCHAIN_BLOCK_TIME_IN_SECONDS * 1000;
let weightA: number, weightB: number;

Expand Down

0 comments on commit c228c92

Please sign in to comment.