From 4160e82fa880dca4bbe9ebb0f6df734b35a315cd Mon Sep 17 00:00:00 2001 From: Miodec Date: Wed, 5 Apr 2023 23:47:00 +0200 Subject: [PATCH 1/2] better spacing debug --- .../src/ts/controllers/input-controller.ts | 9 ---- frontend/src/ts/test/test-input.ts | 43 ++++++++++++++++--- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/frontend/src/ts/controllers/input-controller.ts b/frontend/src/ts/controllers/input-controller.ts index 43eaa19a9..ded10b2d2 100644 --- a/frontend/src/ts/controllers/input-controller.ts +++ b/frontend/src/ts/controllers/input-controller.ts @@ -824,15 +824,6 @@ $(document).keydown(async (event) => { return; } - if (TestInput.spacingDebug) { - console.log( - "spacing debug", - "keypress", - event.key, - "length", - TestInput.keypressTimings.spacing.array.length - ); - } TestInput.setKeypressNotAfk(); //blocking firefox from going back in history with backspace diff --git a/frontend/src/ts/test/test-input.ts b/frontend/src/ts/test/test-input.ts index 9bc9cdc8a..aa0381f4c 100644 --- a/frontend/src/ts/test/test-input.ts +++ b/frontend/src/ts/test/test-input.ts @@ -322,14 +322,36 @@ export function recordKeyupTime(key: string): void { } export function recordKeydownTime(key: string): void { - if (!keysToTrack.includes(key)) return; + if (!keysToTrack.includes(key)) { + if (spacingDebug) { + console.log( + "spacing debug", + "key not tracked", + key, + "spacing array", + keypressTimings.spacing.array.length + ); + } + return; + } if (key === "Android") { key = "Android" + androidIndex; androidIndex++; } - if (keyDownData[key] !== undefined) return; + if (keyDownData[key] !== undefined) { + if (spacingDebug) { + console.log( + "spacing debug", + "key already down", + key, + "spacing array", + keypressTimings.spacing.array.length + ); + } + return; + } const now = performance.now(); @@ -348,8 +370,8 @@ export function recordKeydownTime(key: string): void { console.log( "spacing debug", "recorded", - "key", - "length", + key, + "spacing array", keypressTimings.spacing.array.length, "val", roundTo2(diff) @@ -359,6 +381,9 @@ export function recordKeydownTime(key: string): void { keypressTimings.spacing.last = now; if (keypressTimings.spacing.first === -1) { keypressTimings.spacing.first = now; + if (spacingDebug) { + console.log("spacing debug", "saved first", now); + } } } @@ -393,7 +418,12 @@ export function resetKeypressTimings(): void { }; keyDownData = {}; androidIndex = 0; - if (spacingDebug) console.clear(); + if (spacingDebug) { + console.clear(); + if (spacingDebug) { + console.log("spacing debug", "reset keypress timings"); + } + } } export function pushMissedWord(word: string): void { @@ -448,4 +478,7 @@ export function restart(): void { array: [], }, }; + if (spacingDebug) { + console.log("spacing debug", "restart"); + } } From eedb92d77f72b2fef5484dcf2ba815b497ee12a3 Mon Sep 17 00:00:00 2001 From: Miodec Date: Thu, 6 Apr 2023 01:39:44 +0200 Subject: [PATCH 2/2] sending chartotal to the backend --- backend/src/api/controllers/result.ts | 1 + backend/src/api/schemas/result-schema.ts | 1 + frontend/src/ts/test/test-logic.ts | 3 +++ 3 files changed, 5 insertions(+) diff --git a/backend/src/api/controllers/result.ts b/backend/src/api/controllers/result.ts index 2e9bd0b55..937ad666f 100644 --- a/backend/src/api/controllers/result.ts +++ b/backend/src/api/controllers/result.ts @@ -322,6 +322,7 @@ export async function addResult( delete result.keyOverlap; delete result.lastKeyToEnd; delete result.startToFirstKey; + delete result.charTotal; if (req.ctx.configuration.users.lastHashesCheck.enabled) { let lastHashes = user.lastReultHashes ?? []; diff --git a/backend/src/api/schemas/result-schema.ts b/backend/src/api/schemas/result-schema.ts index 69400e5bf..c033427e6 100644 --- a/backend/src/api/schemas/result-schema.ts +++ b/backend/src/api/schemas/result-schema.ts @@ -8,6 +8,7 @@ const RESULT_SCHEMA = joi blindMode: joi.boolean().required(), challenge: joi.string(), charStats: joi.array().items(joi.number().min(0)).required(), + charTotal: joi.number().min(0), chartData: joi .alternatives() .try( diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index 9fa856093..a99781aba 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -1307,6 +1307,7 @@ interface CompletedEvent extends MonkeyTypes.Result { keyOverlap: number; lastKeyToEnd: number; startToFirstKey: number; + charTotal: number; } type PartialCompletedEvent = Omit, "chartData"> & { @@ -1359,6 +1360,7 @@ function buildCompletedEvent(difficultyFailed: boolean): CompletedEvent { wpm: undefined, rawWpm: undefined, charStats: undefined, + charTotal: undefined, acc: undefined, mode: Config.mode, mode2: undefined, @@ -1414,6 +1416,7 @@ function buildCompletedEvent(difficultyFailed: boolean): CompletedEvent { stats.extraChars, stats.missedChars, ]; + completedEvent.charTotal = stats.allChars; completedEvent.acc = stats.acc; // if the last second was not rounded, add another data point to the history