Merge pull request #1312 from Estebene/master

Ignoring Zen Trailing AFK #966
This commit is contained in:
Jack 2021-05-01 19:19:18 +01:00 committed by GitHub
commit ac9b2b918f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 4 deletions

View file

@ -288,12 +288,12 @@ function handleSpace(event, isEnter) {
// currentKeypress.words.push(TestLogic.words.currentIndex);
TestStats.incrementKeypressCount();
TestStats.pushKeypressWord(TestLogic.words.currentIndex);
TestStats.updateLastKeypress();
if (Config.difficulty == "expert" || Config.difficulty == "master") {
TestLogic.fail();
return;
} else if (TestLogic.words.currentIndex == TestLogic.words.length) {
//submitted last word that is incorrect
TestStats.setLastSecondNotRound();
TestLogic.finish();
return;
}
@ -609,6 +609,7 @@ function handleAlpha(event) {
}
}
TestStats.incrementKeypressCount();
TestStats.updateLastKeypress();
TestStats.pushKeypressWord(TestLogic.words.currentIndex);
// currentKeypress.count++;
// currentKeypress.words.push(TestLogic.words.currentIndex);
@ -672,7 +673,6 @@ function handleAlpha(event) {
TestLogic.input.pushHistory();
TestLogic.corrected.pushHistory();
TestStats.setLastSecondNotRound();
TestLogic.finish();
}
}

View file

@ -948,6 +948,14 @@ export function finish(difficultyFailed = false) {
TimerProgress.hide();
Keymap.hide();
Funbox.activate("none", null);
if (Misc.roundTo2(TestStats.calculateTestSeconds()) % 1 != 0) {
TestStats.setLastSecondNotRound();
}
if (Config.mode == "zen" || bailout) {
TestStats.removeAfkData();
}
let stats = TestStats.calculateStats();
if (stats === undefined) {
stats = {
@ -1779,7 +1787,6 @@ export function fail() {
input.pushHistory();
corrected.pushHistory();
TestStats.pushKeypressesToHistory();
TestStats.setLastSecondNotRound();
finish(true);
let testSeconds = TestStats.calculateTestSeconds(performance.now());
let afkseconds = TestStats.calculateAfkSeconds();

View file

@ -17,6 +17,8 @@ export let currentKeypress = {
words: [],
};
export let lastKeypress;
// export let errorsPerSecond = [];
// export let currentError = {
// count: 0,
@ -97,7 +99,12 @@ export function setInvalid() {
export function calculateTestSeconds(now) {
if (now === undefined) {
return (end - start) / 1000;
let endAfkSeconds = (end - lastKeypress) / 1000;
if ((Config.mode == "zen" || TestLogic.bailout) && endAfkSeconds < 7) {
return (lastKeypress - start) / 1000;
} else {
return (end - start) / 1000;
}
} else {
return (now - start) / 1000;
}
@ -111,6 +118,10 @@ export function setStart(s) {
start = s;
}
export function updateLastKeypress() {
lastKeypress = performance.now();
}
export function pushToWpmHistory(word) {
wpmHistory.push(word);
}
@ -216,6 +227,14 @@ export function pushMissedWord(word) {
}
}
export function removeAfkData() {
let testSeconds = calculateTestSeconds();
keypressPerSecond.splice(testSeconds);
keypressTimings.duration.array.splice(testSeconds);
keypressTimings.spacing.array.splice(testSeconds);
wpmHistory.splice(testSeconds);
}
function countChars() {
let correctWordChars = 0;
let correctChars = 0;