diff --git a/frontend/src/ts/controllers/input-controller.ts b/frontend/src/ts/controllers/input-controller.ts index c3d05ac0a..f732593a9 100644 --- a/frontend/src/ts/controllers/input-controller.ts +++ b/frontend/src/ts/controllers/input-controller.ts @@ -238,7 +238,6 @@ function handleSpace(): void { Caret.updatePosition(); TestInput.incrementKeypressCount(); TestInput.pushKeypressWord(TestWords.words.currentIndex); - TestInput.updateLastKeypress(); if (Config.difficulty == "expert" || Config.difficulty == "master") { TestLogic.fail("difficulty"); return; @@ -249,6 +248,7 @@ function handleSpace(): void { } Replay.addReplayEvent("submitErrorWord"); } + TestInput.updateLastKeypress(); let wordLength: number; if (Config.mode === "zen") { @@ -885,7 +885,7 @@ $(document).keydown(async (event) => { 0, { important: true, - duration: 5000, + duration: 5, } ); } diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index b54b24077..5b4040612 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -1555,6 +1555,11 @@ export async function finish(difficultyFailed = false): Promise { TestInput.forceKeyup(now); //this ensures that the last keypress(es) are registered + const endAfkSeconds = (now - TestInput.keypressTimings.spacing.last) / 1000; + if ((Config.mode == "zen" || TestInput.bailout) && endAfkSeconds < 7) { + TestStats.setEnd(TestInput.keypressTimings.spacing.last); + } + TestUI.setResultCalculating(true); TestUI.setResultVisible(true); TestState.setActive(false); diff --git a/frontend/src/ts/test/test-stats.ts b/frontend/src/ts/test/test-stats.ts index ae69c7289..4b5200c6c 100644 --- a/frontend/src/ts/test/test-stats.ts +++ b/frontend/src/ts/test/test-stats.ts @@ -4,6 +4,7 @@ import * as Misc from "../utils/misc"; import * as TestInput from "./test-input"; import * as TestWords from "./test-words"; import * as FunboxList from "./funbox/funbox-list"; +import * as TestState from "./test-state"; interface CharCount { spaces: number; @@ -186,16 +187,12 @@ export function setInvalid(): void { export function calculateTestSeconds(now?: number): number { if (now === undefined) { - const endAfkSeconds = (end - TestInput.lastKeypress) / 1000; - if ((Config.mode == "zen" || TestInput.bailout) && endAfkSeconds < 7) { - return (TestInput.lastKeypress - start) / 1000; - } else { - return (end - start) / 1000; - } + return (end - start) / 1000; } else { return (now - start) / 1000; } } + let avg = 0; export function calculateWpmAndRaw(): MonkeyTypes.WordsPerMinuteAndRaw { const start = performance.now(); @@ -279,13 +276,15 @@ export function calculateWpmAndRaw(): MonkeyTypes.WordsPerMinuteAndRaw { spaces = 0; } chars += currTestInput.length; - const testSeconds = calculateTestSeconds(performance.now()); + const testSeconds = calculateTestSeconds( + TestState.isActive ? performance.now() : end + ); const wpm = Math.round( ((correctWordChars + spaces) * (60 / testSeconds)) / 5 ); const raw = Math.round(((chars + spaces) * (60 / testSeconds)) / 5); - const end = performance.now(); - avg = (end - start + avg) / 2; + const endPerf = performance.now(); + avg = (endPerf - start + avg) / 2; return { wpm: wpm, raw: raw, diff --git a/frontend/static/about/supporters.json b/frontend/static/about/supporters.json index f3ab15dec..9ee37423a 100644 --- a/frontend/static/about/supporters.json +++ b/frontend/static/about/supporters.json @@ -80,6 +80,7 @@ "John", "Moanatari", "Gregory", + "Yen Cheng", "Hopeless Love", "Kalen", "Ben",