Nombrar la detección anterior y encadenar los tiempos de CaMa hasta el tratamiento

This commit is contained in:
2026-12-04 05:49:56 -06:00
parent 972bdf0d8a
commit e31c128991
8 changed files with 75 additions and 54 deletions
+27 -5
View File
@@ -5,6 +5,8 @@ import { Reading } from './measures';
export interface RouteStep {
label: string;
measure?: string;
/** the step (its position) this one starts after; the previous one by default */
after?: number;
}
/** One row of a duration table: the median days, how many measurements and the quartiles.
@@ -17,6 +19,25 @@ export interface DurationRow {
observations?: number;
low?: number;
high?: number;
after?: number;
/** where its bar starts, in days, when the steps are chained */
start?: number;
}
/** Where each step's bar starts when drawn as a schematic sequence (a Gantt chart): where the
* step it follows ends. A step without a median moves nothing after it. */
export function chainStarts(steps: { median?: number; after?: number }[]): number[] {
const starts: number[] = [];
steps.forEach(({ after }, i) => {
const j = after ?? i - 1;
starts.push(j < 0 ? 0 : starts[j] + (steps[j].median ?? 0));
});
return starts;
}
export function chained(rows: DurationRow[]): DurationRow[] {
const starts = chainStarts(rows);
return rows.map((row, i) => ({ ...row, start: starts[i] }));
}
/** The rows of a route in one reading; every step keeps its row. `published` says which
@@ -26,12 +47,13 @@ export function durationRows(
read: (measure: string) => Reading | undefined,
published: (measure: string) => boolean,
): DurationRow[] {
return steps.map(({ label, measure }) => {
if (!measure || !published(measure)) return { label, status: 'unpublished' };
return steps.map(({ label, measure, after }) => {
if (!measure || !published(measure)) return { label, after, status: 'unpublished' };
const r = read(measure);
if (r?.score === undefined) return { label, status: 'empty' };
if (r?.score === undefined) return { label, after, status: 'empty' };
return {
label,
after,
status: 'value',
median: r.score,
observations: r.populations['measure-observation'],
@@ -41,6 +63,6 @@ export function durationRows(
});
}
/** The scale of a table of durations, from zero: the largest median or third quartile shown. */
/** The scale of a table of durations, from zero: the farthest median or third quartile shown. */
export const durationMax = (rows: DurationRow[]): number =>
Math.max(0, ...rows.map((r) => Math.max(r.median ?? 0, r.high ?? 0)));
Math.max(0, ...rows.map((r) => (r.start ?? 0) + Math.max(r.median ?? 0, r.high ?? 0)));