mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 13:27:49 +08:00
hopefully fixed the extra time added when the website is left in the background for a long time
This commit is contained in:
parent
393b57455a
commit
88ad37484f
2 changed files with 20 additions and 6 deletions
|
@ -659,9 +659,10 @@ export function restart(
|
|||
if (active) {
|
||||
TestStats.pushKeypressesToHistory();
|
||||
let testSeconds = TestStats.calculateTestSeconds(performance.now());
|
||||
let afkseconds = TestStats.calculateAfkSeconds();
|
||||
let afkseconds = TestStats.calculateAfkSeconds(testSeconds);
|
||||
// incompleteTestSeconds += ;
|
||||
let tt = testSeconds - afkseconds;
|
||||
if (tt < 0) tt = 0;
|
||||
console.log(
|
||||
`increasing incomplete time by ${tt}s (${testSeconds}s - ${afkseconds}s afk)`
|
||||
);
|
||||
|
@ -1033,7 +1034,7 @@ export function finish(difficultyFailed = false) {
|
|||
lastTestWpm = stats.wpm;
|
||||
|
||||
let testtime = stats.time;
|
||||
let afkseconds = TestStats.calculateAfkSeconds();
|
||||
let afkseconds = TestStats.calculateAfkSeconds(testtime);
|
||||
let afkSecondsPercent = Misc.roundTo2((afkseconds / testtime) * 100);
|
||||
|
||||
ChartController.result.options.annotation.annotations = [];
|
||||
|
@ -1857,7 +1858,9 @@ export function fail() {
|
|||
TestStats.pushKeypressesToHistory();
|
||||
finish(true);
|
||||
let testSeconds = TestStats.calculateTestSeconds(performance.now());
|
||||
let afkseconds = TestStats.calculateAfkSeconds();
|
||||
TestStats.incrementIncompleteSeconds(testSeconds - afkseconds);
|
||||
let afkseconds = TestStats.calculateAfkSeconds(testSeconds);
|
||||
let tt = testSeconds - afkseconds;
|
||||
if (tt < 0) tt = 0;
|
||||
TestStats.incrementIncompleteSeconds(tt);
|
||||
TestStats.incrementRestartCount();
|
||||
}
|
||||
|
|
|
@ -156,8 +156,19 @@ export function pushKeypressesToHistory() {
|
|||
};
|
||||
}
|
||||
|
||||
export function calculateAfkSeconds() {
|
||||
return keypressPerSecond.filter((x) => x.count == 0 && x.mod == 0).length;
|
||||
export function calculateAfkSeconds(testSeconds) {
|
||||
let extraAfk = 0;
|
||||
if (testSeconds !== undefined) {
|
||||
extraAfk = Math.ceil(testSeconds) - keypressPerSecond.length;
|
||||
console.log("-- extra afk debug");
|
||||
console.log("should be " + Math.ceil(testSeconds));
|
||||
console.log(keypressPerSecond.length);
|
||||
console.log(
|
||||
`gonna add extra ${extraAfk} seconds of afk because of no keypress data`
|
||||
);
|
||||
}
|
||||
let ret = keypressPerSecond.filter((x) => x.count == 0 && x.mod == 0).length;
|
||||
return ret + extraAfk;
|
||||
}
|
||||
|
||||
export function setLastSecondNotRound() {
|
||||
|
|
Loading…
Reference in a new issue