forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Develop-Participation' into Develop
- Loading branch information
Showing
8 changed files
with
209 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,4 @@ | |
"mongodb-memory-server": "^9.1.6", | ||
"supertest": "^6.3.4" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
{ | ||
<<<<<<< HEAD | ||
"dependencies": { | ||
"chart.js": "^4.4.1", | ||
"react-chartjs-2": "^5.2.0" | ||
} | ||
} | ||
======= | ||
"devDependencies": { | ||
"serve": "^14.2.1" | ||
} | ||
} | ||
} | ||
>>>>>>> origin/Develop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, { useState } from 'react'; | ||
import './App.css'; | ||
import { Game } from './components/Game'; | ||
import { Participation } from './components/Participation'; | ||
|
||
function App() { | ||
const [menuState, setMenuState] = useState(0); | ||
|
||
const goTo = (parameter) => { | ||
setMenuState(parameter); | ||
}; | ||
|
||
return ( | ||
<> | ||
{menuState === 0 && <Game goTo={(x) => goTo(x)} />} | ||
{menuState === 1 && <Participation goTo={(x) => goTo(x)} />} | ||
</> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,60 @@ | ||
import React from 'react'; | ||
//import Chart from "chart.js/auto"; | ||
import React, { useState, useEffect } from 'react'; | ||
import { Bar } from 'react-chartjs-2'; | ||
import axios from 'axios'; | ||
|
||
//const mongoose = require('mongoose'); | ||
export const Participation = ({ userId, goTo }) => { | ||
const [participationData, setParticipationData] = useState(null); | ||
|
||
// Número de juegos, preguntas acertadas/falladas, tiempos | ||
// Esquema de preguntas -> question, correct, incorrects[] | ||
// Esquema de Juegos -> usuario, preguntas[], respuestas[], tiempo | ||
useEffect(() => { | ||
// Realizar la solicitud al servidor para obtener los datos de participación | ||
const fetchData = async () => { | ||
try { | ||
const response = await axios.get(`http://localhost:8005/getParticipation/${userId}`); | ||
setParticipationData(response.data); | ||
} catch (error) { | ||
console.error('Error al obtener los datos de participación:', error); | ||
} | ||
}; | ||
|
||
export const Participation = () => { | ||
return ( | ||
<div> | ||
<h1>Participation</h1> | ||
</div> | ||
); | ||
fetchData(); | ||
}, [userId]); | ||
|
||
//Gráfica | ||
const data = { | ||
labels: ['Preguntas Acertadas', 'Preguntas Falladas'], | ||
datasets: [ | ||
{ | ||
label: 'Número de preguntas', | ||
data: [participationData?.correctAnswers || 0, participationData?.incorrectAnswers || 0], | ||
backgroundColor: ['green', 'red'], | ||
}, | ||
], | ||
}; | ||
|
||
const options = { | ||
scales: { | ||
y: { | ||
beginAtZero: true, | ||
max: Math.max(participationData?.correctAnswers || 0, participationData?.incorrectAnswers || 0) + 1, | ||
}, | ||
}, | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>Participation</h1> | ||
{participationData ? ( | ||
<div> | ||
<p>Número de partidas jugadas: {participationData.totalGames}</p> | ||
<p>Preguntas acertadas: {participationData.correctAnswers}</p> | ||
<p>Preguntas falladas: {participationData.incorrectAnswers}</p> | ||
<p>Tiempo total jugando: {participationData.totalTime} segundos</p> | ||
<Bar data={data} options={options} /> | ||
</div> | ||
) : ( | ||
<p>Cargando datos de participación...</p> | ||
)} | ||
<button onClick={() => goTo(0)}>Menú</button> | ||
</div> | ||
); | ||
}; |