diff --git a/README.md b/README.md index 25b02d26..e64cc4fe 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/question_generator/locales/en.json b/question_generator/locales/en.json index 705fbbb7..101c0fa6 100644 --- a/question_generator/locales/en.json +++ b/question_generator/locales/en.json @@ -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?" } \ No newline at end of file diff --git a/question_generator/locales/es.json b/question_generator/locales/es.json index d743a949..b904a594 100644 --- a/question_generator/locales/es.json +++ b/question_generator/locales/es.json @@ -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?" } \ No newline at end of file diff --git a/question_generator/sports/football/footballQuestions.js b/question_generator/sports/football/footballQuestions.js new file mode 100644 index 00000000..38eefdff --- /dev/null +++ b/question_generator/sports/football/footballQuestions.js @@ -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; \ No newline at end of file diff --git a/question_generator/sports/football/footballTemplates.js b/question_generator/sports/football/footballTemplates.js new file mode 100644 index 00000000..65c3b852 --- /dev/null +++ b/question_generator/sports/football/footballTemplates.js @@ -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(); \ No newline at end of file diff --git a/question_generator/sports/sportTemplate.js b/question_generator/sports/sportTemplate.js index 21af6e9d..b279f524 100644 --- a/question_generator/sports/sportTemplate.js +++ b/question_generator/sports/sportTemplate.js @@ -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(); \ No newline at end of file diff --git a/question_generator/sports/tennis/tennisQuestions.js b/question_generator/sports/tennis/tennisQuestions.js index 3897e87e..daf42e45 100644 --- a/question_generator/sports/tennis/tennisQuestions.js +++ b/question_generator/sports/tennis/tennisQuestions.js @@ -16,7 +16,6 @@ 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. } @@ -24,7 +23,7 @@ class TennisQuestions{ 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 => { @@ -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]; diff --git a/question_generator/sports/tennis/tennisTemplates.js b/question_generator/sports/tennis/tennisTemplates.js index 21042644..89556306 100644 --- a/question_generator/sports/tennis/tennisTemplates.js +++ b/question_generator/sports/tennis/tennisTemplates.js @@ -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 } @@ -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 @@ -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 } @@ -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 }