Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Nov 4, 2024
1 parent 84b7c02 commit cf605b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,19 +424,23 @@ export async function startup(argv: any, version?: string, tracer?: Tracer, ctx?
}

/**
* Calculates the opps count standard deviation from the avg of the given length of previous rounds records
* Calculates the opps count standard deviation from the given length of previous rounds records
*/
export const handleOppsRecord = (
recordSize: number,
previousRecords: number[],
oppCount: number,
): number => {
const avg = Math.floor(previousRecords.reduce((a, b) => a + b, 0) / previousRecords.length);
const sumOfSquaresAvg =
previousRecords.map((v) => (avg - v) ** 2).reduce((a, b) => a + b, 0) /
previousRecords.length;
const stdvsRounup = Math.round(Math.sqrt(sumOfSquaresAvg)); // roundup
previousRecords.push(oppCount);
if (previousRecords.length > recordSize) {
previousRecords.splice(0, previousRecords.length - recordSize);
}
return oppCount - avg;
return oppCount - stdvsRounup;
};

export const main = async (argv: any, version?: string) => {
Expand Down
6 changes: 3 additions & 3 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ describe("Test cli", async function () {
});

it("test handleOppsRecord()", async function () {
const record = [3, 4, 5, 3, 3, 7, 4];
const size = 7;
const record = [6, 2, 3, 1];
const size = 4;
const currentOppCount = 1;
const result = handleOppsRecord(size, record, currentOppCount);
const expected = -3;
const expected = -1;
assert.equal(result, expected);
});
});

0 comments on commit cf605b9

Please sign in to comment.