Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fixes + avg time added (not well calculated) #41

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading