Skip to content

Commit

Permalink
generacion de preguntas aleatorias
Browse files Browse the repository at this point in the history
  • Loading branch information
uo283055 committed Feb 20, 2024
1 parent 46de0aa commit b0b7ab9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
5 changes: 4 additions & 1 deletion questions/createservice/create-service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const Question = require('./create-model')
const Question = require('./create-model');



const app = express();
const port = 8005;
Expand Down Expand Up @@ -30,6 +32,7 @@ app.post('/addQuestion', async (req, res) => {
}
});


//obtiene una pregunta de forma aleatoria
app.post('/getQuestionBody', async (req, res) => {
try {
Expand Down
51 changes: 23 additions & 28 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@ const Game=() =>{


setquestionBody(response.data.questionBody);//obtengo los datos del cuerpo de la pregunta
//setQuestionType(response.data.typeQuestion);
//setQuestionType(response.data.typeAnswer);
setQuestionType(response.data.typeQuestion);
setAnswerType(response.data.typeAnswer);

} catch (error) {
console.error("Error al obtener la pregunta aleatoria", error);
}
};






// Obtener info de wikidata segun el tipo de la pregunta y la respuesta para esa pregunta
//questionType, answerType
const obtenerInformacionWikidata = async () => {
const obtenerPais = async () => {

try {
// Consulta SPARQL//obtengo
Expand Down Expand Up @@ -76,45 +73,43 @@ const Game=() =>{
const index = Math.floor(Math.random() * numEles);//index al azar
const result = data.results.bindings[index];

setInformacionWikidata(result.countryLabel.value);
setInformacionWikidata(result.countryLabel.value+`?`);

} else {
console.error("Error al realizar la consulta en Wikidata. Estado de respuesta:", respuestaWikidata.status);
}
} catch (error) {
console.error("Error al realizar la consulta en Wikidata", error);
}

};

const handleButtonClick = () => {
obtenerPreguntaAleatoria();
//pais, libro,actor, edificio
if (questionType=='pais'){
obtenerPais();}
else if (questionType =='libro'){
obtenerPais();}
else if (questionType ==='actor'){
obtenerPais();}
else if (questionType=='edificio'){
obtenerPais();}
//etc...


//obtenerInformacionWikidata();
/* useEffect(() => {
obtenerPreguntaAleatoria();
}, []);*/


//obtenerPreguntaAleatoria();
};

return (

<div>
<h1>Pregunta</h1>
<h1>Pregunta: </h1>
<div>
<Typography component="h1" variant="h5" sx={{ textAlign: 'center' }}>
Base de pregunta al azar de mongo: {questionBody}
</Typography>

<Button variant="contained" color="primary" onClick={obtenerPreguntaAleatoria}>
pregunta
</Button>

<Typography component="h1" variant="h5" sx={{ textAlign: 'center' }}>
Prueba de Wikidata, pais al azar:{informacionWikidata}
{questionBody} {informacionWikidata}
</Typography>

<Button variant="contained" color="primary" onClick={obtenerInformacionWikidata}>
Wikidata
<Button variant="contained" color="primary" onClick={handleButtonClick}>
Generar pregunta
</Button>
</div>
</div>
Expand Down

0 comments on commit b0b7ab9

Please sign in to comment.