From 0690e26bb694fc1218b382235e769dfb0677a059 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 28 Mar 2023 13:04:20 +0200 Subject: [PATCH] testing new keypress duration apprach --- .../src/ts/controllers/input-controller.ts | 2 + frontend/src/ts/test/test-input.ts | 40 ++++++++++++++++++- frontend/src/ts/test/test-logic.ts | 2 + 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/frontend/src/ts/controllers/input-controller.ts b/frontend/src/ts/controllers/input-controller.ts index e9ee27534..91c5042ef 100644 --- a/frontend/src/ts/controllers/input-controller.ts +++ b/frontend/src/ts/controllers/input-controller.ts @@ -834,6 +834,7 @@ $(document).keydown(async (event) => { } TestInput.recordKeypressSpacing(); TestInput.setKeypressDuration(performance.now()); + TestInput.recordKeydownTime(event.code); TestInput.setKeypressNotAfk(); //blocking firefox from going back in history with backspace @@ -963,6 +964,7 @@ $("#wordsInput").keyup((event) => { ); TestInput.pushKeypressDuration(diff); } + TestInput.recordKeyupTime(event.code); TestInput.setKeypressDuration(now); Monkey.stop(); }); diff --git a/frontend/src/ts/test/test-input.ts b/frontend/src/ts/test/test-input.ts index b7cfdc2c0..abcb20805 100644 --- a/frontend/src/ts/test/test-input.ts +++ b/frontend/src/ts/test/test-input.ts @@ -1,5 +1,5 @@ import * as TestWords from "./test-words"; -import { roundTo2 } from "../utils/misc"; +import { roundTo2, stdDev, mean } from "../utils/misc"; interface Keypress { count: number; @@ -227,7 +227,14 @@ export function setKeypressTimingsTooLong(): void { keypressTimings.duration.array = "toolong"; } +const keysObj: Record = {}; + +let t1 = 0; +let d1 = 0; + export function pushKeypressDuration(val: number): void { + t1 += val; + d1++; (keypressTimings.duration.array as number[]).push(roundTo2(val)); } @@ -235,6 +242,37 @@ export function setKeypressDuration(val: number): void { keypressTimings.duration.current = roundTo2(val); } +let t2 = 0; +let d2 = 0; +const a: number[] = []; + +export function recordKeyupTime(key: string): void { + const now = performance.now(); + const diff = Math.abs(keysObj[key] - now); + + t2 += diff; + d2++; + a.push(roundTo2(diff)); +} + +export function recordKeydownTime(key: string): void { + keysObj[key] = performance.now(); +} + +export function logOldAndNew(): void { + if (!spacingDebug) return; + console.log( + "old", + t1, + d1, + t1 / d1, + keypressTimings.duration.array, + stdDev(keypressTimings.duration.array as number[]), + mean(keypressTimings.duration.array as number[]) + ); + console.log("new", t2, d2, t2 / d2, a, stdDev(a), mean(a)); +} + function pushKeypressSpacing(val: number): void { (keypressTimings.spacing.array as number[]).push(roundTo2(val)); } diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index bd829011b..94c7ae3f3 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -1390,6 +1390,8 @@ function buildCompletedEvent(difficultyFailed: boolean): CompletedEvent { afkDuration: undefined, }; + TestInput.logOldAndNew(); + // stats const stats = TestStats.calculateStats(); if (stats.time % 1 != 0 && Config.mode !== "time") {