diff --git a/frontend/src/ts/test/test-stats.ts b/frontend/src/ts/test/test-stats.ts index a30f7ddaf..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,7 +187,7 @@ export function setInvalid(): void { export function calculateTestSeconds(now?: number): number { if (now === undefined) { - return (end - start) / 1000; + return (end - start) / 1000; } else { return (now - start) / 1000; } @@ -275,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,