From a5898f50bf36da69394c5373e24ae8b568f5462a Mon Sep 17 00:00:00 2001 From: Pablo Lobeto Arenas Date: Sat, 6 Apr 2024 05:04:45 +0200 Subject: [PATCH] Check thar game works correctly and added the monument to the game --- game/qgservice/QGController.js | 28 +++++++++++++------ game/qgservice/generatorLogic/BindResults.js | 4 +-- .../generatorLogic/questiongenerator.js | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/game/qgservice/QGController.js b/game/qgservice/QGController.js index 9eb7730..33ec9c1 100644 --- a/game/qgservice/QGController.js +++ b/game/qgservice/QGController.js @@ -1,8 +1,8 @@ -const { generateQuestionPopulation, generateQuestionCapital, generateQuestionChemical } = require('./generatorLogic/questiongenerator'); +const { generateQuestionPopulation, generateQuestionCapital, generateQuestionChemical, generateQuestionMonument } = require('./generatorLogic/questiongenerator'); const Question4Answers = require('./Question4Answers'); const { executeSparqlQuery } = require('./generatorLogic/SparqlQuery') -const { bindCapitalsResults, bindPopulationResults } = require('./generatorLogic/BindResults') -const { spainCapitalQuery, worldCapitalQuery, worldPopulationQuery, chemicalElementQuery } = require('./generatorLogic/queries') +const { bindCapitalsResults, bindPopulationResults, bindChemicalResults, bindMonumentResults } = require('./generatorLogic/BindResults') +const { spainCapitalQuery, worldCapitalQuery, worldPopulationQuery, chemicalElementQuery, monumentQuery } = require('./generatorLogic/queries') const { createMathQuestions } = require('./generatorLogic/MathQuestions') let QGController = { @@ -12,7 +12,7 @@ let QGController = { const questions = []; // spain capitals - nQuestions = 2; + nQuestions = 3; const spainQueryResult = await executeSparqlQuery(spainCapitalQuery); const spainCapitals = bindCapitalsResults(spainQueryResult) @@ -22,7 +22,7 @@ let QGController = { } // world capitals - nQuestions = 3; + nQuestions = 2; const worldQueryResult = await executeSparqlQuery(worldCapitalQuery); const worldCapitals = bindCapitalsResults(worldQueryResult) @@ -42,17 +42,27 @@ let QGController = { } // chemical elements - nQuestions = 3; - const chemicalResult = await executeSparqlQuery(chemicalElementQueryQuery); - const chemicalElement = bindCapitalsResults(chemicalResult) + nQuestions = 2; + const chemicalResult = await executeSparqlQuery(chemicalElementQuery); + const chemicalElement = bindChemicalResults(chemicalResult) for (let i = 0; i < nQuestions; i++) { const question = generateQuestionChemical(chemicalElement); questions.push(question); } + // monuments + nQuestions = 2; + const monumentResult = await executeSparqlQuery(monumentQuery); + const monument = bindMonumentResults(monumentResult) + + for (let i = 0; i < nQuestions; i++) { + const question = generateQuestionMonument(monument); + questions.push(question); + } + // math questions - const mathquestions = await createMathQuestions(5) + const mathquestions = await createMathQuestions(3) questions.push(...mathquestions) res.json(questions); diff --git a/game/qgservice/generatorLogic/BindResults.js b/game/qgservice/generatorLogic/BindResults.js index a432738..25ecc42 100644 --- a/game/qgservice/generatorLogic/BindResults.js +++ b/game/qgservice/generatorLogic/BindResults.js @@ -29,7 +29,7 @@ function bindChemicalResults(queryResult){ queryResult.results.bindings.forEach(entry => { const elementLabel = entry.elementLabel.value; - const symbol = parseFloat(entry.symbol.value); + const symbol = entry.symbol.value; chemicalElementMap.set(symbol, elementLabel); }); @@ -41,7 +41,7 @@ function bindMonumentResults(queryResult){ queryResult.results.bindings.forEach(entry => { const monumentLabel = entry.monumentLabel.value; - const countryLabel = parseFloat(entry.countryLabel.value); + const countryLabel = entry.countryLabel.value; monumentMap.set(monumentLabel, countryLabel); }); diff --git a/game/qgservice/generatorLogic/questiongenerator.js b/game/qgservice/generatorLogic/questiongenerator.js index ac3fcf8..e259aa5 100644 --- a/game/qgservice/generatorLogic/questiongenerator.js +++ b/game/qgservice/generatorLogic/questiongenerator.js @@ -126,7 +126,7 @@ function generateQuestionMonument(monumentMap) { const randomMonument = monumentArray[Math.floor(Math.random() * monumentArray.length)]; const [randomMonumentLabel, randomCountry] = randomMonument; if (randomMonumentLabel !== monumentLabel && !incorrectAnswers.includes(randomCountry)) { - incorrectAnswers.push(random); + incorrectAnswers.push(randomCountry); } }