From bbbc757c62e05523ff7c13284b5ff2a8cc072419 Mon Sep 17 00:00:00 2001 From: Estebene Date: Tue, 27 Apr 2021 23:35:43 +1200 Subject: [PATCH 1/4] Ignoring Zen Trailing AFK #966 --- src/js/input-controller.js | 2 ++ src/js/test/test-logic.js | 4 ++++ src/js/test/test-stats.js | 20 +++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/js/input-controller.js b/src/js/input-controller.js index a244a30a6..d1b129f7a 100644 --- a/src/js/input-controller.js +++ b/src/js/input-controller.js @@ -232,6 +232,7 @@ function handleSpace(event, isEnter) { TestUI.updateActiveElement(); Funbox.toggleScript(TestLogic.words.getCurrent()); Caret.updatePosition(); + TestStats.updateLastKeypress(); TestStats.incrementKeypressCount(); TestStats.pushKeypressWord(TestLogic.words.currentIndex); // currentKeypress.count++; @@ -288,6 +289,7 @@ 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; diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index 18a67d2c9..b74ce0a40 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -948,6 +948,10 @@ export function finish(difficultyFailed = false) { TimerProgress.hide(); Keymap.hide(); Funbox.activate("none", null); + + if (Config.mode == "zen") { + TestStats.removeZenAfkData(); + } let stats = TestStats.calculateStats(); if (stats === undefined) { stats = { diff --git a/src/js/test/test-stats.js b/src/js/test/test-stats.js index dc0ac2127..72564ea10 100644 --- a/src/js/test/test-stats.js +++ b/src/js/test/test-stats.js @@ -17,6 +17,8 @@ export let currentKeypress = { words: [], }; +export let lastKeypress; + // export let errorsPerSecond = []; // export let currentError = { // count: 0, @@ -97,7 +99,11 @@ export function setInvalid() { export function calculateTestSeconds(now) { if (now === undefined) { - return (end - start) / 1000; + if (Config.mode == "zen") { + return (lastKeypress - start) / 1000; + } else { + return (end - start) / 1000; + } } else { return (now - start) / 1000; } @@ -111,6 +117,10 @@ export function setStart(s) { start = s; } +export function updateLastKeypress() { + lastKeypress = performance.now(); +} + export function pushToWpmHistory(word) { wpmHistory.push(word); } @@ -216,6 +226,14 @@ export function pushMissedWord(word) { } } +export function removeZenAfkData() { + 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; From 75742cccf0a4960c0d952e2835675e2eb38b2872 Mon Sep 17 00:00:00 2001 From: Estebene Date: Thu, 29 Apr 2021 13:02:11 +1200 Subject: [PATCH 2/4] Added AFK ignore for bail out --- src/js/input-controller.js | 2 +- src/js/test/test-logic.js | 4 ++-- src/js/test/test-stats.js | 15 +++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/js/input-controller.js b/src/js/input-controller.js index d1b129f7a..de7afa8c0 100644 --- a/src/js/input-controller.js +++ b/src/js/input-controller.js @@ -232,7 +232,6 @@ function handleSpace(event, isEnter) { TestUI.updateActiveElement(); Funbox.toggleScript(TestLogic.words.getCurrent()); Caret.updatePosition(); - TestStats.updateLastKeypress(); TestStats.incrementKeypressCount(); TestStats.pushKeypressWord(TestLogic.words.currentIndex); // currentKeypress.count++; @@ -611,6 +610,7 @@ function handleAlpha(event) { } } TestStats.incrementKeypressCount(); + TestStats.updateLastKeypress(); TestStats.pushKeypressWord(TestLogic.words.currentIndex); // currentKeypress.count++; // currentKeypress.words.push(TestLogic.words.currentIndex); diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index b74ce0a40..c90bc5916 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -949,8 +949,8 @@ export function finish(difficultyFailed = false) { Keymap.hide(); Funbox.activate("none", null); - if (Config.mode == "zen") { - TestStats.removeZenAfkData(); + if (Config.mode == "zen" || bailout) { + TestStats.removeAfkData(); } let stats = TestStats.calculateStats(); if (stats === undefined) { diff --git a/src/js/test/test-stats.js b/src/js/test/test-stats.js index 72564ea10..aafda7af2 100644 --- a/src/js/test/test-stats.js +++ b/src/js/test/test-stats.js @@ -99,7 +99,7 @@ export function setInvalid() { export function calculateTestSeconds(now) { if (now === undefined) { - if (Config.mode == "zen") { + if (Config.mode == "zen" || TestLogic.bailout) { return (lastKeypress - start) / 1000; } else { return (end - start) / 1000; @@ -226,12 +226,15 @@ export function pushMissedWord(word) { } } -export function removeZenAfkData() { +export function removeAfkData() { let testSeconds = calculateTestSeconds(); - keypressPerSecond.splice(testSeconds); - keypressTimings.duration.array.splice(testSeconds); - keypressTimings.spacing.array.splice(testSeconds); - wpmHistory.splice(testSeconds); + let fullTestSeconds = (end - start) / 1000; + if (fullTestSeconds - testSeconds <= 7) { + keypressPerSecond.splice(testSeconds); + keypressTimings.duration.array.splice(testSeconds); + keypressTimings.spacing.array.splice(testSeconds); + wpmHistory.splice(testSeconds); + } } function countChars() { From dd33f693ae46dcd74572925088b68d02c28a8c00 Mon Sep 17 00:00:00 2001 From: Estebene Date: Fri, 30 Apr 2021 20:32:27 +1200 Subject: [PATCH 3/4] Fixed split stats bug --- src/js/test/test-stats.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/js/test/test-stats.js b/src/js/test/test-stats.js index aafda7af2..26407e272 100644 --- a/src/js/test/test-stats.js +++ b/src/js/test/test-stats.js @@ -99,7 +99,8 @@ export function setInvalid() { export function calculateTestSeconds(now) { if (now === undefined) { - if (Config.mode == "zen" || TestLogic.bailout) { + let endAfkSeconds = (end - lastKeypress) / 1000; + if ((Config.mode == "zen" || TestLogic.bailout) && endAfkSeconds < 7) { return (lastKeypress - start) / 1000; } else { return (end - start) / 1000; @@ -228,13 +229,10 @@ export function pushMissedWord(word) { export function removeAfkData() { let testSeconds = calculateTestSeconds(); - let fullTestSeconds = (end - start) / 1000; - if (fullTestSeconds - testSeconds <= 7) { - keypressPerSecond.splice(testSeconds); - keypressTimings.duration.array.splice(testSeconds); - keypressTimings.spacing.array.splice(testSeconds); - wpmHistory.splice(testSeconds); - } + keypressPerSecond.splice(testSeconds); + keypressTimings.duration.array.splice(testSeconds); + keypressTimings.spacing.array.splice(testSeconds); + wpmHistory.splice(testSeconds); } function countChars() { From b28fe166e54142874e88707b751e76670c52638c Mon Sep 17 00:00:00 2001 From: Estebene Date: Sat, 1 May 2021 21:59:45 +1200 Subject: [PATCH 4/4] Fixed Decimal Bug --- src/js/input-controller.js | 2 -- src/js/test/test-logic.js | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/js/input-controller.js b/src/js/input-controller.js index de7afa8c0..0209c580e 100644 --- a/src/js/input-controller.js +++ b/src/js/input-controller.js @@ -294,7 +294,6 @@ function handleSpace(event, isEnter) { return; } else if (TestLogic.words.currentIndex == TestLogic.words.length) { //submitted last word that is incorrect - TestStats.setLastSecondNotRound(); TestLogic.finish(); return; } @@ -674,7 +673,6 @@ function handleAlpha(event) { TestLogic.input.pushHistory(); TestLogic.corrected.pushHistory(); - TestStats.setLastSecondNotRound(); TestLogic.finish(); } } diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index c90bc5916..d450d16ae 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -949,6 +949,10 @@ export function finish(difficultyFailed = false) { Keymap.hide(); Funbox.activate("none", null); + if (Misc.roundTo2(TestStats.calculateTestSeconds()) % 1 != 0) { + TestStats.setLastSecondNotRound(); + } + if (Config.mode == "zen" || bailout) { TestStats.removeAfkData(); } @@ -1783,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();