Skip to content

Commit

Permalink
Merge pull request #295 from Arquisoft/develop
Browse files Browse the repository at this point in the history
music questions
  • Loading branch information
Toto-hitori authored Apr 26, 2024
2 parents 6f754bf + 8436f27 commit 533004b
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/lab/en2b/quizapi/game/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private Question generateQuestionForGame(Game game){
if(question.isPresent()){
return question.get();
} else {
game.isGameOver();
game.setGameOver(true);
gameRepository.save(game);
throw new InternalApiErrorException("Could not find a question for the game");
}
Expand Down
Binary file added docs/images/wireframe-About.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-Dashboard-GameModes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-Dashboard-ResumeGame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-Dashboard-UserPanel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/wireframe-Dashboard.png
Binary file not shown.
Binary file added docs/images/wireframe-Results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wireframe-Statistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions docs/src/02_architecture_constraints.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,26 @@ The application must be developed according to some constraints that were define

image::wireframe-Root.png[align="center", title="Root Wireframe"]

image::wireframe-About.png[align="center", title="About Wireframe"]

image::wireframe-SignUp.png[align="center", title="Sign up Wireframe"]

image::wireframe-SignIn.png[align="center", title="Sign in Wireframe"]

image::wireframe-Dashboard.png[align="center", title="Dashboard Wireframe"]
image::wireframe-Dashboard-GameModes.png[align="center", title="Dashboard game modes Wireframe"]

image::wireframe-Dashboard-customGameMode.png[align="center", title="Dashboard custom game mode Wireframe"]

image::wireframe-Dashboard-UserPanel.png[align="center", title="Dashboard user panel Wireframe"]

image::wireframe-Dashboard-ResumeGame.png[align="center", title="Dashboard resume game Wireframe"]

image::wireframe-Rules.png[align="center", title="Rules Wireframe"]

image::wireframe-Game.png[align="center", title="Game Wireframe"]

image::wireframe-Menu.png[align="center", title="Menu Wireframe"]
image::wireframe-Statistics.png[align="center", title="Statistics Wireframe"]

image::wireframe-Menu.png[align="center", title="Menu Wireframe"]

image::wireframe-Results.png[align="center", title="Results Wireframe"]
5 changes: 5 additions & 0 deletions questiongenerator/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public static void main(String[] args) {
new BasketballVenueQuestion("es");
}

if (GeneralRepositoryStorer.doesntExist(AnswerCategory.SONG)) {
new MusicAuthorQuestion("en");
new MusicAuthorQuestion("es");
}


// IMAGES
if(GeneralRepositoryStorer.doesntExist(AnswerCategory.STADIUM)) {
Expand Down
95 changes: 95 additions & 0 deletions questiongenerator/src/main/java/templates/MusicAuthorQuestion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package templates;

import model.*;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MusicAuthorQuestion extends QuestionTemplate {


List<String> authorLabels;

private static final String[] spanishStringsIni = {"¿Quién es el autor de '", "¿Quién canta '", "¿Quién es el cantante de '", "¿Quién es el intérprete de '"};
private static final String[] englishStringsIni= {"Who is the author of '", "Who sings '", "Who is the singer of '", "Who is the performer of '"};

private static final String[] spanishStringsFin = {"'?", "'?", "'?", "'?"};
private static final String[] englishStringsFin = {"'?", "'?", "'?", "'?"};


public MusicAuthorQuestion(String langCode) {
super(langCode);
}

@Override
public void setQuery() {
this.sparqlQuery = "SELECT DISTINCT ?songLabel ?performerLabel ?awardLabel " +
"WHERE { " +
" ?song wdt:P31 wd:Q134556; " +
" wdt:P175 ?performer; " +
" p:P166 ?statement. " +
" ?statement ps:P166 ?award. " +
" SERVICE wikibase:label { " +
" bd:serviceParam wikibase:language \"en, es\"." +
" } " +
"}" +
"LIMIT 100";
}

@Override
public void processResults() {
authorLabels = new ArrayList<>();
List<Question> questions = new ArrayList<>();
List<Answer> answers = new ArrayList<>();

for (int i = 0; i < results.length(); i++) {
JSONObject result = results.getJSONObject(i);

String songLabel = "";
String performerLabel = "";

try {
JSONObject songObject = result.getJSONObject("songLabel");
songLabel = songObject.getString("value");

JSONObject performerLabelObject = result.getJSONObject("performerLabel");
performerLabel = performerLabelObject.getString("value");
} catch (Exception e) {
continue;
}

if (needToSkip(songLabel, performerLabel))
continue;

Answer a = new Answer(performerLabel, AnswerCategory.SONG, langCode);
answers.add(a);

String questionString = "";

if (langCode.equals("es"))
questionString = spanishStringsIni[i%4] + songLabel + spanishStringsFin[i%4];
else
questionString = englishStringsIni[i%4] + songLabel + englishStringsFin[i%4];

questions.add(new Question(a, questionString, QuestionCategory.MUSIC, QuestionType.TEXT));
}

repository.saveAll(new ArrayList<>(answers));
repository.saveAll(new ArrayList<>(questions));
}

private boolean needToSkip(String musicLabel, String genreLabel) {
if (authorLabels.contains(musicLabel)) {
return true;
}
authorLabels.add(musicLabel);

if (musicLabel.equals("") || genreLabel.equals(""))
return true;
if (QGHelper.isEntityName(musicLabel) || QGHelper.isEntityName(genreLabel))
return true;

return false;
}
}

0 comments on commit 533004b

Please sign in to comment.