Skip to content

Commit

Permalink
Now deployment works
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Feb 21, 2024
1 parent 8ef17ec commit 26e3563
Show file tree
Hide file tree
Showing 7 changed files with 803 additions and 80 deletions.
38 changes: 38 additions & 0 deletions stats/model/partidas.json
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
}
]
52 changes: 52 additions & 0 deletions stats/model/stats-getter.js
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;

Loading

0 comments on commit 26e3563

Please sign in to comment.