fixed antiguedad perifericos

This commit is contained in:
2026-01-23 15:31:33 -06:00
parent 8f8269e5cc
commit 9dcfa91095
+22 -22
View File
@@ -29,47 +29,47 @@ export default function Pregunta7() {
const api_url = process.env.NEXT_PUBLIC_API_URL;
// ------------------------------
// TRANSFORMADOR (maneja null)
// ------------------------------
const transformarDatos = (items: AntiguedadItem[]): string[] => {
let menores2 = 0;
let menor2 = 0;
let entre2_3 = 0;
let entre4_5 = 0;
let mayores6 = 0;
let notfound = 0;
let mayor6 = 0;
for (const item of items) {
const total = Number(item.total) || 0;
const antig = item.antiguedad
? item.antiguedad.toUpperCase().trim()
: null;
const antig = item.antiguedad?.toLowerCase().trim();
switch (antig) {
case "MENORES DE 2":
menores2 += total;
case "menor a 2 años":
menor2 += total;
break;
case "ENTRE 2 Y 3":
case "entre 2 y 3 años":
entre2_3 += total;
break;
case "ENTRE 4 Y 5":
case "entre 4 y 5 años":
entre4_5 += total;
break;
case "ENTRE 6 Y MAYORES":
mayores6 += total;
case "mayor a 6 años":
mayor6 += total;
break;
default:
notfound += total; // incluye null
}
}
const total = menores2 + entre2_3 + entre4_5 + mayores6 + notfound;
const suma = menor2 + entre2_3 + entre4_5 + mayor6;
if (total === 0) return ["0.00", "0.00", "0.00", "0.00"];
if (suma === 0) return ["0.00", "0.00", "0.00", "0.00"];
const pct = (v: number) => ((v / total) * 100).toFixed(2);
const pct = (v: number) => ((v / suma) * 100).toFixed(2);
return [pct(menores2), pct(entre2_3), pct(entre4_5), pct(mayores6)];
return [
pct(menor2), // Menor a 2
pct(entre2_3), // Entre 2 y 3
pct(entre4_5), // Entre 4 y 5
pct(mayor6), // Mayor a 6
];
};
const cargarDatos = async (baja: boolean) => {
@@ -83,7 +83,7 @@ export default function Pregunta7() {
body,
{
headers: { Authorization: `Bearer ${token}` },
}
},
)
.then((res) => {
const { impresion, digitalizacion } = res.data;