From a055e39278f9fb5afd45aad3d6ec1fb867d2422a Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 12 Nov 2021 14:42:59 +0000 Subject: [PATCH] another timer update --- src/js/exports.js | 2 ++ src/js/test/test-stats.js | 8 +++++++- src/js/test/test-timer.js | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/js/exports.js b/src/js/exports.js index c4fd7b04b..ef4379197 100644 --- a/src/js/exports.js +++ b/src/js/exports.js @@ -24,3 +24,5 @@ global.stats = TestStats.getStats; global.replay = Replay.getReplayExport; global.enableTimerDebug = TestTimer.enableTimerDebug; + +global.getTimerStats = TestTimer.getTimerStats; diff --git a/src/js/test/test-stats.js b/src/js/test/test-stats.js index 56667eab1..72f10d510 100644 --- a/src/js/test/test-stats.js +++ b/src/js/test/test-stats.js @@ -5,6 +5,7 @@ import * as TestStats from "./test-stats"; export let invalid = false; export let start, end; +export let start2, end2; export let wpmHistory = []; export let rawHistory = []; export let burstHistory = []; @@ -157,10 +158,12 @@ export function calculateTestSeconds(now) { export function setEnd(e) { end = e; + end2 = Date.now(); } export function setStart(s) { start = s; + start2 = Date.now(); } export function updateLastKeypress() { @@ -417,8 +420,11 @@ export function calculateStats() { if (Config.mode == "custom") { testSeconds = TestStats.calculateTestSeconds(); } else { - testSeconds = Misc.roundTo2(TestStats.calculateTestSeconds()); + testSeconds = TestStats.calculateTestSeconds(); } + console.log((TestStats.end2 - TestStats.start2) / 1000); + console.log(testSeconds); + testSeconds = Misc.roundTo2(testSeconds); let chars = countChars(); let wpm = Misc.roundTo2( ((chars.correctWordChars + chars.correctSpaces) * (60 / testSeconds)) / 5 diff --git a/src/js/test/test-timer.js b/src/js/test/test-timer.js index c754f3d9a..ed11641fb 100644 --- a/src/js/test/test-timer.js +++ b/src/js/test/test-timer.js @@ -166,6 +166,12 @@ function checkIfTimeIsUp() { // --------------------------------------- +let timerStats = []; + +export function getTimerStats() { + return timerStats; +} + function calc_drift(arr) { // Calculate drift correction. @@ -203,6 +209,10 @@ async function timerStep() { } export function start() { + drift_history = []; + drift_correction = 0; + timerStats = []; + function step() { let dt = Date.now() - expected; //delta time @@ -242,6 +252,12 @@ export function start() { let delay = Math.max(0, interval - dt - drift_correction); if (timerDebug) console.log(`deltatime ${dt}ms`); if (timerDebug) console.log(`delay ${delay}ms`); + timerStats.push({ + timestamp: Date.now(), + delta: dt, + correction: drift_correction, + actualDelay: delay, + }); setTimeout(step, delay); } expected = Date.now() + interval;