Skip to content

Commit

Permalink
Merge branch 'Develop' into question_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
UO287687 committed Mar 23, 2024
2 parents 9adf27c + a22846d commit 0fb454b
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ This repo is a basic application composed of several components.

Both the user and auth service share a Mongo database that is accessed with mongoose.

App Link: http://172.187.201.54:3000/

## Quick start guide

### Using docker
Expand Down
2 changes: 1 addition & 1 deletion question_generator/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"Who has more followers?": "Who has more followers?",
"Who has more looses?": "Who has more looses?",
"Who has more wins?": "Who has more wins?",
"Which player is from?" : "Which player is from %s?"
"Which tennis player is from?" : "Which tennis player is from %s?"
}
2 changes: 1 addition & 1 deletion question_generator/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"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?",
"Which player is from?" : "¿Qué jugador es de %s?"
"Which tennis player is from?" : "¿Qué jugador es de %s?"

}
71 changes: 71 additions & 0 deletions question_generator/sports/football/footballQuestions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const queryExecutor=require("../../queryExecutor")
class FootballQuestions{
#tennisQuestions=null;
static getInstance(){
if (!this.questions) {
this.questions = new FootballQuestions();
}
return this.questions;
}
constructor(){
this.teams={}
}
async loadData(){
if (Object.keys(this.teams).length === 0) {//Se obtienen 100 ciudades relevantes
const query=
`
SELECT DISTINCT ?equipo ?paisLabel ?equipoLabel ?entrenadorLabel ?followers ?estadioLabel
WHERE {
?equipo wdt:P31 wd:Q476028; # Instancia de equipo de fútbol
OPTIONAL {?equipo wdt:P17 ?pais }
OPTIONAL {?equipo wdt:P286 ?entrenador }
OPTIONAL {?equipo wdt:P8687 ?followers }
OPTIONAL {?equipo wdt:P115 ?estadio }
FILTER (BOUND(?entrenador))
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?followers)
LIMIT 250
`
let teams = await queryExecutor.execute(query);
teams.forEach(tenista => {
const playerId = tenista.tenista.value;
const playerName = tenista.tenistaLabel.value;
const followers = tenista.followers.value;
const country = tenista.paisLabel.value;
const record = tenista.victorias.value;

const recordAux = record ? record.split("-") : ['', ''];
const wins = recordAux[0];
const looses = recordAux[1];

if (!this.teams[playerId]) {
this.teams[playerId] = {
playerId: playerId,
playerName: playerName,
followers: followers,
country: country,
wins: wins,
looses: looses
};
}
});
}
}
async getRandomPlayer(number){
await this.loadData();
const array = Object.values(this.data);
const randomResults = array.sort(() => Math.random() - 0.5).slice(0, number);
return randomResults
}
async getPlayerWithMoreGrandSlams() {
const results=await this.getRandomPlayer(4);
//...
return {
correct: "Rafa Nadal",
incorrects: ["Persona 2", "Persona 3"]
}
}

}
module.exports = FootballQuestions;
18 changes: 18 additions & 0 deletions question_generator/sports/football/footballTemplates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const footballQuestions=require('./footballQuestions');
const footballQuery=footballQuestions.getInstance();
function loadData(){
footballQuery.loadData();
}
const templates=[
async ()=>
{
const results = await footballQuery.getPlayerWithMoreGrandSlams();
return{
"question":"Who has more followers? (Tennis)",
"correct":results.correct,
"incorrects":results.incorrects
}
}
]
module.exports.getRandomQuestion = () => templates[Math.floor(Math.random()*templates.length)]();
module.exports.loadData = ()=>loadData();
5 changes: 3 additions & 2 deletions question_generator/sports/sportTemplate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const tennisTemplates=require('./tennis/tennisTemplates');
function loadData(){
tennisTemplates.loadData()
// footballTemplates.loadData()
}
const templates=[
tennisTemplates.getRandomQuestion

tennisTemplates.getRandomQuestion//,
// footballTemplates.getRandomQuestion
]
module.exports.getRandomQuestion = () => templates[Math.floor(Math.random()*templates.length)]();
module.exports.loadData = ()=>loadData();
4 changes: 1 addition & 3 deletions question_generator/sports/tennis/tennisQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ class TennisQuestions{
SELECT DISTINCT ?tenista ?tenistaLabel ?pais ?paisLabel ?victorias ?followers
WHERE {
?tenista wdt:P106 wd:Q10833314.
OPTIONAL { ?tenista wdt:P1532 ?pais. }
OPTIONAL { ?tenista wdt:P564 ?victorias. }
OPTIONAL { ?tenista wdt:P8687 ?followers. }
FILTER (BOUND(?victorias) && BOUND(?pais) && BOUND(?followers))
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?followers)
LIMIT 200
LIMIT 100
`
let players = await queryExecutor.execute(query);
players.forEach(tenista => {
Expand All @@ -33,7 +32,6 @@ class TennisQuestions{
const followers = tenista.followers.value;
const country = tenista.paisLabel.value;
const record = tenista.victorias.value;

const recordAux = record ? record.split("-") : ['', ''];
const wins = recordAux[0];
const looses = recordAux[1];
Expand Down
9 changes: 5 additions & 4 deletions question_generator/sports/tennis/tennisTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const templates=[
{
const results = await tennisQuery.getPlayerWithMoreFollowers();
return{
"question":"Who has more followers?",
"question":"Who has more followers? (Tennis)",
"correct":results.correct,
"incorrects":results.incorrects
}
Expand All @@ -17,7 +17,8 @@ const templates=[
{
const results = await tennisQuery.getPlayerForCountry();
return{
"question":"Which player is from?",

"question":"Which tennis player is from?",
"question_param":results.country,
"correct":results.correct,
"incorrects":results.incorrects
Expand All @@ -27,7 +28,7 @@ const templates=[
{
const results = await tennisQuery.getPlayerWithMoreWins();
return{
"question":"Who has more wins?",
"question":"Who has more wins? (Tennis)",
"correct":results.correct,
"incorrects":results.incorrects
}
Expand All @@ -36,7 +37,7 @@ const templates=[
{
const results = await tennisQuery.getPlayerWithMoreLooses();
return{
"question":"Who has more looses?",
"question":"Who has more looses? (Tennis)",
"correct":results.correct,
"incorrects":results.incorrects
}
Expand Down

0 comments on commit 0fb454b

Please sign in to comment.