another timer update

This commit is contained in:
Jack 2021-11-12 14:42:59 +00:00
parent 324b7f8570
commit a055e39278
3 changed files with 25 additions and 1 deletions

View file

@ -24,3 +24,5 @@ global.stats = TestStats.getStats;
global.replay = Replay.getReplayExport;
global.enableTimerDebug = TestTimer.enableTimerDebug;
global.getTimerStats = TestTimer.getTimerStats;

View file

@ -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

View file

@ -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;