mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-27 16:24:41 +08:00
using actual test end for calculation instead of performance now
This commit is contained in:
parent
73d2db4799
commit
7770613ffb
1 changed files with 7 additions and 4 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue