forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Develop' into question_generator
- Loading branch information
Showing
8 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters