From 9829665c624270d22a36a91f61f0d12d602e4403 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 26 Jul 2022 13:06:15 +0200 Subject: [PATCH] added wpm calculation debug --- frontend/src/ts/index.ts | 2 ++ frontend/src/ts/test/test-stats.ts | 25 +++++++++++++++++++++++-- frontend/src/ts/types/types.d.ts | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/frontend/src/ts/index.ts b/frontend/src/ts/index.ts index d270391fd..ddc532a02 100644 --- a/frontend/src/ts/index.ts +++ b/frontend/src/ts/index.ts @@ -58,3 +58,5 @@ extendedGlobal.toggleUnsmoothedRaw = Result.toggleUnsmoothedRaw; extendedGlobal.enableSpacingDebug = TestInput.enableSpacingDebug; extendedGlobal.egVideoListener = egVideoListener; + +extendedGlobal.wpmCalculationDebug = TestStats.wpmCalculationDebug; diff --git a/frontend/src/ts/test/test-stats.ts b/frontend/src/ts/test/test-stats.ts index 3270bad34..1c7b3e4f3 100644 --- a/frontend/src/ts/test/test-stats.ts +++ b/frontend/src/ts/test/test-stats.ts @@ -99,6 +99,12 @@ export function setLastResult( lastResult = result; } +let wpmCalcDebug = false; +export function wpmCalculationDebug(): void { + console.log("wpm calculation debug enabled"); + wpmCalcDebug = true; +} + export function getStats(): DebugStats { const ret: DebugStats = { lastResult, @@ -408,10 +414,16 @@ function countChars(): CharCount { export function calculateStats(): Stats { let testSeconds = calculateTestSeconds(); - // console.log((end2 - start2) / 1000); - // console.log(testSeconds); + if (wpmCalcDebug) { + console.log("date based time", (end2 - start2) / 1000); + console.log("performance.now based time", testSeconds); + } if (Config.mode != "custom") { testSeconds = Misc.roundTo2(testSeconds); + if (wpmCalcDebug) { + console.log("mode is not custom - wounding"); + console.log("new time", testSeconds); + } } const chars = countChars(); const wpm = Misc.roundTo2( @@ -425,6 +437,15 @@ export function calculateStats(): Stats { (60 / testSeconds)) / 5 ); + if (wpmCalcDebug) { + console.log("chars", chars); + console.log( + "wpm", + ((chars.correctWordChars + chars.correctSpaces) * (60 / testSeconds)) / 5 + ); + console.log("wpm rounded to 2", wpm); + console.log("wpmraw", wpmraw); + } const acc = Misc.roundTo2(calculateAccuracy()); return { wpm: isNaN(wpm) ? 0 : wpm, diff --git a/frontend/src/ts/types/types.d.ts b/frontend/src/ts/types/types.d.ts index 79df91eba..6c7d52598 100644 --- a/frontend/src/ts/types/types.d.ts +++ b/frontend/src/ts/types/types.d.ts @@ -584,6 +584,7 @@ declare namespace MonkeyTypes { enableSpacingDebug(): void; noGoogleNoMo(): void; egVideoListener(options: Record): void; + wpmCalculationDebug(): void; } interface GithubRelease {