From cf605b9fa9a28b6fe69377fdfdb5cc5380dc213c Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Mon, 4 Nov 2024 23:47:08 +0000 Subject: [PATCH] update --- src/cli.ts | 8 ++++++-- test/cli.test.js | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index fb2421b1..5e768c35 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -424,7 +424,7 @@ 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, @@ -432,11 +432,15 @@ export const handleOppsRecord = ( 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) => { diff --git a/test/cli.test.js b/test/cli.test.js index 003842f6..349c9104 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -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); }); });