Skip to content

Commit

Permalink
Empezando Estadisticas
Browse files Browse the repository at this point in the history
  • Loading branch information
uo276026 committed Mar 26, 2024
1 parent 0f0fb44 commit aa39cee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
16 changes: 16 additions & 0 deletions userservice/userservice/user-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ const userSchema = new mongoose.Schema({
type: Date,
default: Date.now,
},
correctAnswers: {
type: int,
default: 0,
},
incorrectAnswers: {
type: int,
default: 0,
},
completedGames: {
type: int,
default: 0,
},
averageTime: {
type: int,
default: 0,
}
});

const User = mongoose.model('User', userSchema);
Expand Down
31 changes: 27 additions & 4 deletions webapp/src/components/Pages/Estadisticas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,32 @@
import React, { useState } from 'react';
import { Container, Typography, TextField, Button, Snackbar } from '@mui/material';
import '../Estilos/estadisticas.css';
import axios from 'axios';


const Juego = ({isLogged}) => {

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [correctAnswers, setCorrectAnswers] = useState(0);
const [incorrectAnswers, setIncorrectAnswers] = useState(0);
const [completedGames, setCompletedGames] = useState(0);
const [averageTime, setAverageTime] = useState(0);

const statsUser = async () => {
try {
const response = await axios.post(`${apiEndpoint}/login`, { username, password });
const datos = response.data;
setCorrectAnswers(datos.correctAnswers);
setIncorrectAnswers(datos.incorrectAnswers);
setCompletedGames(datos.completedGames);
setAverageTime(datos.averageTime);
} catch (error) {
setError(error.response.data.error);
}
};

return (
<Container component="main" maxWidth="xs" sx={{ marginTop: 4 }}>
Expand All @@ -13,19 +36,19 @@ const Juego = ({isLogged}) => {
<tbody>
<tr>
<td>Nº Preguntas acertadas: </td>
<td> x </td>
<td> {correctAnswers} </td>
</tr>
<tr>
<td>Nº Preguntas falladas: </td>
<td> x </td>
<td> {incorrectAnswers} </td>
</tr>
<tr>
<td>Nº Juegos completados: </td>
<td> x </td>
<td> {completedGames} </td>
</tr>
<tr>
<td>Tiempo medio por juego: </td>
<td> x </td>
<td> {averageTime} </td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit aa39cee

Please sign in to comment.