Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

130 añadir plantillas de preguntas #132

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
403 changes: 276 additions & 127 deletions questionservice/data/tematicas.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion questionservice/question-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ app.post("/questions", async (req, res) => {
const tematicasValidas =
temas.length !== 0
? temas
: ["paises", "literatura", "cine", "arte", "programacion"];
: ["paises", "literatura", "cine", "arte", "programacion", "futbolistas", "clubes", "baloncestistas", "politica", "videojuegos"];
const cantidadPreguntas = parseInt(n, 10);
const data = gen.getQuestionsPost(tematicasValidas, cantidadPreguntas, locale);
res.json(data);
Expand Down
46 changes: 26 additions & 20 deletions questionservice/questionGen/GenericGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ class GenericGenerator {
this.props
).join(" ")}
WHERE {
?entity wdt:P31 wd:${this.entity};
?entity ${this.entity};
${this.#generateProps(this.props)} .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es" }
}
LIMIT 10000
`;

const url = `https://query.wikidata.org/sparql?query=${encodeURIComponent(
sparqlQuery
)}&format=json`;
Expand Down Expand Up @@ -102,19 +102,19 @@ class GenericGenerator {

var respuestaCorrecta = "";
var propIndex = 0;
do{
do {
propIndex = Math.floor(Math.random() * propiedades.length);
var propiedadPregunta = propiedades[propIndex];

// Obtener la respuesta correcta
respuestaCorrecta =
entidad[propiedadPregunta][entidad[propiedadPregunta].length - 1];
}while(/^Q\d+/.test(respuestaCorrecta));
} while (/^Q\d+/.test(respuestaCorrecta));

var questionObj = {
pregunta: "",
respuestas: [respuestaCorrecta],
correcta: respuestaCorrecta
correcta: respuestaCorrecta,
};

// Obtener respuestas incorrectas
Expand All @@ -130,7 +130,6 @@ class GenericGenerator {
!entidad[propiedadPregunta].includes(prop) &&
!/^Q\d+/.test(prop) &&
entidadLabel != prop

) {
questionObj.respuestas.push(prop);
}
Expand All @@ -139,21 +138,26 @@ class GenericGenerator {
// Barajar las opciones de respuesta
questionObj.respuestas.sort(() => Math.random() - 0.5);

switch(this.types[propIndex]){
switch (this.types[propIndex]) {
case "date":
questionObj.respuestas = questionObj.respuestas.map(x => this.#dateFormatter(x));
questionObj.respuestas = questionObj.respuestas.map((x) =>
this.#dateFormatter(x)
);
questionObj.correcta = this.#dateFormatter(questionObj.correcta);
break;
case "num":
questionObj.respuestas = questionObj.respuestas.map(x => parseFloat(x).toFixed(2));
questionObj.respuestas = questionObj.respuestas.map((x) =>
parseFloat(x).toFixed(2)
);
questionObj.correcta = parseFloat(questionObj.correcta).toFixed(2);
break;
default:
break;
}
questionObj.pregunta =
this.preguntasMap.get(propiedadPregunta)[locale].replace('%', entidadLabel);

questionObj.pregunta = this.preguntasMap
.get(propiedadPregunta)
[locale].replace("%", entidadLabel);

return questionObj;
}

Expand All @@ -170,18 +174,20 @@ class GenericGenerator {

#dateFormatter(fecha) {
var isAC = false;
if(fecha.startsWith('-')){
isAC = true;
fecha = fecha.substring(1);
if (fecha.startsWith("-")) {
isAC = true;
fecha = fecha.substring(1);
}

const [año, mes, dia] = fecha.split('T')[0].split('-').map(n => Number.parseInt(n).toFixed());
const [año, mes, dia] = fecha
.split("T")[0]
.split("-")
.map((n) => Number.parseInt(n).toFixed());

const fechaFormateada = `${dia}/${mes}/${año}${isAC ? ' a.C.' : ''}`;

return fechaFormateada;
}
const fechaFormateada = `${dia}/${mes}/${año}${isAC ? " a.C." : ""}`;

return fechaFormateada;
}
}

module.exports = GenericGenerator;
2 changes: 1 addition & 1 deletion users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ app.post("/saveGameList", async (req, res) => {
}
const gameDataWithGamemode = { ...gameData, gamemode, questions };

if(gamemode!=="classic" && gamemode!=="bateria" && gamemode!=="calculadora"){
if(gamemode!=="clasico" && gamemode!=="bateria" && gamemode!=="calculadora"){
return res.status(422).json({ error: "Invalid gamemode" });
}

Expand Down
4 changes: 2 additions & 2 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("User Service", () => {
// Datos de la partida a guardar
const gameData = {
username: "testuser",
gameMode: "classic",
gameMode: "clasico",
gameData: {
points: 100,
correctAnswers: 8,
Expand All @@ -115,7 +115,7 @@ describe("User Service", () => {
// Datos de la partida a guardar
const gameData = {
username: "testuseraaa",
gameMode: "classic",
gameMode: "clasico",
gameData: {
points: 100,
correctAnswers: 8,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const root = ReactDOM.createRoot(r);

localStorage.setItem(
"selectedThemes",
JSON.stringify(["paises", "literatura", "cine", "arte", "programacion"])
JSON.stringify(["paises", "literatura", "cine", "arte", "programacion", "futbolistas", "clubes", "baloncestistas", "politica", "videojuegos"])
);
localStorage.setItem("clasicoTime", 10);
localStorage.setItem("clasicoPreguntas", 10);
Expand Down
5 changes: 5 additions & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
"cinema": "Cinema",
"art": "Art",
"programming": "Programming",
"futbolistas": "Football players",
"clubes": "Footbal clubs",
"baloncestistas": "Basketball players",
"politica": "Politics",
"videojuegos": "Videogames",
"save": "Apply Changes",
"timeBetweenClassic": "Time Between Questions (Classic)",
"questionCountClassic": "Number of Questions (Classic)",
Expand Down
5 changes: 5 additions & 0 deletions webapp/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
"cinema": "Cine",
"art": "Arte",
"programming": "Programación",
"futbolistas": "Futbolistas",
"clubes": "Clubes de fútbol",
"baloncestistas": "Jugadores de baloncesto",
"politica": "Política",
"videojuegos": "Videojuegos",
"save": "Aplicar cambios",
"timeBetweenClassic": "Tiempo entre preguntas (Clásico)",
"questionCountClassic": "Número de preguntas (Clásico)",
Expand Down
89 changes: 53 additions & 36 deletions webapp/src/pages/Config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";

const Config = () => {
const { t, i18n} = useTranslation();
const { t, i18n } = useTranslation();

useEffect(() => {
// Obtener el estado de los checkboxes desde el localStorage
Expand Down Expand Up @@ -86,45 +86,62 @@ const Config = () => {
<>
<Nav />
<Flex direction="column" align="center" justify="center">
<Box className="configContainer">
<Box className="configContainer" maxW={"80%"}>
<Heading as="h2" mb={4}>
{t('pages.config.title')}
{t("pages.config.title")}
</Heading>
<FormLabel htmlFor="idioma">{t('pages.config.language')}</FormLabel>
<FormLabel htmlFor="idioma">{t("pages.config.language")}</FormLabel>
<Flex direction="row" align="center" justify="space-around">
<Button colorScheme="teal" onClick={() => i18n.changeLanguage("es")}>Español</Button>
<Button colorScheme="teal" onClick={() => i18n.changeLanguage("en")}>English</Button>
<Button
colorScheme="teal"
onClick={() => i18n.changeLanguage("es")}
>
Español
</Button>
<Button
colorScheme="teal"
onClick={() => i18n.changeLanguage("en")}
>
English
</Button>
</Flex>
<FormLabel htmlFor="clasico">{t('pages.config.topics')}</FormLabel>
<Box
display="grid"
gridTemplateColumns="repeat(auto-fit, minmax(150px, 1fr))"
gridGap={4}
alignItems="start"
>
<Stack spacing={5} direction="row">
<Checkbox id="paises" mb={2}>
{t('pages.config.countries')}
</Checkbox>
<Checkbox id="literatura" mb={2}>
{t('pages.config.literature')}
</Checkbox>
<Checkbox id="cine" mb={2}>
{t('pages.config.cinema')}
</Checkbox>
<Checkbox id="arte" mb={2}>
{t('pages.config.art')}
</Checkbox>
<Checkbox id="programacion" mb={2}>
{t('pages.config.programming')}
</Checkbox>
</Stack>
</Box>

<FormLabel htmlFor="clasico">{t("pages.config.topics")}</FormLabel>
<Stack spacing={5} direction="row" wrap={"wrap"} justifyContent={"center"}>
<Checkbox id="paises" mb={2}>
{t("pages.config.countries")}
</Checkbox>
<Checkbox id="literatura" mb={2}>
{t("pages.config.literature")}
</Checkbox>
<Checkbox id="cine" mb={2}>
{t("pages.config.cinema")}
</Checkbox>
<Checkbox id="arte" mb={2}>
{t("pages.config.art")}
</Checkbox>
<Checkbox id="programacion" mb={2}>
{t("pages.config.programming")}
</Checkbox>
<Checkbox id="futbolistas" mb={2}>
{t("pages.config.futbolistas")}
</Checkbox>
<Checkbox id="clubes" mb={2}>
{t("pages.config.clubes")}
</Checkbox>
<Checkbox id="baloncestistas" mb={2}>
{t("pages.config.baloncestistas")}
</Checkbox>
<Checkbox id="politica" mb={2}>
{t("pages.config.politica")}
</Checkbox>
<Checkbox id="videojuegos" mb={2}>
{t("pages.config.videojuegos")}
</Checkbox>
</Stack>
<Box>
<FormLabel htmlFor="clasico">
{" "}
{t('pages.config.timeBetweenClassic')}
{t("pages.config.timeBetweenClassic")}
</FormLabel>
<NumberInput
id="clasico"
Expand All @@ -143,7 +160,7 @@ const Config = () => {
</NumberInput>
<FormLabel htmlFor="clasicoPreguntas">
{" "}
{t('pages.config.questionCountClassic')}
{t("pages.config.questionCountClassic")}
</FormLabel>
<NumberInput
id="clasicoPreguntas"
Expand All @@ -161,7 +178,7 @@ const Config = () => {
</NumberInputStepper>
</NumberInput>
<FormLabel htmlFor="bateria">
{t('pages.config.totalTimeBattery')}
{t("pages.config.totalTimeBattery")}
</FormLabel>
<NumberInput
id="bateria"
Expand All @@ -180,7 +197,7 @@ const Config = () => {
</NumberInput>
</Box>
<Button colorScheme="teal" onClick={handleConfig} mb={4}>
{t('pages.config.save')}
{t("pages.config.save")}
</Button>
</Box>
</Flex>
Expand Down