From 1a47ca9b00387e0ac8ada49123cbdf219161f52c Mon Sep 17 00:00:00 2001 From: Miodec Date: Wed, 5 Apr 2023 18:27:17 +0200 Subject: [PATCH] added start to first --- backend/src/api/schemas/result-schema.ts | 1 + frontend/src/ts/test/test-input.ts | 15 ++++++++++++--- frontend/src/ts/test/test-logic.ts | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/backend/src/api/schemas/result-schema.ts b/backend/src/api/schemas/result-schema.ts index 96842bd3d..69400e5bf 100644 --- a/backend/src/api/schemas/result-schema.ts +++ b/backend/src/api/schemas/result-schema.ts @@ -55,6 +55,7 @@ const RESULT_SCHEMA = joi ), keyOverlap: joi.number().min(0), lastKeyToEnd: joi.number().min(0), + startToFirstKey: joi.number().min(0), lang: joi.string(), stringified: joi.string(), language: joi.string().required(), diff --git a/frontend/src/ts/test/test-input.ts b/frontend/src/ts/test/test-input.ts index e3986587b..9bc9cdc8a 100644 --- a/frontend/src/ts/test/test-input.ts +++ b/frontend/src/ts/test/test-input.ts @@ -62,6 +62,7 @@ interface Keypress { interface KeypressTimings { spacing: { + first: number; last: number; array: number[]; }; @@ -216,6 +217,7 @@ export let accuracy = { }; export let keypressTimings: KeypressTimings = { spacing: { + first: -1, last: -1, array: [], }, @@ -329,8 +331,10 @@ export function recordKeydownTime(key: string): void { if (keyDownData[key] !== undefined) return; + const now = performance.now(); + keyDownData[key] = { - timestamp: performance.now(), + timestamp: now, index: keypressTimings.duration.array.length, }; keypressTimings.duration.array.push(0); @@ -338,7 +342,7 @@ export function recordKeydownTime(key: string): void { updateOverlap(keyDownData[key].timestamp); if (keypressTimings.spacing.last !== -1) { - const diff = Math.abs(performance.now() - keypressTimings.spacing.last); + const diff = Math.abs(now - keypressTimings.spacing.last); keypressTimings.spacing.array.push(roundTo2(diff)); if (spacingDebug) { console.log( @@ -352,7 +356,10 @@ export function recordKeydownTime(key: string): void { ); } } - keypressTimings.spacing.last = performance.now(); + keypressTimings.spacing.last = now; + if (keypressTimings.spacing.first === -1) { + keypressTimings.spacing.first = now; + } } function updateOverlap(now: number): void { @@ -372,6 +379,7 @@ function updateOverlap(now: number): void { export function resetKeypressTimings(): void { keypressTimings = { spacing: { + first: -1, last: -1, array: [], }, @@ -432,6 +440,7 @@ export function restart(): void { }; keypressTimings = { spacing: { + first: -1, last: -1, array: [], }, diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index 76042782d..9fa856093 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -1306,6 +1306,7 @@ interface CompletedEvent extends MonkeyTypes.Result { challenge?: string | null; keyOverlap: number; lastKeyToEnd: number; + startToFirstKey: number; } type PartialCompletedEvent = Omit, "chartData"> & { @@ -1382,6 +1383,9 @@ function buildCompletedEvent(difficultyFailed: boolean): CompletedEvent { lastKeyToEnd: Misc.roundTo2( TestStats.end - TestInput.keypressTimings.spacing.last ), + startToFirstKey: Misc.roundTo2( + TestInput.keypressTimings.spacing.first - TestStats.start + ), consistency: undefined, keyConsistency: undefined, funbox: Config.funbox,