mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-17 11:06:17 +08:00
fixed global stats
This commit is contained in:
parent
5417dd9f20
commit
7b96d8cba7
2 changed files with 12 additions and 11 deletions
19
server.js
19
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}`);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue