Ajustar indicadores, fecha de corte y ficha de CaMa y CaCu

This commit is contained in:
2026-12-03 19:33:13 -06:00
parent 0fe772ed6f
commit cbcb524902
18 changed files with 333 additions and 120 deletions
+58 -5
View File
@@ -16,6 +16,7 @@ export type Mode = {
kind: 'counts';
measure: string;
catalog: Category[];
aggregate?: { label: string; color: string; codes: string[] };
/** The records counted in the category distribution. */
unit?: string;
/** What the share in the second column is a share of. */
@@ -54,6 +55,7 @@ export type Mode = {
measure: string;
/** the categories drawn in each group, in this order (each in its own colour) */
catalog: Category[];
aggregate?: { label: string; color: string; codes: string[] };
/** the groups' stratifier (its crossed cells `<stratum>-category`) and their order */
stratum: string;
order: string[];
@@ -262,10 +264,23 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
const most = mode.percent ? total : Math.max(...Object.values(cells).map(size));
return {
head: [mode.unit ?? 'n', mode.percentLabel ?? 'Porcentaje'],
rows: all.map(({ code, label, color }) => {
rows: all.flatMap(({ code, label, color }, index) => {
const n = size(cells[code]);
const cols = [`${n}`, pct(n, total)];
return { label, color, width: (100 * n) / most, marks: [], cells: cols };
const row = { label, color, width: (100 * n) / most, marks: [], cells: cols };
if (index !== 0 || !mode.aggregate) return [row];
const a = mode.aggregate;
const sum = a.codes.reduce((total, key) => total + size(cells[key]), 0);
return [
row,
{
label: a.label,
color: a.color,
width: (100 * sum) / most,
marks: [],
cells: [`${sum}`, pct(sum, total)],
},
];
}),
note: hiddenNote(mode, of),
};
@@ -433,6 +448,24 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
}
}
/** Reported form answers within the subsequent round, over that round's own total. */
export function subsequentHistory(reading?: Reading) {
const values = reading?.strata['subsequent_history'];
const den = reading?.strata['round']?.['subsequent']?.['initial-population'] ?? 0;
if (!values) return undefined;
return [
['within_1_year', 'Un año o menos'],
['2_years', 'Dos años'],
['3_or_more_years', 'Tres o más años'],
].map(([code, label]) => {
const count = values[code]?.['initial-population'] ?? 0;
return {
label,
text: `${count}/${den} · ${den ? ((100 * count) / den).toFixed(1) + ' %' : '—'}`,
};
});
}
/** The groups of a grouped mode: each group (an age group, a follow-up status, a screening round) with
* one independent bar per category over the group's own records. A group the report leaves out is
* drawn empty only when the listed ones add up to every record of the period (`complete`). */
@@ -464,13 +497,18 @@ export function grouped(
const den = total(code);
return {
code,
label: name(code),
label:
mode.stratum === 'age_group' &&
code === '<25' &&
['CACU_EU7', 'CACU_VPH_GENOTIPO'].includes(mode.measure)
? '14 años y 10 meses a menos de 25 años'
: name(code),
total: den,
hint: den ? undefined : `Sin ${mode.unit} en el grupo`,
rows: mode.catalog.map((c) => {
rows: mode.catalog.flatMap((c, index) => {
const count = n(code, c.code);
const percent = den ? (100 * count) / den : undefined;
return {
const row = {
label: c.label,
color: c.color,
count,
@@ -478,6 +516,21 @@ export function grouped(
percent,
text: `${count}/${den} · ${percent === undefined ? '—' : percent.toFixed(1) + ' %'}`,
};
if (index !== 0 || !mode.aggregate) return [row];
const a = mode.aggregate;
const sum = a.codes.reduce((total, key) => total + n(code, key), 0);
const share = den ? (100 * sum) / den : undefined;
return [
row,
{
label: a.label,
color: a.color,
count: sum,
of: den,
percent: share,
text: `${sum}/${den} · ${share === undefined ? '—' : share.toFixed(1) + ' %'}`,
},
];
}),
};
});