diff --git a/models/cama/survival/development.py b/models/cama/survival/development.py index f23c17d..8a1c956 100644 --- a/models/cama/survival/development.py +++ b/models/cama/survival/development.py @@ -118,3 +118,18 @@ def development(labelled_members: pd.DataFrame, desarrollo: dict) -> dict: def population(population_curves: dict, development: dict) -> dict: """Everything the version publishes about its cohort, by file name under `analisis/`: the curves and the development.""" return {**population_curves, **development} + + +def subgroup_points(labelled_members: pd.DataFrame, desarrollo: dict) -> list[dict]: + """The pipeline's stages 01 and 05 over the members as they are now: the depuration, then the LR and HBN fitted on them with + each clinical scenario's survival at the horizons and its bootstrap interval (`subgrupos_puntos`), one row per model, + horizon and scenario. What the dashboard draws as a scenario's points between trainings.""" + from models.cama.seer_survival import pipeline + + with tempfile.TemporaryDirectory() as tmp: + out = Path(tmp) + _recoded_frame(labelled_members).to_csv(out / pipeline.RECODED, index=False) + (out / pipeline.COLUMN_MAP).write_text("{}", encoding="utf-8") + pipeline.run_pipeline(out, only=["01", "05"], everything=True, settings=_seer_settings(desarrollo)) + table = pd.read_csv(out / "subgrupos_puntos_LR_HBN.csv").replace([np.inf, -np.inf], np.nan).astype(object) + return table.where(table.notna(), None).to_dict("records")