From 69ab517114dd857bfbc2b17f4c1ae4dab6c512c2 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 14 Apr 2024 01:18:10 +0200 Subject: [PATCH 1/8] =?UTF-8?q?A=C3=B1adidos=20servicios=20a=20Sonar=20y?= =?UTF-8?q?=20los=20endpoints=20a=20OpenAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatewayservice/openapi.yaml | 271 ++++++++++++++++++++++++++++++++++++ sonar-project.properties | 2 +- 2 files changed, 272 insertions(+), 1 deletion(-) diff --git a/gatewayservice/openapi.yaml b/gatewayservice/openapi.yaml index 8075ba4b..76676322 100644 --- a/gatewayservice/openapi.yaml +++ b/gatewayservice/openapi.yaml @@ -131,6 +131,277 @@ paths: type: string description: Shows the error info.. example: Invalid credentials + '500': + description: Internal server error. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error information. + example: Internal Server Error + /generateQuestion: + get: + summary: Generate a question. + operationId: generateQuestion + responses: + '200': + description: Generation successful. Returns the question, the options, the correct option, the image (if neccessary) and the question id + content: + application/json: + schema: + type: object + properties: + responseQuestion: + type: string + description: Question. + example: ¿Cual es la capital de España? + responseOptions: + type: array + description: Options of the question. + example: [Barcelona, Madrid, Oviedo, Valladolid] + responseCorrectOption: + type: string + description: Correct option. + example: Madrid + responseImage: + type: URL + description: URL of the image of the question if neccessary. + example: https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/Joe_Biden_presidential_portrait.jpg/220px-Joe_Biden_presidential_portrait.jpg + '400': + description: Error during the question generator. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Shows the error info. + example: numberOfQuestions is not defined + '500': + description: Internal server error. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error information. + example: Internal Server Error + /updateQuestion: + get: + summary: Update a question. + operationId: updateQuestion + parameters: + time: + in: query + description: Time of the question. + example: 10 + required: true + schema: + type: string + correct: + in: query + description: If the question was answered correctly. + example: true + required: true + schema: + type: boolean + responses: + '200': + description: Update successful. Returns a message ans the updated question + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: A message indicating the operation was succesful. + example: Tiempo de pregunta actualizado exitosamente + updatedQuestion: + type: object + description: The question updated. + example: {enunciado: ¿Cual es la capital de España?, respuesta_correcta: Madrid, respuesta_falsa1: Barcelona, respuesta_falsa2: Oviedo, respuesta_falsa3: Valladolid, + time: 10, correct: true} + '404': + description: Cannot find the question. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Shows the error info. + example: La pregunta no fue encontrada + '400': + description: Error when update the question + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Shows the error info. + example: Cannot read property 'time' of undefined + '500': + description: Internal server error. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error information. + example: Internal Server Error + /saveGameHistory: + post: + summary: Save the game history. + operationId: saveGameHistory + responses: + '200': + description: Succesful saving the game history + content: + application/json: + schema: + type: object + properties: + success: + type: boolean + description: Indicates if the operation has been succesful. + example: true + '400': + description: Error when saving the game history + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Shows the error info. + example: Error al guardar el historial del juego + '500': + description: Internal server error. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error information. + example: Internal Server Error + /configureGame: + post: + summary: Configure the game. + operationId: configureGame + responses: + '200': + description: Succesful configure the game number of questions + content: + application/json: + schema: + type: object + properties: + maxQuestions: + type: int + description: The new number of questions of the question. + example: 10 + '400': + description: Error when configuring the game + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Shows the error info. + example: Cannot read property 'valueQuestion' of undefined + '500': + description: Internal server error. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error information. + example: Internal Server Error + /gamehistory: + get: + summary: Charge the game history. + operationId: gamehistory + parameters: + username: + in: query + description: User which game history we want to recover. + example: Pepito + required: true + schema: + type: string + responses: + '200': + description: Succesful charge the game history + '400': + description: Error when charging the game history + '500': + description: Internal server error. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error information. + example: Internal Server Error + /topUsers: + get: + summary: Charge the top users. + operationId: topUsers + responses: + '200': + description: Succesful charge the top users + '400': + description: Error when charging the top users + '500': + description: Internal server error. + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error information. + example: Internal Server Error + /endgamestats: + get: + summary: Charge the end game statistics. + operationId: endgamestats + parameters: + username: + in: query + description: User which game statistics we want to charge. + example: Pepito + required: true + schema: + type: string + responses: + '200': + description: Succesful charge the end game statitics + '400': + description: Error when charging the end game statistics '500': description: Internal server error. content: diff --git a/sonar-project.properties b/sonar-project.properties index 9080fe9d..d6bda32c 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -11,7 +11,7 @@ sonar.language=js sonar.projectName=wiq_es2c sonar.coverage.exclusions=**/*.test.js -sonar.sources=webapp/src/components,users/authservice,users/userservice,gatewayservice +sonar.sources=webapp/src/components,users/authservice,users/userservice,gatewayservice,gamehistoryservice,questiongenerator sonar.sourceEncoding=UTF-8 sonar.exclusions=node_modules/** sonar.javascript.lcov.reportPaths=**/coverage/lcov.info From db77892fc52671b6e27646d72d1bf5d994382edf Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 14 Apr 2024 19:27:57 +0200 Subject: [PATCH 2/8] =?UTF-8?q?A=C3=B1adidas=20preguntas=20por=20tematicas?= =?UTF-8?q?=20al=20generador=20de=20preguntas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- questiongenerator/image_questions.js | 86 ++++++++++++++----- questiongenerator/text_questions.js | 122 ++++++++++++++++++--------- 2 files changed, 146 insertions(+), 62 deletions(-) diff --git a/questiongenerator/image_questions.js b/questiongenerator/image_questions.js index 0e2b558c..ff131639 100644 --- a/questiongenerator/image_questions.js +++ b/questiongenerator/image_questions.js @@ -1,25 +1,69 @@ // Todas las consultas -var queries = - // pregunta = Imagen de un presidente de EE.UU., opcion = Nombres de presidentes de EE.UU. - [`SELECT ?option ?optionLabel ?imageLabel - WHERE { - ?option wdt:P31 wd:Q5; - wdt:P39 wd:Q11696; - wdt:P18 ?imageLabel. - SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } - } - `, - // pregunta = Imagen de un país, opcion = Pais - `SELECT DISTINCT ?option ?optionLabel ?imageLabel - WHERE { - ?option wdt:P31 wd:Q6256; - rdfs:label ?optionLabel; - - OPTIONAL { ?option wdt:P18 ?imageLabel. } - FILTER(lang(?optionLabel) = "es") - FILTER EXISTS { ?option wdt:P18 ?imageLabel } - } - `]; +var queries = {}; + +queries['Geografia'] = + [ + // pregunta = Imagen de un país, opcion = Pais + ` + SELECT DISTINCT ?option ?optionLabel ?imageLabel + WHERE { + ?option wdt:P31 wd:Q6256; + rdfs:label ?optionLabel; + + OPTIONAL { ?option wdt:P18 ?imageLabel. } + FILTER(lang(?optionLabel) = "es") + FILTER EXISTS { ?option wdt:P18 ?imageLabel } + } + ` + ]; + +queries['Cultura'] = + [ + // pregunta = cuadro, opcion -> nombre + ` + SELECT ?optionLabel ?imageLabel + WHERE { + ?option wdt:P31 wd:Q3305213. + ?option wdt:P18 ?imageLabel. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + LIMIT 200 + ` + ]; + +queries['Personajes'] = + [ + // pregunta = imagen pintor, opcion = nombre pintor + ` + SELECT ?optionLabel ?imageLabel + WHERE { + ?option wdt:P106 wd:Q1028181; + wdt:P18 ?imageLabel. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + LIMIT 200 + `, + // pregunta = imagen futbolista, opcion = nombre futbolista + ` + SELECT ?optionLabel ?imageLabel + WHERE { + ?option wdt:P106 wd:Q937857; + wdt:P18 ?imageLabel. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + LIMIT 200 + `, + // pregunta = imagen cantante, opcion = nombre cantante + ` + SELECT ?optionLabel ?imageLabel + WHERE { + ?option wdt:P106/wdt:P279* wd:Q177220; + wdt:P18 ?imageLabel. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + LIMIT 200 + ` + ]; // Todas las preguntas, en el mismo orden que las consultas var questions = ["¿Que presidente de EE.UU es el que se muestra en la imagen?", diff --git a/questiongenerator/text_questions.js b/questiongenerator/text_questions.js index 3e353113..550a87e5 100644 --- a/questiongenerator/text_questions.js +++ b/questiongenerator/text_questions.js @@ -1,45 +1,85 @@ // Todas las consultas -var queries = - // pregunta = Pais, opcion = capitales - [`SELECT ?question ?questionLabel ?option ?optionLabel - WHERE { - ?question wdt:P31 wd:Q6256; wdt:P36 ?option. - SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } - } - LIMIT 200 - `, - // pregunta = Club de futbol, opcion = estadio - ` - SELECT ?question ?questionLabel ?option ?optionLabel - WHERE { - ?question wdt:P31 wd:Q476028. - ?question wdt:P115 ?option. - ?question wdt:P17 wd:Q29. - SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } - } - LIMIT 100 - `, - // Pregunta = Numero en la tabla periodica, opcion = Elemento - ` - SELECT ?option ?optionLabel ?questionLabel (SUBSTR(?símbolo, 1, 1) AS ?sym) - WHERE { - ?option wdt:P31 wd:Q11344; - wdt:P1086 ?questionLabel. - SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], es". } - } - LIMIT 100 - `, - // Pregunta = Batalla historica, opcion = año - `SELECT ?question ?questionLabel ?optionLabel - WHERE { - ?question wdt:P31 wd:Q178561. - ?question wdt:P580 ?date. - FILTER (YEAR(?date) >= 1500 && YEAR(?date) <= 2000) - BIND(YEAR(?date) as ?optionLabel) - SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } - } - LIMIT 100 - `]; +var queries = {}; + +queries['Geografia'] = + [ + // pregunta = Pais, opcion = capitales + `SELECT ?question ?questionLabel ?option ?optionLabel + WHERE { + ?question wdt:P31 wd:Q6256; wdt:P36 ?option. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + LIMIT 200 + `, + // pregunta = pais, opcion = montaña + ` + SELECT ?questionLabel ?optionLabel + WHERE { + ?country wdt:P31 wd:Q6256. + ?country wdt:P610 ?mountainRange. + ?mountainRange wdt:P2044 ?elevation. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + GROUP BY ?country ?questionLabel ?optionLabel + `, + // pregunta = poblacion, opcion = pais + ` + SELECT ?optionLabel ?questionLabel + WHERE { + ?option wdt:P31 wd:Q6256. + ?option wdt:P1082 ?questionLabel. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + `] + +queries['Cultura'] = + [ + // pregunta = pelicula, opcion = director + ` + SELECT DISTINCT ?questionLabel ?optionLabel + WHERE { + ?question wdt:P31 wd:Q11424; + wdt:P57 ?option. + ?question wdt:P577 ?publicationDate. + FILTER(YEAR(?publicationDate) >= 2000) + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es. } + } + LIMIT 200 + ` + ]; + +queries['Informatica'] = + [ + // pregunta = software, opcion = fecha + ` + SELECT ?questionLabel ?optionLabel + WHERE { + ?question wdt:P31 wd:Q7397. + ?question wdt:P571 ?optionLabel. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + `, + // pregunta = sistema operativo, opcion = creador + ` + SELECT ?questionLabel ?optionLabel + WHERE { + ?question wdt:P31 wd:Q9135. + ?question wdt:P178 ?option. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + LIMIT 200 + `, + // pregunta = creador, opcion = empresa + ` + SELECT ?optionLabel ?questionLabel + WHERE { + ?option wdt:P31 wd:Q4830453. + ?option wdt:P112 ?question. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + LIMIT 200 + ` + ]; // Todas las preguntas, en el mismo orden que las consultas var questions = ["¿Cuál es la capital de ", From 55c4a13ab47e7f712c8c27746cd3a8a8eb95d049 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 14 Apr 2024 23:19:51 +0200 Subject: [PATCH 3/8] =?UTF-8?q?Empezada=20la=20implementaci=C3=B3n=20de=20?= =?UTF-8?q?las=20tem=C3=A1ticas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatewayservice/gateway-service.js | 2 +- questiongenerator/image_questions.js | 22 +++++++- questiongenerator/question.js | 64 ++++++++++++++++++---- questiongenerator/text_questions.js | 56 ++++++++++++++++--- webapp/src/components/Game.js | 10 +--- webapp/src/components/GameConfiguration.js | 19 ++++++- webapp/src/components/PantallaInicio.js | 3 +- 7 files changed, 142 insertions(+), 34 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 01013524..da529e7c 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -50,7 +50,7 @@ app.post('/adduser', async (req, res) => { app.get(`/generateQuestion`, async (req, res) => { try { // Forward the add user request to the user service - const URL = generatorUrl + '/generateQuestion?user=' + req.query.user; + const URL = generatorUrl + '/generateQuestion?user=' + req.query.user + "&thematic" + req.query.thematic; const response = await axios.get(URL); res.json(response.data); } catch (error) { diff --git a/questiongenerator/image_questions.js b/questiongenerator/image_questions.js index ff131639..2f1b3985 100644 --- a/questiongenerator/image_questions.js +++ b/questiongenerator/image_questions.js @@ -62,11 +62,29 @@ queries['Personajes'] = SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } } LIMIT 200 + `, + // pregunta = Imagen de un presidente de EE.UU., opcion = Nombres de presidentes de EE.UU. + ` + SELECT ?option ?optionLabel ?imageLabel + WHERE { + ?option wdt:P31 wd:Q5; + wdt:P39 wd:Q11696; + wdt:P18 ?imageLabel. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } ` ]; // Todas las preguntas, en el mismo orden que las consultas -var questions = ["¿Que presidente de EE.UU es el que se muestra en la imagen?", - "¿Que país es el que aparece en la siguiente imagen?"]; +var questions = {}; + +questions['Geografia'] = ["¿Que país es el que aparece en la siguiente imagen?"]; + +questions['Cultura'] = ["¿Cuál es el nombre del siguiente cuadro?"]; + +questions['Personajes'] = ["¿Cuál es el nombre de este pintor?", + "¿Cuál es el nombre de este futbolista?", + "¿Cuál es el nombre de este cantante?", + "¿Que presidente de EE.UU es el que se muestra en la imagen?"]; module.exports = { queries, questions }; \ No newline at end of file diff --git a/questiongenerator/question.js b/questiongenerator/question.js index 0c4c03f9..279f7a93 100644 --- a/questiongenerator/question.js +++ b/questiongenerator/question.js @@ -24,12 +24,8 @@ app.use((req, res, next) => { next(); }); -var queries = []; -queries = queries.concat(textQueries); -queries = queries.concat(imagesQueries); -var questions = []; -questions = questions.concat(textQuestions); -questions = questions.concat(imagesQuestions); +var queries = getAllQueries(textQueries, imagesQueries); +var questions = getAllQueries(textQuestions, imagesQuestions); var correctOption = ""; var options = []; @@ -48,13 +44,30 @@ var maxQuestions = 5; const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/questiondb'; mongoose.connect(mongoUri); +function getAllQueries(textData, imageData) { + var results = {}; + for (var thematic in textData) { + results[thematic] = textData[thematic]; + } + + for (var thematic in imageData) { + if (results[thematic]) { + results[thematic] = results[thematic].concat(imageData[thematic]); + } else { + results[thematic] = imageData[thematic]; + } + } + + return results; +} + app.get('/generateQuestion', async (req, res) => { try { if(numberOfQuestions == 0){ gameId = null; } const user = req.query.user; - await generarPregunta(); + await generarPregunta(req.query.thematic); numberOfQuestions++; if(numberOfQuestions>=maxQuestions){ numberOfQuestions = 0; @@ -94,14 +107,34 @@ var server = app.listen(port, () => { -async function generarPregunta() { +async function generarPregunta(thematic) { + if(thematic === "Geografia") { + changeQueriesAndQuestions("Geografia"); + } else if(thematic === "Cultura") { + changeQueriesAndQuestions("Cultura"); + } else if(thematic === "Informatica") { + changeQueriesAndQuestions("Informatica"); + } else if(thematic === "Personajes") { + changeQueriesAndQuestions("Personajes"); + } + randomNumber = Math.floor(Math.random() * 2); try { // Petición a la API de WikiData - randomNumber = Math.floor(Math.random() * queries.length); + // TODO Arreglar el mismo problema que aquí pero con las preguntas + // TODO En queries y questions hay que mirar como se pueden poner todos los valores sin clave en los arrays, como estaba antes, dependiendo de la tematica + let thematics = Object.keys(queries); + randomNumber = Math.floor(Math.random() * thematics.length); + console.log("TEMATICAS: " + thematics); + let key = thematics[randomNumber]; + console.log("CLAVE: " + key); + + let thematicQueries = queries[key]; + randomNumber = Math.floor(Math.random() * thematicQueries.length); + console.log("CONSULTA: " + thematicQueries[randomNumber]); var response = await axios.get(url, { params: { - query: queries[randomNumber], + query: thematicQueries[randomNumber], format: 'json' }, headers: { @@ -118,6 +151,11 @@ async function generarPregunta() { } } +function changeQueriesAndQuestions(thematic) { + queries = queries[thematic]; + questions = questions[thematic]; +} + function procesarDatos(data) { // Hay que eliminar todos los elementos de options para que no se acumulen options = []; @@ -150,14 +188,16 @@ function procesarDatos(data) { // Escogemos un índice aleatorio como la opción correcta var correctIndex = Math.floor(Math.random() * 4); correctOption = data[randomIndexes[correctIndex]].optionLabel.value; + let thematics = Object.keys(questions); + let key = thematics[randomNumber]; if(quest == "") { - question = questions[randomNumber]; + question = questions[key]; image = data[randomIndexes[correctIndex]].imageLabel.value; } else { image = ""; questionValue = data[randomIndexes[correctIndex]].questionLabel.value; - question = questions[randomNumber] + questionValue + "?"; + question = questions[key] + questionValue + "?"; } diff --git a/questiongenerator/text_questions.js b/questiongenerator/text_questions.js index 550a87e5..045a2efb 100644 --- a/questiongenerator/text_questions.js +++ b/questiongenerator/text_questions.js @@ -24,10 +24,10 @@ queries['Geografia'] = `, // pregunta = poblacion, opcion = pais ` - SELECT ?optionLabel ?questionLabel + SELECT ?optionLabel ?question ?questionLabel WHERE { ?option wdt:P31 wd:Q6256. - ?option wdt:P1082 ?questionLabel. + ?option wdt:P1082 ?question. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } } `] @@ -45,6 +45,38 @@ queries['Cultura'] = SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es. } } LIMIT 200 + `, + // pregunta = termino, opcion = universo + ` + SELECT DISTINCT ?question ?questionLabel ?option ?optionLabel + WHERE { + { + ?term wdt:P1080 wd:Q19595297; # Relacionado con Warhammer 40000 + rdfs:label ?termLabel. + BIND("Warhammer 40000" AS ?option) + } + UNION + { + ?term wdt:P1080 wd:Q19786052; # Relacionado con Star Wars + rdfs:label ?termLabel. + BIND("Star Wars" AS ?option) + } + UNION + { + ?term wdt:P1080 wd:Q18043309; # Relacionado con Star Trek + rdfs:label ?termLabel. + BIND("Star Trek" AS ?option) + } + UNION + { + ?term wdt:P1080 wd:Q81738; # Relacionado con Legendarium + rdfs:label ?termLabel. + BIND("Legendarium" AS ?option) + } + FILTER(LANG(?termLabel) = "es") + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } + } + LIMIT 200 ` ]; @@ -52,10 +84,10 @@ queries['Informatica'] = [ // pregunta = software, opcion = fecha ` - SELECT ?questionLabel ?optionLabel + SELECT ?questionLabel ?option ?optionLabel WHERE { ?question wdt:P31 wd:Q7397. - ?question wdt:P571 ?optionLabel. + ?question wdt:P571 ?option. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } } `, @@ -82,9 +114,17 @@ queries['Informatica'] = ]; // Todas las preguntas, en el mismo orden que las consultas -var questions = ["¿Cuál es la capital de ", - "¿En que campo juega el ", - "¿Cuál es el elemento de la tabla periódica número ", - "¿En que año ocurrio la "]; +var questions = {}; + +questions['Geografia'] = ["¿Cuál es la capital de ", + "¿Que montaña se encuentra en ", + "¿Que pais tiene una poblacion de personas de "]; + +questions['Cultura'] = ["¿Que director dirigio ", + "¿Con que universo ficticio está relacionado el siguiente término: "]; + +questions['Informatica'] = ["¿En que fecha se creó ", + "¿Quién creo el sistema opertativo ", + "¿Que empresa tecnológica fue creada por "]; module.exports = { queries, questions }; \ No newline at end of file diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 7fabb36b..eaed6d94 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -22,23 +22,19 @@ const Game = () => { const [answeredQuestions,setAnsweredQuestions] = useState(0); const [isTimeRunning, setIsTimeRunning] = useState(true); - - - // Comentario de prueba para el despliegue - const location = useLocation(); const MAX_TIME = location.state ? location.state.time : null; const MAX_PREGUNTAS = location.state ? location.state.question : null; + const THEMATIC = location.state ? location.state.thematic : null; const navigate = useNavigate(); - - const getQuestion = useCallback(async () => { try { const response = await axios.get(`${apiEndpoint}/generateQuestion`, { params: { - user: usernameGlobal + user: usernameGlobal, + thematic: THEMATIC } }); setQuestion(response.data.responseQuestion); diff --git a/webapp/src/components/GameConfiguration.js b/webapp/src/components/GameConfiguration.js index b9619e6b..73e9326e 100644 --- a/webapp/src/components/GameConfiguration.js +++ b/webapp/src/components/GameConfiguration.js @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import axios from 'axios'; import { useNavigate} from 'react-router-dom'; -import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; +import { Container, Typography, TextField, Button, Snackbar, skeletonClasses } from '@mui/material'; import '../App.css'; const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; @@ -12,6 +12,7 @@ const GameConfiguration = () => { const [openSnackbar, setOpenSnackbar] = useState(false); const [error, setError] = useState(''); const [snackbarMessage, setSnackbarMessage] = useState(''); + const [selectedOption, setSelectedOption] = useState(null); const maxTime = 60; const [valueTime, setValueTime] = useState(30); @@ -45,13 +46,17 @@ const GameConfiguration = () => { const configureAndStart = async () => { try { await axios.post(`${apiEndpoint}/configureGame`, {valueTime, valueQuestion}); - navigate("/Game", {state: {time: valueTime, question:valueQuestion}}); + navigate("/Game", {state: {time: valueTime, question:valueQuestion, thematic:selectedOption}}); } catch (error) { setError(error.response.data.error); setOpenSnackbar(true); } }; + const handleOptionSelect = (event) => { + setSelectedOption(event.target.value); + }; + return ( { max: 60, }} /> +
+ +