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

Cancio general fixes #46

Merged
merged 3 commits into from
Mar 5, 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
2 changes: 2 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ app.use(express.json());
const metricsMiddleware = promBundle({includeMethod: true});
app.use(metricsMiddleware);

app.set("json spaces", 40);

// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'OK' });
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Bateria from './pages/Bateria/Bateria.js';
import WrongRoute from './pages/WrongRoute/WrongRoute.js';
import Stats from './pages/Stats/Stats.js';
import './App.css';
import {BrowserRouter, Routes, Route, Navigate} from "react-router-dom";
import {BrowserRouter, Routes, Route} from "react-router-dom";
import { ProtectedRoute } from './routers/ProtectedRoute.js';

function App() {
Expand Down
13 changes: 3 additions & 10 deletions webapp/src/pages/Clasico/Clasico.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@ const JuegoPreguntas = () => {
.then((response) => response.json())
.then((data) => {
setPreguntas(data);
//setIsLoading(false);
setPreguntaActual(data[0]);
setIsLoading(false);
})
.catch((error) => {
console.error('Error al obtener las preguntas:', error);
setIsLoading(false);
});
}, []);

useEffect(() => {
if (preguntas && preguntas.length > 0) {
setPreguntaActual(preguntas[0]);
setIsLoading(false);
}
}, [preguntas]);

useEffect(() => {
if (tiempoRestante === 0) {
setPreguntaTerminada(true);
Expand Down Expand Up @@ -96,12 +90,11 @@ const JuegoPreguntas = () => {

setTiempoTotal(tiempoTotal+10-tiempoRestante);


setRespuestaSeleccionada(null);
setTiempoRestante(10);
if (indicePregunta + 1 < preguntas.length) {
setIndicePregunta(indicePregunta + 1);
setPreguntaActual(preguntas[indicePregunta]);
setPreguntaActual(preguntas[indicePregunta + 1]);
} else {

try {
Expand Down
6 changes: 0 additions & 6 deletions webapp/src/pages/Stats/Stats.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,4 @@ input, button, a{
color: #6b456c;
font-family: "Times New Roman", serif;

}

body {
background-color: #ffffe5;
font-family: "Times New Roman", serif;

}
179 changes: 107 additions & 72 deletions webapp/src/pages/Stats/Stats.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import Nav from '../../components/Nav/Nav.js';
import Footer from '../../components/Footer/Footer.js';
import './Stats.css';

import React, { useState, useEffect } from "react";
import axios from "axios";
import Nav from "../../components/Nav/Nav.js";
import Footer from "../../components/Footer/Footer.js";
import "./Stats.css";

const Stats = () => {
const [username, setUsername] = useState(localStorage.username);
const [stats, setStats] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);


const fetchStats = () => {
setIsLoading(true);
fetch(`http://localhost:8001/getstats?user=${username}`)
Expand All @@ -21,97 +19,134 @@ const Stats = () => {
setIsLoading(false);
})
.catch((error) => {
console.error('Error al obtener las preguntas:', error);
setError(error.message || 'Ha ocurrido un error al obtener las estadísticas');
console.error("Error al obtener las preguntas:", error);
setError(
error.message || "Ha ocurrido un error al obtener las estadísticas"
);
setIsLoading(false);
});
};

useEffect(() => {
fetch(`http://localhost:8001/getstats?user=${username}`)
.then((response) => response.json())
.then((data) => {
setStats(data);
setIsLoading(false);
})
.catch((error) => {
console.error('Error al obtener las preguntas:', error);
setIsLoading(false);
});
const delayDebounceFn = setTimeout(() => {
fetch(`http://localhost:8001/getstats?user=${username}`)
.then((response) => response.json())
.then((data) => {
setStats(data);
setIsLoading(false);
})
.catch((error) => {
console.error("Error al obtener las preguntas:", error);
setIsLoading(false);
});
}, 2000);
return () => clearTimeout(delayDebounceFn);
}, [username]);

const handleUsernameChange = (event) => {
setUsername(event.target.value);
};

const handleSearch = () => {
if (username.trim() !== '') {
fetchStats();
}
};

if (isLoading) {
return <div>
<h2> Cargando ... </h2>
<p>Se está consultando su búsqueda, espere unos instantes.</p>
</div>
return (
<div>
<h2> Cargando ... </h2>
<p>Se está consultando su búsqueda, espere unos instantes.</p>
</div>
);
}

if (error) {
return <>
return (
<>
<Nav />
<div>
<label htmlFor="usernameInput">Nombre de Usuario: </label>
<input
type="text"
id="usernameInput"
value={username}
onChange={handleUsernameChange}
/>
<button onClick={handleSearch}>Buscar</button>
<h2>Error: {error}</h2>
<p>Por favor compruebe si los valores del formulario son correctos e inténtelo de nuevo</p>
</div>
<Footer />
</>
<label htmlFor="usernameInput">Nombre de Usuario: </label>
<input
type="text"
id="usernameInput"
value={username}
onChange={handleUsernameChange}
/>
<h2>Error: {error}</h2>
<p>
Por favor compruebe si los valores del formulario son correctos e
inténtelo de nuevo
</p>
</div>
<Footer />
</>
);
}

return (
<>
<Nav />
<div>
<h2>Estadísticas de Usuario</h2>
<label htmlFor="usernameInput"> <strong>Nombre de Usuario: </strong></label>
<input
type="text"
id="usernameInput"
value={username}
onChange={handleUsernameChange}
/>
<button onClick={handleSearch}>Buscar</button>
{stats === null && !isLoading && (
<Nav />
<div>
<h2>Estadísticas de Usuario</h2>
<label htmlFor="usernameInput">
{" "}
<strong>Nombre de Usuario: </strong>
</label>
<input
type="text"
id="usernameInput"
value={username}
onChange={handleUsernameChange}
/>
{stats === null && !isLoading && (
<div>
<p>El usuario no ha jugado ninguna partida.</p>
</div>
)}
{stats && (
<div>
<hr></hr>
<p><strong>Usuario: </strong>{stats.username}</p>
<pre> <strong>Juegos Jugados: </strong>{stats.nGamesPlayed}</pre>
<pre> <strong>Promedio de Puntos: </strong>{stats.avgPoints}</pre>
<pre> <strong>Puntos Totales: </strong>{stats.totalPoints}</pre>
<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>
)}
</div>
<Footer />
{stats && (
<div>
<hr></hr>
<p>
<strong>Usuario: </strong>
{stats.username}
</p>
<pre>
{" "}
<strong>Juegos Jugados: </strong>
{stats.nGamesPlayed}
</pre>
<pre>
{" "}
<strong>Promedio de Puntos: </strong>
{stats.avgPoints}
</pre>
<pre>
{" "}
<strong>Puntos Totales: </strong>
{stats.totalPoints}
</pre>
<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>
)}
</div>
<Footer />
</>

);
};

Expand Down
Loading