From 09f62d84893f318b2972a9b906ecadb76e4ca72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Thu, 28 Mar 2024 21:41:55 +0100 Subject: [PATCH 1/3] More templates added to planets category --- docs/images/deploymentDiagramWIQ.svg | 1 - question_generator/locales/en.json | 7 + question_generator/locales/es.json | 7 + .../planets/planetsQuestions.js | 123 +++++++++++++----- .../planets/planetsTemplates.js | 20 +++ 5 files changed, 123 insertions(+), 35 deletions(-) delete mode 100644 docs/images/deploymentDiagramWIQ.svg diff --git a/docs/images/deploymentDiagramWIQ.svg b/docs/images/deploymentDiagramWIQ.svg deleted file mode 100644 index b778d0cc..00000000 --- a/docs/images/deploymentDiagramWIQ.svg +++ /dev/null @@ -1 +0,0 @@ -
Actor
Actor
Device
Device
Browser
Browser
WebApp
WebApp
GatewayService
GatewayService
Microservices
Microservices
Question generator
Question generator
AuthService
AuthService
UserService
UserService
Docker container
Docker cont...
Docker container
Docker cont...
Docker container
Docker cont...
MongoDB
MongoDB
Wikidata
Wikidata
Azure VM
Azure VM
Docker container
Docker cont...
Docker container
Docker cont...
Docker container
Docker cont...
Text is not SVG - cannot display
\ No newline at end of file diff --git a/question_generator/locales/en.json b/question_generator/locales/en.json index c7b75061..d30c5f79 100644 --- a/question_generator/locales/en.json +++ b/question_generator/locales/en.json @@ -7,6 +7,13 @@ "Which city is in the time zone?": "Which city is in the time zone %s?", "Which planet is bigger?": "Which planet is bigger?", + "Which planet has a mass of?": "Which planet has a mass of %s kg?", + "Which planet has a radius of?": "Which planet has a radius of %s km?", + "Which planet has an orbital period of?" : "Which planet has an orbital period of %s days?", + "Which planet has x as the lowest point?" : "Which planet has %s as the lowest point?", + "Which planet has x as the highest point?" : "Which planet has %s as the highest point?", + "Which planet has an area of x?" : "Which planet has an area of %s km2?", + "Which planet has a density of x?" : "Which planet has a density of %s kg/m3?", "Who has more Grand Slams?": "Who has more Grand Slams?", "Who has more followers?": "Who has more followers?", diff --git a/question_generator/locales/es.json b/question_generator/locales/es.json index 8f2b67f4..4c19d4f3 100644 --- a/question_generator/locales/es.json +++ b/question_generator/locales/es.json @@ -7,6 +7,13 @@ "Which city is in the time zone?": "¿Qué ciudad está en la zona horaria %s?", "Which planet is bigger?": "¿Qué planeta es más grande?", + "Which planet has a mass of?": "¿Qué planeta tiene una masa de %s kg?", + "Which planet has a radius of?": "¿Qué planeta tiene un radio de %s km?", + "Which planet has an orbital period of?" : "¿Qué planeta tiene un período orbital de %s días?", + "Which planet has x as the lowest point?" : "¿Qué planeta tiene %s como el punto más bajo?", + "Which planet has x as the highest point?" : "¿Qué planeta tiene %s como el punto más alto?", + "Which planet has an area of x?" : "¿Qué planeta tiene un área de %s km2?", + "Which planet has a density of x?" : "¿Qué planeta tiene una densidad de %s kg/m3?", "Who has more Grand Slams?": "¿Quién tiene más Grand Slams?", "Who has more followers?": "¿Quién tiene más seguidores?", diff --git a/question_generator/planets/planetsQuestions.js b/question_generator/planets/planetsQuestions.js index 085bde74..e3ce0c55 100644 --- a/question_generator/planets/planetsQuestions.js +++ b/question_generator/planets/planetsQuestions.js @@ -1,4 +1,5 @@ const queryExecutor=require("../queryExecutor") +const QuestionsUtils = require("../questions-utils"); class PlanetsQuestions{ #planetsQuestions=null; static getInstance(){ @@ -10,39 +11,86 @@ class PlanetsQuestions{ constructor(){ this.planets={} } - async loadData(){ - let newResults={}; - const query= ` - SELECT ?planet ?planetLabel (SAMPLE(?radius) AS ?radius) - WHERE { - ?categ wdt:P361 wd:Q337768. - ?planet wdt:P31 ?categ. - OPTIONAL { - ?planet wdt:P2120 ?radius. - } - FILTER EXISTS { - ?planet wdt:P2120 ?radius. - } - SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } + async loadPlanets(){ + let result={}; + const planetsQueries=[ + ` + SELECT ?planet ?planetLabel + WHERE { + ?categ wdt:P361 wd:Q337768. + ?planet wdt:P31 ?categ. + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } + } + `, + ` + SELECT ?planet ?planetLabel + WHERE { + ?planet wdt:P31 wd:Q3504248; + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } + } + ` + + ]; + for(let i = 0; i { + const planetId = planet.planet.value.match(/Q\d+/)[0]; + const planetName = planet.planetLabel.value; + if (!result[planetId]) { + result[planetId] = { + planetId: planetId, + name: planetName + } + } + }); } - GROUP BY ?planet ?planetLabel - `; - const results=await queryExecutor.execute(query) - results.forEach(planet => { - const planetId = planet.planet.value; - const planetName = planet.planetLabel.value; - const radius = planet.radius.value; + return result; - if (!newResults[planetId]) { - newResults[planetId] = { - planetId: planetId, - planetName: planetName, - radius: [] - }; + } + async loadData(){ + let newResults = await this.loadPlanets(); + const propertiesToLoad=[ + { + name:'radius', + id: 'P2120' + }, + { + name:'density', + id: 'P2054' + }, + { + name:'area', + id: 'P2046' + }, + { + name:'mass', + id: 'P2067' + }, + { + name:'orbital_period', + id: 'P2047' + }, + { + name:'highest_point', + id: 'P610' + }, + { + name:'lowest_point', + id: 'P1589' } - - newResults[planetId].radius.push(parseFloat(radius)); - }); + ] + for(let i = 0; i 0){ + for(let j=0;j Math.random() - 0.5).slice(0, number); return randomResults } + async doQuestion(property,nValues){ + if(Object.keys(this.planets).length==0){ + await this.loadData(); + } + return QuestionsUtils.getValuesFromDataAndProperty(this.planets, property, nValues); + } async getBiggestPlanet(){ const results=await this.getRandomPlanets(4); - const formattedResults = await results.sort((a, b) => b.radius[0] - a.radius[0]); - var finalResults={ + let formattedResults = results.filter(planet => planet.radius !== undefined); + formattedResults = await formattedResults.sort((a, b) => parseFloat(b.radius) - parseFloat(a.radius)); + let finalResults={ correct: null, incorrects:[] } for(let i = 0; i < Math.min(formattedResults.length,4); i++) { if(i==0){ - finalResults.correct=formattedResults[i].planetName; + finalResults.correct=formattedResults[i].name; } else{ - finalResults.incorrects.push(formattedResults[i].planetName); + finalResults.incorrects.push(formattedResults[i].name); } } return finalResults; diff --git a/question_generator/planets/planetsTemplates.js b/question_generator/planets/planetsTemplates.js index 31b10fd5..0525a68b 100644 --- a/question_generator/planets/planetsTemplates.js +++ b/question_generator/planets/planetsTemplates.js @@ -12,6 +12,26 @@ const templates=[ "correct":planets.correct, "incorrects":planets.incorrects } + }, + async ()=> + { + const result= await planetsQuery.doQuestion('radius',4); + return{ + "question":"Which planet has a radius of?", + "question_param":result.question_param, + "correct":result.correct, + "incorrects":result.incorrects + } + }, + async ()=> + { + const result= await planetsQuery.doQuestion('area',4); + return{ + "question": "Which planet has an area of x?", + "question_param":result.question_param, + "correct":result.correct, + "incorrects":result.incorrects + } } From e12e9d193753d5e957c9b2587598592e04508062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Thu, 28 Mar 2024 22:56:42 +0100 Subject: [PATCH 2/3] i18n files updated --- question_generator/locales/en.json | 6 +++--- question_generator/locales/es.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/question_generator/locales/en.json b/question_generator/locales/en.json index d30c5f79..3f45a916 100644 --- a/question_generator/locales/en.json +++ b/question_generator/locales/en.json @@ -16,8 +16,8 @@ "Which planet has a density of x?" : "Which planet has a density of %s kg/m3?", "Who has more Grand Slams?": "Who has more Grand Slams?", - "Who has more followers?": "Who has more followers?", - "Who has more looses?": "Who has more looses?", - "Who has more wins?": "Who has more wins?", + "Who has more followers? (Tennis)": "Who has more followers? (Tennis)", + "Who has more looses? (Tennis)": "Who has more looses? (Tennis)", + "Who has more wins? (Tennis)": "Who has more wins? (Tennis)", "Which tennis player is from?" : "Which tennis player is from %s?" } \ No newline at end of file diff --git a/question_generator/locales/es.json b/question_generator/locales/es.json index 4c19d4f3..1692eeea 100644 --- a/question_generator/locales/es.json +++ b/question_generator/locales/es.json @@ -16,9 +16,9 @@ "Which planet has a density of x?" : "¿Qué planeta tiene una densidad de %s kg/m3?", "Who has more Grand Slams?": "¿Quién tiene más Grand Slams?", - "Who has more followers?": "¿Quién tiene más seguidores?", - "Who has more looses?": "¿Quién tiene más derrotas?", - "Who has more wins?": "¿Quién tiene más victorias?", + "Who has more followers?": "¿Quién tiene más seguidores? (Tenis)", + "Who has more looses?": "¿Quién tiene más derrotas? (Tenis)", + "Who has more wins?": "¿Quién tiene más victorias? (Tenis)", "Which tennis player is from?" : "¿Qué jugador es de %s?" } \ No newline at end of file From 7c57d544b737d9f94036af404575424c0ed960c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Thu, 28 Mar 2024 23:22:48 +0100 Subject: [PATCH 3/3] Templates for autonomous communities of Spain added --- .../autonomousCommunitiesSpainQuestions.js | 87 +++++++++++++++++++ .../autonomousCommunitiesSpainTemplates.js | 59 +++++++++++++ .../geography/geographyTemplate.js | 5 +- question_generator/locales/en.json | 11 ++- question_generator/locales/es.json | 7 ++ 5 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 question_generator/geography/autonomous_communities_spain/autonomousCommunitiesSpainQuestions.js create mode 100644 question_generator/geography/autonomous_communities_spain/autonomousCommunitiesSpainTemplates.js diff --git a/question_generator/geography/autonomous_communities_spain/autonomousCommunitiesSpainQuestions.js b/question_generator/geography/autonomous_communities_spain/autonomousCommunitiesSpainQuestions.js new file mode 100644 index 00000000..d7b9f9f4 --- /dev/null +++ b/question_generator/geography/autonomous_communities_spain/autonomousCommunitiesSpainQuestions.js @@ -0,0 +1,87 @@ +const queryExecutor=require("../../queryExecutor"); +const QuestionsUtils = require("../../questions-utils"); +class CAQuestions{ + static getInstance(){ + if (!this.questions) { + this.questions = new CAQuestions(); + } + return this.questions; + } + constructor(){ + this.data={}; + } + async loadValues(){ + let result={}; + const queries=[ + ` + SELECT ?community ?communityLabel + WHERE { + ?community wdt:P31 wd:Q10742; + SERVICE wikibase:label { bd:serviceParam wikibase:language "es". } + } + ` + + ]; + for(let i = 0; i { + const caId = ca.community.value.match(/Q\d+/)[0]; + const caName = ca.communityLabel.value; + if (!result[caId]) { + result[caId] = { + caId: caId, + name: caName, + } + } + }); + } + return result; + + } + async loadData(){ + let newResults = await this.loadValues(); + const propertiesToLoad=[ + { + name:'capital', + id: 'P36' + }, + { + name:'highest_point', + id: 'P610' + }, + { + name:'population', + id: 'P1082' + }, + { + name: 'area', + id: 'P2046' + }, + { + name: 'head_of_government', + id: 'P6' + } + ] + for(let i = 0; i 0){ + for(let j=0;j + { + const results= await Query.doQuestion('area',4); + return{ + "question":"Which autonomous community of Spain has an area of?", + "question_param":results.question_param, + "correct":results.correct, + "incorrects":results.incorrects + } + }, + async ()=> + { + const results= await Query.doQuestion('population',4); + return{ + "question":"Which autonomous community of Spain has a population of?", + "question_param":results.question_param, + "correct":results.correct, + "incorrects":results.incorrects + } + }, + async ()=> + { + const results= await Query.doQuestion('capital',4); + return{ + "question":"Which autonomous community of Spain has a capital called?", + "question_param":results.question_param, + "correct":results.correct, + "incorrects":results.incorrects + } + }, + async ()=> + { + const results= await Query.doQuestion('head_of_government',4); + return{ + "question":"Which autonomous community of Spain has a president called?", + "question_param":results.question_param, + "correct":results.correct, + "incorrects":results.incorrects + } + }, + async ()=> + { + const results= await Query.doQuestion('highest_point',4); + return{ + "question":"Which autonomous community of Spain has x as the highest point?", + "question_param":results.question_param, + "correct":results.correct, + "incorrects":results.incorrects + } + } +] +module.exports.getRandomQuestion = () => templates[Math.floor(Math.random()*templates.length)](); +module.exports.loadData = () =>loadData(); \ No newline at end of file diff --git a/question_generator/geography/geographyTemplate.js b/question_generator/geography/geographyTemplate.js index ddf64a8d..9db847ed 100644 --- a/question_generator/geography/geographyTemplate.js +++ b/question_generator/geography/geographyTemplate.js @@ -1,9 +1,12 @@ const citiesTemplate=require('./cities/citiesTemplates') +const autonomousCommunitiesSpainTemplate=require('./autonomous_communities_spain/autonomousCommunitiesSpainTemplates') function loadData(){ citiesTemplate.loadData(); + autonomousCommunitiesSpainTemplate.loadData(); } const templates=[ - citiesTemplate.getRandomQuestion + citiesTemplate.getRandomQuestion, + autonomousCommunitiesSpainTemplate.getRandomQuestion ] module.exports.getRandomQuestion = () => templates[Math.floor(Math.random()*templates.length)](); module.exports.loadData = () =>loadData(); \ No newline at end of file diff --git a/question_generator/locales/en.json b/question_generator/locales/en.json index 3f45a916..791300bf 100644 --- a/question_generator/locales/en.json +++ b/question_generator/locales/en.json @@ -2,9 +2,18 @@ "Which city is higher above sea level?": "Which city is higher above sea level?", "Which city has more population?": "Which city has more population?", "Which city is in?": "Which city is in %s?", - "Which city has an area of?": "Which city has an area od %s km2?", + "Which city has an area of?": "Which city has an area of %s km2?", "Which city is governed by?": "Which city is governed by %s?", "Which city is in the time zone?": "Which city is in the time zone %s?", + + "Which autonomous community of Spain has an area of?": "Which autonomous community of Spain has an area of %s km2?", + "Which autonomous community of Spain has a population of?": "Which autonomous community of Spain has a population of %s?", + "Which autonomous community of Spain has a capital called?": "Which autonomous community of Spain has a capital called %s?", + "Which autonomous community of Spain has a president called?": "Which autonomous community of Spain has a president called %s?", + "Which autonomous community of Spain has x as the highest point?" : "Which autonomous community of Spain has %s as the highest point?", + + + "Which planet is bigger?": "Which planet is bigger?", "Which planet has a mass of?": "Which planet has a mass of %s kg?", diff --git a/question_generator/locales/es.json b/question_generator/locales/es.json index 1692eeea..68b0c2b2 100644 --- a/question_generator/locales/es.json +++ b/question_generator/locales/es.json @@ -6,6 +6,13 @@ "Which city is governed by?": "¿Qué ciudad es gobernada por %s?", "Which city is in the time zone?": "¿Qué ciudad está en la zona horaria %s?", + "Which autonomous community of Spain has an area of?": "¿Qué comunidad autónoma de España tiene un área de %s km2?", + "Which autonomous community of Spain has a population of?": "¿Qué comunidad autónoma de España tiene una población de %s?", + "Which autonomous community of Spain has a capital called?": "¿Qué comunidad autónoma de España tiene una capital llamada %s?", + "Which autonomous community of Spain has a president called?": "¿Qué comunidad autónoma de España tiene un presidente llamado %s?", + "Which autonomous community of Spain has x as the highest point?" : "¿Qué comunidad autónoma de España tiene %s como el punto más alto?", + + "Which planet is bigger?": "¿Qué planeta es más grande?", "Which planet has a mass of?": "¿Qué planeta tiene una masa de %s kg?", "Which planet has a radius of?": "¿Qué planeta tiene un radio de %s km?",