forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
803 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[ | ||
{ | ||
"username": "vagrant", | ||
"points": 200, | ||
"correctQuestions": 7, | ||
"incorrectQuestions": 3 | ||
}, | ||
{ | ||
"username": "vagrant", | ||
"points": 400, | ||
"correctQuestions": 16, | ||
"incorrectQuestions": 4 | ||
}, | ||
{ | ||
"username": "jose123", | ||
"points": 200, | ||
"correctQuestions": 8, | ||
"incorrectQuestions": 2 | ||
}, | ||
{ | ||
"username": "vagrant", | ||
"points": 1000, | ||
"correctQuestions": 40, | ||
"incorrectQuestions": 10 | ||
}, | ||
{ | ||
"username": "rober200", | ||
"points": 100, | ||
"correctQuestions": 3, | ||
"incorrectQuestions": 2 | ||
}, | ||
{ | ||
"username": "jose123", | ||
"points": 40, | ||
"correctQuestions": 1, | ||
"incorrectQuestions": 1 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const fs = require('fs'); | ||
|
||
class StatsForUser { | ||
|
||
getStatsForUser(username){ | ||
// Leer el archivo JSON de partidas | ||
const data = fs.readFileSync("./model/partidas.json"); | ||
const partidas = JSON.parse(data); | ||
|
||
let nGamesPlayed = 0; | ||
let totalPoints = 0; | ||
let totalCorrectQuestions = 0; | ||
let totalIncorrectQuestions = 0; | ||
|
||
// Calcular las estadísticas para el usuario | ||
for (const partida of partidas){ | ||
if (partida.username === this.username){ | ||
nGamesPlayed++; | ||
totalPoints += partida.points; | ||
totalCorrectQuestions += partida.correctQuestions; | ||
totalIncorrectQuestions += partida.incorrectQuestions; | ||
} | ||
} | ||
|
||
// Calcular el promedio de puntos por juego | ||
const avgPoints = nGamesPlayed > 0 ? totalPoints / nGamesPlayed : 0; | ||
|
||
// Calcular el ratio de preguntas acertadas/falladas | ||
const ratioCorrectToIncorrect = totalIncorrectQuestions !== 0 ? totalCorrectQuestions / totalIncorrectQuestions : totalCorrectQuestions; | ||
|
||
// Construir el objeto JSON con las estadísticas | ||
const statsJSON = { | ||
username: this.username, | ||
nGamesPlayed: nGamesPlayed, | ||
avgPoints: avgPoints, | ||
totalPoints: totalPoints, | ||
totalCorrectQuestions: totalCorrectQuestions, | ||
totalIncorrectQuestions: totalIncorrectQuestions, | ||
ratioCorrectToIncorrect: ratioCorrectToIncorrect | ||
}; | ||
|
||
return statsJSON; | ||
} | ||
|
||
existsUser(username){ | ||
//TODO | ||
return true; | ||
} | ||
} | ||
|
||
module.exports = StatsForUser; | ||
|
Oops, something went wrong.