Skip to content

Commit

Permalink
Merge branch 'develop' into documentation_final_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelMH1 committed May 3, 2024
2 parents 897b853 + c018349 commit 521215f
Show file tree
Hide file tree
Showing 17 changed files with 4,414 additions and 1,057 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
- run: npm --prefix gameservice test -- --coverage
- run: npm --prefix apisgatewayservice test -- --coverage
- run: npm --prefix questionsservice/questiongeneratorservice test -- --coverage
# - run: npm --prefix questionsservice/wikidataExtractor test -- --coverage
- run: npm --prefix questionsservice/wikidataExtractor test -- --coverage

- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- run: npm --prefix gameservice test -- --coverage
- run: npm --prefix apisgatewayservice test -- --coverage
- run: npm --prefix questionsservice/questiongeneratorservice test -- --coverage
# - run: npm --prefix questionsservice/wikidataExtractor test -- --coverage
- run: npm --prefix questionsservice/wikidataExtractor test -- --coverage

- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
Expand Down Expand Up @@ -69,16 +69,17 @@ jobs:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
env:
API_URI: http://${{ secrets.DEPLOY_HOST }}:8000
with:
name: arquisoft/wiq_es6c/webapp
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: webapp
buildargs: API_URI
buildargs: API_URI1, API_URI2
platforms: linux/arm64
env:
API_URI1: http://${{ secrets.DEPLOY_HOST }}:8000
API_URI2: http://${{ secrets.DEPLOY_HOST }}:8100
docker-push-authservice:
name: Push auth service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ services:
build: ./webapp
depends_on:
- gatewayservice
- apisgatewayservice
ports:
- "3000:3000"
restart: always
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const cors = require('cors');
const axios = require('axios');
const mongooseUri = (process.env.DATAMODELS_URI === undefined) ? '../node_modules/mongoose' : 'mongoose';
const mongoose = require(mongooseUri);
const { QuestionGenerator } = require('./questiongenerator')
const { QuestionGenerator } = require('./questiongenerator');

const app = express();
const port = 8007;
Expand Down
43 changes: 28 additions & 15 deletions questionsservice/questiongeneratorservice/questiongenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QuestionGenerator {
generateMethod: (plantilla, respuestas) => this.generateQuestionNonDuplicatedAnswers(plantilla, respuestas),
pregunta: (param) => `¿En qué continente se situa ${param}?`,
filtro: { pais: { $exists: true }, continente: { $exists: true } },
filtro_decoys: (answer) => { return { pais: { $exists: true }, continente: { $exists: true, $ne: answer.continente} }},
filtro_decoys: (answer) => { return { pais: { $exists: true }, continente: { $exists: true, $ne: answer.continente } } },
campo_pregunta: 'pais',
campo_respuesta: 'continente'
},
Expand All @@ -45,7 +45,7 @@ class QuestionGenerator {
generateMethod: (plantilla, respuestas) => this.generateQuestionNonDuplicatedAnswers(plantilla, respuestas),
pregunta: (param) => `¿Cual de los siguientes paises se situa en ${param}?`,
filtro: { pais: { $exists: true }, continente: { $exists: true } },
filtro_decoys: (answer) => { return { pais: { $exists: true }, continente: { $exists: true, $ne: answer.continente} }},
filtro_decoys: (answer) => { return { pais: { $exists: true }, continente: { $exists: true, $ne: answer.continente } } },
campo_pregunta: 'continente',
campo_respuesta: 'pais'
},
Expand All @@ -54,7 +54,7 @@ class QuestionGenerator {
generateMethod: (plantilla, respuestas) => this.generateQuestionNonDuplicatedAnswers(plantilla, respuestas),
pregunta: (param) => `¿En qué país se situa la atracción turística "${param}"?`,
filtro: { pais: { $exists: true }, monumento: { $exists: true } },
filtro_decoys: (answer) => { return { monumento: { $exists: true }, pais: { $exists: true, $ne: answer.pais} }},
filtro_decoys: (answer) => { return { monumento: { $exists: true }, pais: { $exists: true, $ne: answer.pais } } },
campo_pregunta: 'monumento',
campo_respuesta: 'pais'
},
Expand All @@ -63,7 +63,7 @@ class QuestionGenerator {
generateMethod: (plantilla, respuestas) => this.generateQuestionNonDuplicatedAnswers(plantilla, respuestas),
pregunta: (param) => `¿Cuál de las siguientes atraccioones turísticas se encuentra en ${param}?`,
filtro: { pais: { $exists: true }, monumento: { $exists: true } },
filtro_decoys: (answer) => { return { monumento: { $exists: true }, pais: { $exists: true, $ne: answer.pais} }},
filtro_decoys: (answer) => { return { monumento: { $exists: true }, pais: { $exists: true, $ne: answer.pais } } },
campo_pregunta: 'pais',
campo_respuesta: 'monumento'
},
Expand All @@ -88,7 +88,7 @@ class QuestionGenerator {
generateMethod: (plantilla, respuestas) => this.generateQuestionNonDuplicatedAnswers(plantilla, respuestas),
pregunta: (param) => `¿Quién fue el director de la película "${param}"?`,
filtro: { pelicula: { $exists: true }, director: { $exists: true } },
filtro_decoys: (answer) => { return { pelicula: { $exists: true }, director: { $exists: true, $ne: answer.director} }},
filtro_decoys: (answer) => { return { pelicula: { $exists: true }, director: { $exists: true, $ne: answer.director } } },
campo_pregunta: 'pelicula',
campo_respuesta: 'director'
},
Expand All @@ -97,7 +97,7 @@ class QuestionGenerator {
generateMethod: (plantilla, respuestas) => this.generateQuestionNonDuplicatedAnswers(plantilla, respuestas),
pregunta: (param) => `¿Cuál de estas películas ha sido dirigida por "${param}"?`,
filtro: { pelicula: { $exists: true }, director: { $exists: true } },
filtro_decoys: (answer) => { return { pelicula: { $exists: true }, director: { $exists: true, $ne: answer.director} }},
filtro_decoys: (answer) => { return { pelicula: { $exists: true }, director: { $exists: true, $ne: answer.director } } },
campo_pregunta: 'director',
campo_respuesta: 'pelicula'
},
Expand All @@ -106,7 +106,7 @@ class QuestionGenerator {
generateMethod: (plantilla, respuestas) => this.generateQuestionNonDuplicatedAnswers(plantilla, respuestas),
pregunta: (param) => `¿Quién canta la canción "${param}"?`,
filtro: { cancion: { $exists: true }, artista: { $exists: true } },
filtro_decoys: (answer) => { return { cancion: { $exists: true }, artista: { $exists: true, $ne: answer.artista} }},
filtro_decoys: (answer) => { return { cancion: { $exists: true }, artista: { $exists: true, $ne: answer.artista } } },
campo_pregunta: 'cancion',
campo_respuesta: 'artista'
},
Expand All @@ -115,7 +115,7 @@ class QuestionGenerator {
generateMethod: (plantilla, respuestas) => this.generateQuestionNonDuplicatedAnswers(plantilla, respuestas),
pregunta: (param) => `¿Cuál de las siguientes canciones es interpretada por "${param}"?`,
filtro: { cancion: { $exists: true }, artista: { $exists: true } },
filtro_decoys: (answer) => { return { cancion: { $exists: true }, artista: { $exists: true, $ne: answer.artista} }},
filtro_decoys: (answer) => { return { cancion: { $exists: true }, artista: { $exists: true, $ne: answer.artista } } },
campo_pregunta: 'artista',
campo_respuesta: 'cancion'
}
Expand All @@ -136,8 +136,8 @@ class QuestionGenerator {
// }
];

