Skip to content

Commit

Permalink
Correccion formato números
Browse files Browse the repository at this point in the history
  • Loading branch information
uo287998 committed Mar 30, 2024
1 parent d8b317e commit 768521c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion preguntas/generatorservice/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P2046 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
},
{
"question": "¿Cuál es la suerficie ocupada por el ^ en kilómetros cuadrados (km2)?",
"question": "¿Cuál es la superficie ocupada por el ^ en kilómetros cuadrados (km2)?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q165. ?p wdt:P2046 ?r. FILTER (?r > 800000) FILTER (STR(?p) != 'http://www.wikidata.org/entity/Q3240274') SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". }}"

},
Expand Down
25 changes: 24 additions & 1 deletion preguntas/generatorservice/question-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ app.get('/generate-question', async (req, res) => {
// Add pLabel to question string from template
const question = template.question.replace('^', correctAnswer.pLabel);

//Cambio de formato de numero. Se intenta hacer más legible
if (question.includes('superficie') || question.includes('área')) {
correctAnswer.rLabel = await formatoNumero(correctAnswer.rLabel);
for (let i = 0; i < allAnswers.length; i++) {
allAnswers[i] = await formatoNumero(allAnswers[i]);
}
}

// Create a new question
const newQuestion = new Question({
question: question,
Expand Down Expand Up @@ -148,4 +156,19 @@ function getThumbUrl(originalUrl, width) {
"/commons/", "/commons/thumb/").replace(".svg", ".png") + "/"+ width +"px-" + filename;
return thumbnailUrl;
}*/
}*/

//Funcion de formateo de numeros
async function formatoNumero(numero) {
// Convertir el número a string y reemplazar puntos por comas
let numeroStr = numero.toString().replace('.', ',');

// Separar la parte entera de la decimal
let partes = numeroStr.split(',');

// Formatear la parte entera con puntos cada 3 dígitos
partes[0] = partes[0].replace(/\B(?=(\d{3})+(?!\d))/g, '.');

// Unir las partes nuevamente
return partes.join(',');
}

0 comments on commit 768521c

Please sign in to comment.