Skip to content

Commit

Permalink
fix(result saving): dont save results if the tab was manually slowed …
Browse files Browse the repository at this point in the history
…down
  • Loading branch information
Miodec committed May 5, 2024
1 parent 413a74b commit 80e0af7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,12 @@ export async function finish(difficultyFailed = false): Promise<void> {

let tooShort = false;
//fail checks
if (difficultyFailed) {
const dateDur = (TestStats.end3 - TestStats.start3) / 1000;
if (ce.testDuration < dateDur - 0.05 || ce.testDuration > dateDur + 0.05) {
Notifications.add("Test invalid - inconsistent test duration", 0);
TestStats.setInvalid();
dontSave = true;
} else if (difficultyFailed) {
Notifications.add(`Test failed - ${failReason}`, 0, {
duration: 1,
});
Expand Down
16 changes: 15 additions & 1 deletion frontend/src/ts/test/test-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Stats = {
export let invalid = false;
export let start: number, end: number;
export let start2: number, end2: number;
export let start3: number, end3: number;
export let lastSecondNotRound = false;

export let lastResult: SharedTypes.Result<SharedTypes.Config.Mode>;
Expand Down Expand Up @@ -166,11 +167,13 @@ export function calculateWpmAndRaw(
export function setEnd(e: number): void {
end = e;
end2 = Date.now();
end3 = new Date().getTime();
}

export function setStart(s: number): void {
start = s;
start2 = Date.now();
start3 = new Date().getTime();
}

export function calculateAfkSeconds(testSeconds: number): number {
Expand Down Expand Up @@ -370,7 +373,18 @@ export function calculateStats(): Stats {
testSeconds,
" (date based) ",
(end2 - start2) / 1000,
" (performance.now based)"
" (performance.now based)",
(end3 - start3) / 1000,
" (new Date based)"
);
console.debug(
"Test seconds",
Numbers.roundTo1(testSeconds),
" (date based) ",
Numbers.roundTo1((end2 - start2) / 1000),
" (performance.now based)",
Numbers.roundTo1((end3 - start3) / 1000),
" (new Date based)"
);
if (Config.mode !== "custom") {
testSeconds = Numbers.roundTo2(testSeconds);
Expand Down

0 comments on commit 80e0af7

Please sign in to comment.