From 7b96d8cba7cdb1123d65c7eb06109d16adef1673 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Wed, 19 May 2021 17:07:41 -0400 Subject: [PATCH] fixed global stats --- server.js | 19 ++++++++++--------- src/js/account.js | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/server.js b/server.js index f0074bc8d..d110e3c7a 100644 --- a/server.js +++ b/server.js @@ -384,6 +384,7 @@ async function stripAndSave(uid, obj) { } async function getIncrementedTypingStats(userData, resultObj) { + let userGlobalStats = userData.globalStats; try { let newStarted; let newCompleted; @@ -403,20 +404,20 @@ async function getIncrementedTypingStats(userData, resultObj) { )}` ); - if (userData.startedTests === undefined) { + if (userGlobalStats.started === undefined) { newStarted = resultObj.restartCount + 1; } else { - newStarted = userData.startedTests + resultObj.restartCount + 1; + newStarted = userGlobalStats.started + resultObj.restartCount + 1; } - if (userData.completedTests === undefined) { + if (userGlobalStats.completed === undefined) { newCompleted = 1; } else { - newCompleted = userData.completedTests + 1; + newCompleted = userGlobalStats.completed + 1; } - if (userData.timeTyping === undefined) { + if (userGlobalStats.time === undefined) { newTime = tt; } else { - newTime = userData.timeTyping + tt; + newTime = userGlobalStats.time + tt; } // db.collection("users") // .doc(uid) @@ -428,9 +429,9 @@ async function getIncrementedTypingStats(userData, resultObj) { incrementPublicTypingStats(resultObj.restartCount + 1, 1, tt); return { - newStarted: newStarted, - newCompleted: newCompleted, - newTime: roundTo2(newTime), + started: newStarted, + completed: newCompleted, + time: roundTo2(newTime), }; } catch (e) { console.error(`Error while incrementing stats for user ${uid}: ${e}`); diff --git a/src/js/account.js b/src/js/account.js index f944959da..605fb622a 100644 --- a/src/js/account.js +++ b/src/js/account.js @@ -726,8 +726,8 @@ export function update() { ); } $(".pageAccount .testsStarted .val").text(`${testCount + testRestarts}`); - console.log(testCount); - console.log(testRestarts); + console.log("Test count: " + testCount); + console.log("Test restarts: " + testRestarts); $(".pageAccount .testsCompleted .val").text( `${testCount}(${Math.floor( (testCount / (testCount + testRestarts)) * 100