TEA gate: TEA_GATE_SLOW stretches its waits on a busy shared server (default 1)

This commit is contained in:
2026-11-29 23:10:46 -06:00
parent eda8dde354
commit 3300ec3048
+9 -6
View File
@@ -30,6 +30,8 @@ from models.definitions import tea_preview
from persistance import config, previews from persistance import config, previews
ROOT = Path(__file__).parents[2] ROOT = Path(__file__).parents[2]
# A busy shared server runs the gate slower: its waits stretch by this factor (default 1).
SLOW = float(os.environ.get("TEA_GATE_SLOW", "1"))
HOSPITAL = Path(os.environ.get("TEA_HOSPITAL", Path.home() / "isssteleon-data")) HOSPITAL = Path(os.environ.get("TEA_HOSPITAL", Path.home() / "isssteleon-data"))
# The age curves' reference cohort (public, outside git) and where its measures are kept. # The age curves' reference cohort (public, outside git) and where its measures are kept.
os.environ.setdefault("TEA_REFERENCE_DIR", "/mnt/drive/eeg-helsinki") os.environ.setdefault("TEA_REFERENCE_DIR", "/mnt/drive/eeg-helsinki")
@@ -146,7 +148,7 @@ def _day(value) -> date:
def _wait_for_sensor_analysis(api): def _wait_for_sensor_analysis(api):
deadline = time.monotonic() + 3600 deadline = time.monotonic() + 3600 * SLOW
while time.monotonic() < deadline: while time.monotonic() < deadline:
runs = ok(api.get("/runs", params={"job": "tea_eeg", "domain": "tea"})) runs = ok(api.get("/runs", params={"job": "tea_eeg", "domain": "tea"}))
for run in runs: for run in runs:
@@ -166,7 +168,7 @@ def scored_hospital(api, platform):
pipeline = json.loads(PIPELINE.read_text().replace("{hospital}", str(HOSPITAL))) pipeline = json.loads(PIPELINE.read_text().replace("{hospital}", str(HOSPITAL)))
put_concept_map(api, "hospital_tea") put_concept_map(api, "hospital_tea")
ok(api.put("/ingest/pipelines/tea", json=pipeline)) ok(api.put("/ingest/pipelines/tea", json=pipeline))
wait_for(api, ok(api.post("/ingest/pipelines/tea/runs", json={}))["run_id"], 1800) wait_for(api, ok(api.post("/ingest/pipelines/tea/runs", json={}))["run_id"], int(1800 * SLOW))
_wait_for_sensor_analysis(api) _wait_for_sensor_analysis(api)
q = platform.query q = platform.query
@@ -230,7 +232,7 @@ def scored_hospital(api, platform):
# The age curves: one training run gives a version of each, from the reference cohort; # The age curves: one training run gives a version of each, from the reference cohort;
# promoted after their clinical validation, they score every analysed EEG as the # promoted after their clinical validation, they score every analysed EEG as the
# current platform's curves do. # current platform's curves do.
wait_for(api, ok(api.post("/models/tea/train", json={}))["run_id"], 3600) wait_for(api, ok(api.post("/models/tea/train", json={}))["run_id"], int(3600 * SLOW))
names = ok(api.get("/models/tea")) names = ok(api.get("/models/tea"))
assert len(names) == 7 assert len(names) == 7
files = {"file": ("validacion.pdf", b"%PDF-1.4 clinical validation", "application/pdf")} files = {"file": ("validacion.pdf", b"%PDF-1.4 clinical validation", "application/pdf")}
@@ -238,7 +240,7 @@ def scored_hospital(api, platform):
ok(api.post(f"/models/tea/{name}/versions/1/reports/clinical_validation", files=files)) ok(api.post(f"/models/tea/{name}/versions/1/reports/clinical_validation", files=files))
ok(api.post(f"/models/tea/{name}/versions/1/promote")) ok(api.post(f"/models/tea/{name}/versions/1/promote"))
pending = {"scope": {"mode": "pending"}} pending = {"scope": {"mode": "pending"}}
wait_for(api, ok(api.post("/tea/eegs/analyze", json=pending))["run_id"], 1800) wait_for(api, ok(api.post("/tea/eegs/analyze", json=pending))["run_id"], int(1800 * SLOW))
scored = {(e, c): r for e, c, *r in q( scored = {(e, c): r for e, c, *r in q(
"select edf, code, z, outside, p5, median, p95 from gold.tea_eeg_metrics")} # fmt: skip "select edf, code, z, outside, p5, median, p95 from gold.tea_eeg_metrics")} # fmt: skip
for key, theirs in metrics.items(): for key, theirs in metrics.items():
@@ -253,12 +255,13 @@ def scored_hospital(api, platform):
def _association_gate(api, platform): def _association_gate(api, platform):
name = "ados2_association" name = "ados2_association"
wait_for(api, ok(api.post("/models/tea/train", json={"models": [name]}))["run_id"], 3600) training = ok(api.post("/models/tea/train", json={"models": [name]}))["run_id"]
wait_for(api, training, int(3600 * SLOW))
files = {"file": ("validacion.pdf", b"%PDF-1.4 clinical validation", "application/pdf")} files = {"file": ("validacion.pdf", b"%PDF-1.4 clinical validation", "application/pdf")}
ok(api.post(f"/models/tea/{name}/versions/1/reports/clinical_validation", files=files)) ok(api.post(f"/models/tea/{name}/versions/1/reports/clinical_validation", files=files))
ok(api.post(f"/models/tea/{name}/versions/1/promote")) ok(api.post(f"/models/tea/{name}/versions/1/promote"))
pending = {"scope": {"mode": "pending"}} pending = {"scope": {"mode": "pending"}}
wait_for(api, ok(api.post("/tea/eegs/analyze", json=pending))["run_id"], 1800) wait_for(api, ok(api.post("/tea/eegs/analyze", json=pending))["run_id"], int(1800 * SLOW))
tables = REFERENCE / "tables" tables = REFERENCE / "tables"
biomarkers = { biomarkers = {