static getAvailableTopics(){
return [ ...this.temas.keys() ];
static getAvailableTopics() {
return [...this.temas.keys()];
}


Expand All @@ -151,21 +151,21 @@ class QuestionGenerator {
throw new Error(`Not enought data found to generate a question`);
}
let randomDecoys = [];
if (respuestas > 1){
if (respuestas > 1) {
randomDecoys = await plantilla.modelo.aggregate([
{ $match: plantilla.filtro_decoys(randomAnswer[0]) },
{ $sample: { size: respuestas-1 } }
{ $sample: { size: respuestas - 1 } }
]);
}
if (randomDecoys.length < respuestas-1) {
if (randomDecoys.length < respuestas - 1) {
console.error(`Not enought data found to generate a question`);
throw new Error(`Not enought data found to generate a question`);
}

const retQuestion = {
pregunta: plantilla.pregunta(randomAnswer[0][plantilla.campo_pregunta]),
respuesta_correcta: randomAnswer[0][plantilla.campo_respuesta],
respuestas_incorrectas: Array.from({ length: respuestas-1 }, (_, i) => randomDecoys[i][plantilla.campo_respuesta])
respuestas_incorrectas: Array.from({ length: respuestas - 1 }, (_, i) => randomDecoys[i][plantilla.campo_respuesta])
};
return retQuestion;
}
Expand All @@ -183,7 +183,7 @@ class QuestionGenerator {
const retQuestion = {
pregunta: plantilla.pregunta(randomDocs[0][plantilla.campo_pregunta]),
respuesta_correcta: randomDocs[0][plantilla.campo_respuesta],
respuestas_incorrectas: Array.from({ length: respuestas-1 }, (_, i) => randomDocs[i+1][plantilla.campo_respuesta])
respuestas_incorrectas: Array.from({ length: respuestas - 1 }, (_, i) => randomDocs[i + 1][plantilla.campo_respuesta])
};
return retQuestion;
}
Expand All @@ -196,6 +196,7 @@ class QuestionGenerator {
let plantilla = this.plantillas[plantillasDisponibles[index]];
retQuestions.push(await plantilla.generateMethod(plantilla, respuestas));
}
this.easterEgg(plantillasDisponibles, retQuestions);
console.log("\nPreguntas generadas:");
console.log(retQuestions);
return retQuestions;
Expand Down Expand Up @@ -228,6 +229,18 @@ class QuestionGenerator {
return [...new Set(templates)];
}

static easterEgg(plantillasDisponibles, retQuestions) {
if (plantillasDisponibles.includes(10)){
for(let question of retQuestions) {
if (question.pregunta.includes('Quién canta la canción')) {
question.pregunta = '¿Quién es el famoso batería del grupo Kactus Jack?';
question.respuesta_correcta = 'Jose Emilio Labra Gayo';
return;
}
}
}
}

}

module.exports = {
Expand Down
Loading

0 comments on commit 521215f

Please sign in to comment.