Skip to content

Commit

Permalink
Merge pull request #94 from Arquisoft/quizGame
Browse files Browse the repository at this point in the history
Corrección bugs #91, #92, #93
  • Loading branch information
uo287998 authored Mar 31, 2024
2 parents 874fe63 + 9457040 commit 3e65cf9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
20 changes: 10 additions & 10 deletions preguntas/generatorservice/data/data.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[
{
"question": "¿Cuál es la capital de ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P36 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P36 ?r. FILTER(?p != wd:Q124653007) SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
},
{
"question": "¿A qué continente pertenece ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P30 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P30 ?r. FILTER(?p NOT IN (wd:Q703695, wd:Q28846511, wd:Q120088504, wd:Q115166787)) SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
},
{
"question": "¿Cuál es el área en Kilómetros cuadrados (Km2) de ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P2046 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
},
{
"question": "¿Cuál es la suerficie ocupada por el ^ en kilómetros cuadrados (km2)?",
"question": "¿Cuál es la superficie ocupada por el ^ en kilómetros cuadrados (km2)?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q165. ?p wdt:P2046 ?r. FILTER (?r > 800000) FILTER (STR(?p) != 'http://www.wikidata.org/entity/Q3240274') SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". }}"

},
Expand Down Expand Up @@ -41,22 +41,22 @@
},
{
"question": "¿Cuál es el apodo de ^?",
"query":"SELECT ?pLabel (SAMPLE(?r) AS ?rLabel) WHERE { ?p wdt:P31 wd:Q5; wdt:P118 wd:Q155223; wdt:P8687 ?followers; wdt:P1449 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } } GROUP BY ?pLabel"
"query":"SELECT ?pLabel (SAMPLE(?r) AS ?rLabel) WHERE { ?p wdt:P31 wd:Q5; wdt:P118 wd:Q155223; wdt:P8687 ?followers; wdt:P1449 ?r. FILTER(?followers > 100000) SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } } GROUP BY ?pLabel"
},



{
"question": "¿Qúe moneda es utilizada en ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P38 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P38 ?r. FILTER(?r NOT IN (wd:Q100928009, wd:Q329248, wd:Q4228784, wd:Q96051466)) SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
},
{
"question": "¿Cuál es el nombre del presidente/jefe de Estado de ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P35 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P35 ?r. FILTER(?p != wd:Q124653007) SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
},
{
"question": "¿Cuál es el nombre del primer ministro de ^?",
"query": "SELECT ?pLabel ?rLabel WHERE {?p wdt:P31 wd:Q6256. ?p wdt:P6 ?r. FILTER (?p != wd:Q967 && ?p != wd:Q965) SERVICE wikibase:label { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],es'. }}"
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P6 ?r. FILTER (?p != wd:Q967 && ?p != wd:Q965 && ?p != wd:Q124653007) SERVICE wikibase:label { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],es'. } }"
},
{
"question": "¿Qué imagen es de ^?",
Expand All @@ -67,16 +67,16 @@

{
"question": "¿Cuál es la bandera de ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. OPTIONAL { ?p wdt:P41 ?rLabel } FILTER(BOUND(?rLabel)) SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". }}"
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. FILTER (?p != wd:Q124653007) OPTIONAL { ?p wdt:P41 ?rLabel } FILTER(BOUND(?rLabel)) SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"

},
{
"question": "¿Cuál es el logo de ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q13393265; wdt:P118 wd:Q155223; wdt:P154 ?rLabel. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
"query": "SELECT ?pLabel (SAMPLE(?rLogo) AS ?rLabel) WHERE { ?p wdt:P31 wd:Q13393265; wdt:P118 wd:Q155223; wdt:P154 ?rLogo. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } } GROUP BY ?pLabel"
},
{
"question": "¿Cuál es el escudo de ^?",
"query":"SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q476028; wdt:P118 ?liga; wdt:P154 ?rLabel. VALUES ?liga { wd:Q9448 wd:Q324867 wd:Q82595 wd:Q15804} SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
"query":"SELECT ?pLabel (SAMPLE(?rLogo) AS ?rLabel) WHERE { ?p wdt:P31 wd:Q476028; wdt:P118 ?liga; wdt:P154 ?rLogo. VALUES ?liga { wd:Q9448 wd:Q324867 wd:Q82595 wd:Q15804} SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } } GROUP BY ?pLabel"
},


