using actual test end for calculation instead of performance now

This commit is contained in:
Miodec 2023-04-17 16:38:09 +02:00
parent 73d2db4799
commit 7770613ffb

View file

@ -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,