/** A scenario the report says has too few deaths for a curve, with its counts and the minimum. */ export interface Insufficient { name: string; n?: number | null; deaths?: number | null; minimum?: number; } /** Her scenarios without a curve, apart: those the report lists as lacking deaths (with the numbers it * gives) and those it does not mention at all. */ export function sortUndrawn( report: Record | null | undefined, undrawn: string[], ): { insufficient: Insufficient[]; missing: string[] } { const listed = ( Array.isArray(report?.['escenarios_sin_curvas']) ? report['escenarios_sin_curvas'] : [] ) as { escenario?: string; n?: number | null; fallecidos?: number | null; }[]; const minimum = typeof report?.['min_fallecidos_escenario'] === 'number' ? report['min_fallecidos_escenario'] : undefined; const insufficient: Insufficient[] = []; const missing: string[] = []; for (const name of undrawn) { const found = listed.find((s) => s.escenario === name); if (found) insufficient.push({ name, n: found.n, deaths: found.fallecidos, minimum }); else missing.push(name); } return { insufficient, missing }; } /** What the section says of a scenario the report lists as lacking deaths; the numbers are the * report's and a missing one is left out, never replaced. */ export function insufficientText(u: Insufficient): string { const fmt = (v: number) => v.toLocaleString('es-MX'); const counts = [ typeof u.n === 'number' ? `n = ${fmt(u.n)}` : '', typeof u.deaths === 'number' ? `fallecidos = ${fmt(u.deaths)}` : '', ] .filter(Boolean) .join(', '); const details = [ counts, u.minimum !== undefined ? `mínimo requerido: ${fmt(u.minimum)} fallecidos` : '', ].filter(Boolean); return `Datos insuficientes para trazar la curva${details.length ? ` (${details.join('; ')})` : ''}.`; }