mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-28 16:54:04 +08:00
testing new keypress duration apprach
This commit is contained in:
parent
e4b3182c3a
commit
0690e26bb6
3 changed files with 43 additions and 1 deletions
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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<string, number> = {};
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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") {
|
||||
|
|
Loading…
Reference in a new issue