generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from Arquisoft/develop
added tests for coverage and flag questions
- Loading branch information
Showing
15 changed files
with
600 additions
and
336 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
api/src/main/java/lab/en2b/quizapi/questions/answer/AnswerCategory.java
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,6 +1,6 @@ | ||
package lab.en2b.quizapi.questions.answer; | ||
|
||
public enum AnswerCategory { | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE, COUNTRY_FLAG | ||
} | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package model; | ||
|
||
public enum AnswerCategory { | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE | ||
CAPITAL_CITY, COUNTRY, SONG, STADIUM, BALLON_DOR, GAMES_PUBLISHER, PAINTING, WTPOKEMON, GAMES_COUNTRY, GAMES_GENRE, BASKETBALL_VENUE, COUNTRY_FLAG | ||
} | ||
|
77 changes: 77 additions & 0 deletions
77
questiongenerator/src/main/java/templates/CountryFlagQuestion.java
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,77 @@ | ||
package templates; | ||
|
||
import model.QuestionCategory; | ||
import model.QuestionType; | ||
import model.Answer; | ||
import model.AnswerCategory; | ||
import model.Question; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CountryFlagQuestion extends QuestionTemplate { | ||
|
||
private static final String[] spanishStringsIni = {"¿Que país tiene esta bandera? ", "¿A qué país pertenece esta bandera? ", "¿De qué país es esta bandera? ", "¿Cuál es el país de esta bandera? "}; | ||
private static final String[] englishStringsIni= {"Which country has this flag? ", "To which country belongs this flag? ", "From which country is this flag? ", "What is the country represented by this flag? "}; | ||
|
||
List<String> countryLabels; | ||
|
||
public CountryFlagQuestion(String langCode) { | ||
super(langCode); | ||
} | ||
|
||
@Override | ||
public void setQuery() { | ||
this.sparqlQuery = "SELECT ?countryLabel ?flagLabel\n" + | ||
"WHERE " + | ||
"{ " + | ||
" ?country wdt:P31 wd:Q6256; " + | ||
" wdt:P41 ?flag. " + | ||
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"" + langCode + "\". } " + | ||
"}"; | ||
} | ||
|
||
@Override | ||
public void processResults() { | ||
countryLabels = 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 countryLabel = result.getJSONObject("countryLabel").getString("value"); | ||
String flagLabel = result.getJSONObject("flagLabel").getString("value"); | ||
|
||
if (needToSkip(countryLabel, flagLabel)) { | ||
continue; | ||
} | ||
|
||
Answer a = new Answer(countryLabel, AnswerCategory.COUNTRY_FLAG, langCode); | ||
answers.add(a); | ||
|
||
if (langCode.equals("es")){ | ||
String questionString = spanishStringsIni[i%4] + QGHelper.LINKCONCAT + flagLabel; | ||
questions.add(new Question(a, questionString, QuestionCategory.GEOGRAPHY, QuestionType.IMAGE)); | ||
} else { | ||
String questionString = englishStringsIni[i%4] + QGHelper.LINKCONCAT + flagLabel; | ||
questions.add(new Question(a, questionString, QuestionCategory.GEOGRAPHY, QuestionType.IMAGE)); | ||
} | ||
} | ||
repository.saveAll(new ArrayList<>(answers)); | ||
repository.saveAll(new ArrayList<>(questions)); | ||
} | ||
|
||
private boolean needToSkip(String countryLabel, String venueLabel){ | ||
if (countryLabels.contains(countryLabel)) { | ||
return true; | ||
} | ||
countryLabels.add(countryLabel); | ||
|
||
if (QGHelper.isEntityName(countryLabel) || QGHelper.isEntityName(venueLabel)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,62 +1,62 @@ | ||
import React from "react"; | ||
import PropTypes from 'prop-types'; | ||
import { Button, Box } from "@chakra-ui/react"; | ||
import { FaKiwiBird, FaRandom, FaPalette } from "react-icons/fa"; | ||
import { TbWorld } from "react-icons/tb"; | ||
import { IoIosFootball, IoLogoGameControllerB } from "react-icons/io"; | ||
|
||
const DashboardButton = ({ label, selectedButton, onClick, iconName }) => { | ||
const isSelected = label === selectedButton; | ||
let icon = null; | ||
|
||
switch (iconName) { | ||
case "FaKiwiBird": | ||
icon = <FaKiwiBird style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "IoIosFootball": | ||
icon = <IoIosFootball style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "FaGlobeAmericas": | ||
icon = <TbWorld style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "IoLogoGameControllerB": | ||
icon = <IoLogoGameControllerB style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "FaPalette": | ||
icon = <FaPalette style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "FaRandom": | ||
icon = <FaRandom style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return ( | ||
<Button | ||
colorScheme={"green"} | ||
variant={isSelected ? "solid" : "ghost"} | ||
textAlign="center" | ||
m="1em" | ||
display="flex" | ||
flexDirection="column" | ||
alignItems="center" | ||
size="lg" | ||
height="4rem" | ||
maxW={{ base: "100%", md: "calc(100% / 3 - 2em)" }} | ||
onClick={() => onClick(label)} | ||
> | ||
{icon} | ||
<Box>{label}</Box> | ||
</Button> | ||
); | ||
}; | ||
|
||
DashboardButton.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
selectedButton: PropTypes.string.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
iconName: PropTypes.string.isRequired | ||
}; | ||
|
||
import React from "react"; | ||
import PropTypes from 'prop-types'; | ||
import { Button, Box } from "@chakra-ui/react"; | ||
import { FaKiwiBird, FaRandom, FaPalette } from "react-icons/fa"; | ||
import { TbWorld } from "react-icons/tb"; | ||
import { IoIosFootball, IoLogoGameControllerB } from "react-icons/io"; | ||
|
||
const DashboardButton = ({ label, selectedButton, onClick, iconName }) => { | ||
const isSelected = label === selectedButton; | ||
let icon = null; | ||
|
||
switch (iconName) { | ||
case "FaKiwiBird": | ||
icon = <FaKiwiBird data-testid={"FaKiwiBird"} style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "IoIosFootball": | ||
icon = <IoIosFootball data-testid={"IoIosFootball"} style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "FaGlobeAmericas": | ||
icon = <TbWorld data-testid={"FaGlobeAmericas"} style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "IoLogoGameControllerB": | ||
icon = <IoLogoGameControllerB data-testid={"IoLogoGameControllerB"} style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "FaPalette": | ||
icon = <FaPalette data-testid={"FaPalette"} style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
case "FaRandom": | ||
icon = <FaRandom data-testid={"FaRandom"} style={{ marginBottom: '0.5em', marginRight: '0.25em', fontSize: '1.8em' }} />; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return ( | ||
<Button | ||
colorScheme={"green"} | ||
variant={isSelected ? "solid" : "ghost"} | ||
textAlign="center" | ||
m="1em" | ||
display="flex" | ||
flexDirection="column" | ||
alignItems="center" | ||
size="lg" | ||
height="4rem" | ||
maxW={{ base: "100%", md: "calc(100% / 3 - 2em)" }} | ||
onClick={() => onClick(label)} | ||
> | ||
{icon} | ||
<Box>{label}</Box> | ||
</Button> | ||
); | ||
}; | ||
|
||
DashboardButton.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
selectedButton: PropTypes.string.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
iconName: PropTypes.string.isRequired | ||
}; | ||
|
||
export default DashboardButton; |
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
Oops, something went wrong.