Skip to content

Commit

Permalink
Fix in gameSaving
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Apr 27, 2024
1 parent 3a2b154 commit 219f815
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions statsservice/stats-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ app.post("/saveGame", async (req, res) => {
});
await stats.save();
} else {
let ratio = 0;
if ((stats.totalIncorrectQuestions +
stats.totalCorrectQuestions +
gameData.incorrectAnswers +
gameData.correctAnswers) > 0) {
ratio =
((stats.totalCorrectQuestions + gameData.correctAnswers) /
(stats.totalIncorrectQuestions +
stats.totalCorrectQuestions +
gameData.incorrectAnswers +
gameData.correctAnswers)) *
100
}
await Stats.updateOne(
{ username: username, gamemode: gamemode },
{
Expand All @@ -83,13 +96,7 @@ app.post("/saveGame", async (req, res) => {
avgPoints:
(stats.avgPoints * stats.nGamesPlayed + gameData.points) /
(stats.nGamesPlayed + 1),
ratioCorrect:
((stats.totalCorrectQuestions + gameData.correctAnswers) /
(stats.totalIncorrectQuestions +
stats.totalCorrectQuestions +
gameData.incorrectAnswers +
gameData.correctAnswers)) *
100,
ratioCorrect: ratio,
avgTime:
(stats.avgTime * stats.nGamesPlayed + gameData.avgTime) /
(stats.nGamesPlayed + 1),
Expand Down

0 comments on commit 219f815

Please sign in to comment.