Expand Down
32 changes: 29 additions & 3 deletions preguntas/generatorservice/question-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const templateData = require('./data/data.json');
const app = express();
const port = 8003;

/**
//Constante para el tamaño de imagenes
const widthSize = 140;
*/

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/questiondb';
Expand Down Expand Up @@ -79,13 +81,14 @@ app.get('/generate-question', async (req, res) => {
const wrongAnswer2 = formattedResults[randomIndex2];
const wrongAnswer3 = formattedResults[randomIndex3];

/**
//Cambio de URL. Imagen redimensionada
if (correctAnswer.rLabel.includes('upload.wikimedia.org')) {
correctAnswer.rLabel = getThumbUrl(correctAnswer.rLabel, widthSize);
wrongAnswer1.rLabel = getThumbUrl(wrongAnswer1.rLabel, widthSize);
wrongAnswer2.rLabel = getThumbUrl(wrongAnswer2.rLabel, widthSize);
wrongAnswer3.rLabel = getThumbUrl(wrongAnswer3.rLabel, widthSize);
}
}*/

//Creación de array desordenado con todas las respuestas
const allAnswersSorted = [correctAnswer.rLabel, wrongAnswer1.rLabel, wrongAnswer2.rLabel, wrongAnswer3.rLabel];
Expand All @@ -94,6 +97,14 @@ app.get('/generate-question', async (req, res) => {
// Add pLabel to question string from template
const question = template.question.replace('^', correctAnswer.pLabel);

//Cambio de formato de numero. Se intenta hacer más legible
if (question.includes('superficie') || question.includes('área')) {
correctAnswer.rLabel = await formatoNumero(correctAnswer.rLabel);
for (let i = 0; i < allAnswers.length; i++) {
allAnswers[i] = await formatoNumero(allAnswers[i]);
}
}

// Create a new question
const newQuestion = new Question({
question: question,
Expand Down Expand Up @@ -132,7 +143,7 @@ function shuffleArray(array) {
}
return array;
}

/**
function getThumbUrl(originalUrl, width) {
// Verifica si la URL es de Wikipedia
if (!originalUrl.includes('upload.wikimedia.org/wikipedia/commons/')) {
Expand All @@ -145,4 +156,19 @@ function getThumbUrl(originalUrl, width) {
"/commons/", "/commons/thumb/").replace(".svg", ".png") + "/"+ width +"px-" + filename;
return thumbnailUrl;
}
}*/

//Funcion de formateo de numeros
async function formatoNumero(numero) {
// Convertir el número a string y reemplazar puntos por comas
let numeroStr = numero.toString().replace('.', ',');

// Separar la parte entera de la decimal
let partes = numeroStr.split(',');

// Formatear la parte entera con puntos cada 3 dígitos
partes[0] = partes[0].replace(/\B(?=(\d{3})+(?!\d))/g, '.');

// Unir las partes nuevamente
return partes.join(',');
}
4 changes: 2 additions & 2 deletions webapp/src/components/QuizGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const QuizGame = () => {
>
{
answer.startsWith('http') ?
<img src={answer} alt="imagen" style={{ height: '110px' }} />
<img src={answer} alt="imagen" style={{ maxWidth:"180px", height: '110px' }} />
: answer
}
</Button>
Expand Down Expand Up @@ -176,7 +176,7 @@ const QuizGame = () => {
>
{
answer.startsWith('http') ?
<img src={answer} alt="imagen" style={{ height: '110px' }} />
<img src={answer} alt="imagen" style={{ maxWidth: '180px', height: '110px' }} />
: answer
}
</Button>
Expand Down

0 comments on commit 3e65cf9

Please sign in to comment.