Live survival: the scenarios of a patient and the figure of one scenario

This commit is contained in:
rockdrigo
2026-11-21 13:14:06 -06:00
parent 3b192207fd
commit a53179aa2e
2 changed files with 58 additions and 24 deletions
+27 -8
View File
@@ -1,4 +1,4 @@
"""What a model's production version found about its cohort: `GET /<domain>/modelo/curvas`, `GET /<domain>/modelo/desarrollo` and, over the data ingested so far, `POST /<domain>/modelo/curvas/consulta`.
"""What a model's production version found about its cohort: `GET /<domain>/modelo/curvas`, `GET /<domain>/modelo/desarrollo` and, over the data ingested so far, `GET /<domain>/modelo/escenarios` and `POST /<domain>/modelo/curvas/consulta`.
The population results a training run publishes (`analisis/curvas.json`, `models.cama.survival.population`): the cohort's
survival curves and the model's survival at each horizon with its intervals, for the dashboard to draw. They describe the
@@ -82,23 +82,42 @@ def model_analysis_blueprint(domain: str, scenario: str) -> Blueprint:
"mlflow_run_id": resolved.run_id},
"desarrollo": json.loads(content)})
@blueprint.post("/modelo/curvas/consulta")
def live_curves():
"""The figure's record for the selection in the body (`{filtros, periodo}`), scored with the production version over
the data ingested so far. 422 with the reason when the selection is too small or invalid."""
@blueprint.get("/modelo/escenarios")
def patient_scenarios():
"""The clinical scenarios `?paciente=<pac_id>` belongs to (the whole cohort when she is in none), over the data
ingested so far. 404 while there is no version in production; 422 with the reason for a patient outside the cohort."""
from models.cama.survival import live
query = request.get_json(silent=True) or {}
try:
_, _, labelled, version = _live_context(domain, scenario)
except LookupError as error:
return jsonify({"error": f"sin curvas: {error}"}), 404
paciente = request.args.get("paciente", "")
if not paciente.isdigit():
return jsonify({"error": "Falta la paciente."}), 422
try:
found = live.patient_scenarios(labelled, int(paciente))
except live.QueryError as error:
return jsonify({"error": str(error)}), 422
return jsonify({"modelo": {"nombre": f"{domain}-{scenario}", "version": str(version)}, "escenarios": found})
@blueprint.post("/modelo/curvas/consulta")
def live_curves():
"""The figure's record for the clinical scenario in the body (`{escenario}`, none for the whole cohort), scored with the
production version over the data ingested so far. 422 with the reason for an unknown scenario or one too small."""
from models.cama.survival import live
name = (request.get_json(silent=True) or {}).get("escenario")
try:
spec, model, labelled, version = _live_context(domain, scenario)
except LookupError as error:
return jsonify({"error": f"sin curvas: {error}"}), 404
key = json.dumps({"v": version, "q": query}, sort_keys=True, default=str)
key = json.dumps({"v": version, "e": name}, default=str)
with _LOCK:
record = _ANSWERS.get(key)
if record is None:
try:
record = live.curves(spec, model, labelled, query)
record = live.curves(spec, model, labelled, name)
except live.QueryError as error:
return jsonify({"error": str(error)}), 422
with _LOCK: