Skip to content

Commit

Permalink
Merge pull request #41 from Arquisoft/fixing-stats
Browse files Browse the repository at this point in the history
More fixes +  avg time added (not well calculated)
  • Loading branch information
iyanfdezz authored Mar 4, 2024
2 parents f2f8259 + e2a88f4 commit 2c36795
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
15 changes: 0 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ services:
- "8003:8003"
networks:
- mynetwork

statsservice:
container_name: statsservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/statsservice:latest
profiles: ["dev", "prod"]
build: ./statsservice
depends_on:
- mongodb
ports:
- "8004:8004"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

statsservice:
container_name: statsservice-${teamname:-defaultASW}
Expand Down Expand Up @@ -90,7 +76,6 @@ services:
- userservice
- authservice
- questionservice
- statsservice
ports:
- "8000:8000"
networks:
Expand Down
8 changes: 6 additions & 2 deletions users/userservice/stats-getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ class StatsForUser {
var totalPoints = 0;
var totalCorrectQuestions = 0;
var totalIncorrectQuestions = 0;
var avgTime=0;
var totalTime=0;

for (const partida of partidas){
totalPoints += partida.points;
totalCorrectQuestions += partida.correctAnswers;
totalIncorrectQuestions += partida.incorrectAnswers;
totalTime+=partida.avgTime;
}

var avgPoints = nGamesPlayed > 0 ?
Expand All @@ -31,14 +32,17 @@ class StatsForUser {
var ratioCorrectToIncorrect = totalIncorrectQuestions !== 0 ?
totalCorrectQuestions / totalIncorrectQuestions : totalCorrectQuestions;

var avgTime = nGamesPlayed > 0 ? totalTime / nGamesPlayed : 0;

var statsJSON = {
username: username,
nGamesPlayed: nGamesPlayed,
avgPoints: avgPoints,
totalPoints: totalPoints,
totalCorrectQuestions: totalCorrectQuestions,
totalIncorrectQuestions: totalIncorrectQuestions,
ratioCorrectToIncorrect: ratioCorrectToIncorrect
ratioCorrectToIncorrect: ratioCorrectToIncorrect,
avgTime: avgTime
};

return statsJSON;
Expand Down
1 change: 1 addition & 0 deletions webapp/src/pages/Stats/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const Stats = () => {
<pre> <strong>Preguntas Correctas Totales: </strong>{stats.totalCorrectQuestions}</pre>
<pre> <strong>Preguntas Incorrectas Totales: </strong>{stats.totalIncorrectQuestions}</pre>
<pre> <strong>Ratio Correctas/Incorrectas: </strong>{stats.ratioCorrectToIncorrect}</pre>
<pre> <strong>Tiempo por pregunta (s): </strong>{stats.avgTime}</pre>
<hr></hr>
</div>
)}
Expand Down

0 comments on commit 2c36795

Please sign in to comment.