diff --git a/tests/test_model_analysis.py b/tests/test_model_analysis.py index f2cae90..18d869c 100644 --- a/tests/test_model_analysis.py +++ b/tests/test_model_analysis.py @@ -101,8 +101,9 @@ def live_client(client, monkeypatch): masks = {"< 45 años": np.arange(200) < 100, "Diminuto": np.arange(200) < 3, "Estadio IV": np.zeros(200, bool)} holder.files["analisis/desarrollo.json"] = json.dumps({"tablas": {"escenarios_resumen": SUMMARY}}).encode() - def curves(spec, model, labelled_members, name): + def curves(spec, model, labelled_members, name, points=None): holder.calls += 1 + holder.points = points if holder.error: raise live.QueryError(holder.error) return {"n": 100, "escenario": name or "Toda la cohorte"} @@ -240,3 +241,21 @@ def test_the_members_are_computed_once_per_build_and_version_and_read_from_their assert reads == [8, 9] and again.equals(first) assert [p.name for p in (tmp_path / "modelos").iterdir()] == ["cama-survival-v3-armado9.parquet"] + + +def test_the_figure_takes_the_points_the_version_published_for_the_scenario(live_client): + """Pins down: the live figure of a scenario carries the points the pipeline's survival stage published for it + (`subgrupos_puntos`: LR, HBN and their combination with bootstrap intervals), and none for a scenario without them. Fails if + the figure draws the members' own scores where the version has the pipeline's.""" + rows = [{"modelo": m, "meses": h, "S": 0.9, "IC_inf": 0.85, "IC_sup": 0.95, "subgrupo": "< 45 años"} + for m in ("LR", "HBN", "COMB") for h in (6, 12, 18)] + record = json.loads(live_client.holder.files["analisis/desarrollo.json"]) + record["tablas"]["subgrupos_puntos"] = {"columnas": ["modelo", "meses", "S", "IC_inf", "IC_sup", "subgrupo"], "filas": rows} + live_client.holder.files["analisis/desarrollo.json"] = json.dumps(record).encode() + + live_client.post("/cama/modelo/curvas/consulta", json={"escenario": "< 45 años"}) + published = live_client.holder.points + live_client.post("/cama/modelo/curvas/consulta", json={"escenario": "Estadio IV"}) + + assert published["COMB"] == {"S": [0.9] * 3, "low": [0.85] * 3, "high": [0.95] * 3} + assert live_client.holder.points is None diff --git a/webapi/model_analysis.py b/webapi/model_analysis.py index 5acabf5..bb82646 100644 --- a/webapi/model_analysis.py +++ b/webapi/model_analysis.py @@ -188,8 +188,9 @@ def model_analysis_blueprint(domain: str, scenario: str) -> Blueprint: with _LOCK: record = _ANSWERS.get(key) if record is None: + published = live.published_points(_summary(domain, scenario, version, table="subgrupos_puntos"), name) try: - record = live.curves(spec, model, labelled, name) + record = live.curves(spec, model, labelled, name, published) except live.QueryError as error: return jsonify({"error": str(error)}), 422 with _LOCK: