Indicators cycle recomputes the CaMa survival scenario points over each new build; the figure draws them
This commit is contained in:
@@ -109,6 +109,7 @@ def live_client(client, monkeypatch):
|
||||
return {"n": 100, "escenario": name or "Toda la cohorte"}
|
||||
|
||||
monkeypatch.setattr(model_analysis, "_live_context", lambda d, s: ("spec", "model", labelled, "3"))
|
||||
monkeypatch.setattr(model_analysis, "_current_build", lambda d, s: None)
|
||||
monkeypatch.setattr(live, "scenario_masks", lambda frame: masks)
|
||||
monkeypatch.setattr(live, "curves", curves)
|
||||
model_analysis._ANSWERS.clear()
|
||||
@@ -259,3 +260,35 @@ def test_the_figure_takes_the_points_the_version_published_for_the_scenario(live
|
||||
|
||||
assert published["COMB"] == {"S": [0.9] * 3, "low": [0.85] * 3, "high": [0.95] * 3}
|
||||
assert live_client.holder.points is None
|
||||
|
||||
|
||||
def test_the_cycle_computes_the_scenario_points_once_per_build_and_the_figure_takes_them(live_client, tmp_path, monkeypatch):
|
||||
"""Pins down: `refresh_subgroups` runs the pipeline's survival stage over the latest build's members once and saves its
|
||||
scenario points beside them; the figure then draws those points instead of the ones the version published when it trained,
|
||||
and a new build replaces the file. Fails if the figure keeps the training's points after the data changed, or every cycle
|
||||
reruns the stage for the same build."""
|
||||
from models.cama.survival import development
|
||||
from webapi import model_analysis
|
||||
|
||||
monkeypatch.setenv("INDICADORES_DIR", str(tmp_path))
|
||||
build = {"id": 8}
|
||||
monkeypatch.setattr(model_analysis, "_current_build", lambda d, s: ("3", build["id"]))
|
||||
monkeypatch.setattr(model_analysis, "_live_context", lambda d, s: (SimpleNamespace(config={"desarrollo": {}}), "model", None, "3"))
|
||||
runs = []
|
||||
|
||||
def stage(labelled, desarrollo):
|
||||
runs.append(build["id"])
|
||||
return [{"modelo": m, "meses": h, "S": 0.7, "IC_inf": 0.6, "IC_sup": 0.8, "subgrupo": "< 45 años"}
|
||||
for m in ("LR", "HBN", "COMB") for h in (6, 12, 18)]
|
||||
|
||||
monkeypatch.setattr(development, "subgroup_points", stage)
|
||||
|
||||
first = model_analysis.refresh_subgroups("cama")
|
||||
again = model_analysis.refresh_subgroups("cama")
|
||||
rows = model_analysis._subgroup_rows("cama", "survival", "3")
|
||||
build["id"] = 9
|
||||
model_analysis.refresh_subgroups("cama")
|
||||
|
||||
assert first == ["survival"] and again == [] and runs == [8, 9]
|
||||
assert [r["S"] for r in rows if r["modelo"] == "COMB"] == [0.7] * 3
|
||||
assert [p.name for p in (tmp_path / "modelos").glob("*-subgrupos.json")] == ["cama-survival-v3-armado9-subgrupos.json"]
|
||||
|
||||
Reference in New Issue
Block a user