From d8b317e98a7d3fc9a9b9fa9826516637e7c9e167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Fern=C3=A1ndez?= Date: Sat, 30 Mar 2024 13:24:26 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Preguntas=20con=20im=C3=A1genes=20V.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preguntas/generatorservice/question-service.js | 9 ++++++--- webapp/src/components/QuizGame.js | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/preguntas/generatorservice/question-service.js b/preguntas/generatorservice/question-service.js index 5ef8624e..5066cfa7 100644 --- a/preguntas/generatorservice/question-service.js +++ b/preguntas/generatorservice/question-service.js @@ -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'; @@ -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]; @@ -132,7 +135,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/')) { @@ -145,4 +148,4 @@ function getThumbUrl(originalUrl, width) { "/commons/", "/commons/thumb/").replace(".svg", ".png") + "/"+ width +"px-" + filename; return thumbnailUrl; -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/webapp/src/components/QuizGame.js b/webapp/src/components/QuizGame.js index 66cac370..cdd1a47e 100644 --- a/webapp/src/components/QuizGame.js +++ b/webapp/src/components/QuizGame.js @@ -146,7 +146,7 @@ const QuizGame = () => { > { answer.startsWith('http') ? - imagen + imagen : answer } @@ -176,7 +176,7 @@ const QuizGame = () => { > { answer.startsWith('http') ? - imagen + imagen : answer } From 768521c102bcadd61dd59ad8050a79c46ecf61cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Fern=C3=A1ndez?= Date: Sat, 30 Mar 2024 14:41:37 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Correccion=20formato=20n=C3=BAmeros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preguntas/generatorservice/data/data.json | 2 +- .../generatorservice/question-service.js | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/preguntas/generatorservice/data/data.json b/preguntas/generatorservice/data/data.json index 9e0073cf..9039e225 100644 --- a/preguntas/generatorservice/data/data.json +++ b/preguntas/generatorservice/data/data.json @@ -12,7 +12,7 @@ "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\". }}" }, diff --git a/preguntas/generatorservice/question-service.js b/preguntas/generatorservice/question-service.js index 5066cfa7..16f8ead9 100644 --- a/preguntas/generatorservice/question-service.js +++ b/preguntas/generatorservice/question-service.js @@ -97,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, @@ -148,4 +156,19 @@ function getThumbUrl(originalUrl, width) { "/commons/", "/commons/thumb/").replace(".svg", ".png") + "/"+ width +"px-" + filename; return thumbnailUrl; -}*/ \ No newline at end of file +}*/ + +//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(','); +} From 9457040a7fc2148aff236a2c316434df00006f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Fern=C3=A1ndez?= Date: Sun, 31 Mar 2024 19:24:14 +0200 Subject: [PATCH 3/3] Eliminar bugs data.json --- preguntas/generatorservice/data/data.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/preguntas/generatorservice/data/data.json b/preguntas/generatorservice/data/data.json index 9039e225..8c74c4f4 100644 --- a/preguntas/generatorservice/data/data.json +++ b/preguntas/generatorservice/data/data.json @@ -1,11 +1,11 @@ [ { "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 ^?", @@ -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 ^?", @@ -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" },