ADOS-2 scoring step in the indicators cycle, run after the document import commits; EEG analysis ordered before the relation steps

This commit is contained in:
ulises
2026-11-22 22:01:50 -06:00
parent 430d165594
commit eb88cb7eb0
10 changed files with 139 additions and 9 deletions
+2 -1
View File
@@ -6,7 +6,8 @@ Each step is a function of `cycle.py`. It takes the `Context` and, as parameters
Hamilton builds the graph from those names. Steps pass no data: everything goes through the database, by
Persistance's repositories (`ctx.repos`), so each one can run on its own.
migrate -> catalogs, registry, definitions, analyze_eeg
migrate -> catalogs, registry, definitions, score_ados2
score_ados2 -> analyze_eeg (TEA: the ADOS-2 CSS and classification, quick)
analyze_eeg -> relate_ados2, load (TEA: the EEG analysis)
relate_ados2 -> load (TEA: the ADOS-2 association)
catalogs -> load, check_silver
+3 -2
View File
@@ -13,7 +13,7 @@ from datetime import date
from pathlib import Path
from webapi.orchestration.context import Context
from webapi.orchestration.eeg import live_ados2_relation, live_eeg_analysis
from webapi.orchestration.eeg import live_ados2_relation, live_ados2_scoring, live_eeg_analysis
from webapi.orchestration.estimators import live_estimators
from webapi.orchestration.runner import run
@@ -46,7 +46,8 @@ def main(argv: list[str] | None = None) -> None:
logging.basicConfig(level=logging.INFO, format="%(message)s")
ctx = Context(args.project, args.year_from, args.year_to, args.cutoff, args.allow_undecided, args.parameters,
estimators=live_estimators(args.project), eeg_analysis=live_eeg_analysis(args.project),
ados2_relation=live_ados2_relation(args.project))
ados2_relation=live_ados2_relation(args.project),
ados2_scoring=live_ados2_scoring(args.project))
for paso in run(ctx, only=args.only):
print(f"{paso.name:20} {paso.seconds:6.1f} s")
+3
View File
@@ -42,6 +42,9 @@ class Context:
# The domain's EEG analysis (`webapi.orchestration.eeg.live_eeg_analysis`): run by the `analyze_eeg` step before
# the silver load, it writes the analysis of each stored EDF to bronze. Without it, that step does nothing.
eeg_analysis: Callable[[], Any] | None = field(default=None, compare=False, repr=False)
# The domain's ADOS-2 scoring (`webapi.orchestration.eeg.live_ados2_scoring`): run by the `score_ados2` step, it
# writes each evaluation's CSS and classification from its items. Without it, that step does nothing.
ados2_scoring: Callable[[], Any] | None = field(default=None, compare=False, repr=False)
# The domain's ADOS-2 association (`webapi.orchestration.eeg.live_ados2_relation`): run by the `relate_ados2` step
# after the EEG analysis, it fits the model on the analysed EEGs. Without it, that step does nothing.
ados2_relation: Callable[[], Any] | None = field(default=None, compare=False, repr=False)
+11 -1
View File
@@ -82,16 +82,26 @@ def catalogs(migrate: str, ctx: Context) -> dict[str, int]:
return counts
def analyze_eeg(migrate: str, ctx: Context) -> dict[str, int]:
def analyze_eeg(migrate: str, score_ados2: dict, ctx: Context) -> dict[str, int]:
"""The EEG analysis of each stored EDF that needs one (`ctx.eeg_analysis`), written to bronze before `load` reads
it: the verdict, quality checks and metrics in `eeg`, `eeg_criterio`, `eeg_metrica`, `eeg_metrica_electrodo`
and `eeg_metrica_zona`.
Waits for `score_ados2` only so the quick scoring doesn't queue behind a long analysis.
Returns how many EEGs were pending and how each ended; nothing without an analysis (every domain but TEA)."""
if ctx.eeg_analysis is None:
return {}
return asdict(ctx.eeg_analysis())
def score_ados2(migrate: str, ctx: Context) -> dict:
"""The CSS and classification of each ADOS-2 from its items, module, algorithm and the child's age
(`ctx.ados2_scoring`), written to bronze before the association and `load` read them. Returns how many
evaluations were scored; nothing without a scoring (every domain but TEA)."""
if ctx.ados2_scoring is None:
return {}
return asdict(ctx.ados2_scoring())
def relate_ados2(analyze_eeg: dict[str, int], ctx: Context) -> dict:
"""The ADOS-2 association fitted on the EEGs the analysis left (`ctx.ados2_relation`), written to
`relacion_ados2` and `relacion_ados2_paciente` before `load`, so the same cycle's gold views show it. Returns
+15
View File
@@ -4,6 +4,8 @@ ADOS-2 association fitted on what it left.
`EEG_ANALYSIS_CLUSTER` says where the batch runs: `auto` (the default: the scheduler in `DASK_SCHEDULER_ADDRESS` if
set, otherwise a local cluster), `local`, `remote`, `sync` (in the cycle's own process), or `off`, which leaves the
analysis out of the cycle (`python -m models tea analyze` and `POST /governance/eeg/run` still run it).
`ADOS2_SCORING=off` leaves the ADOS-2 CSS and classification out of the cycle (`python -m models tea score-ados2`
still computes them).
`ADOS2_RELATION=off` leaves the association out (`python -m models tea relate-ados2` still runs it).
"""
import os
@@ -14,6 +16,7 @@ from typing import Any
CLUSTER_ENV = "EEG_ANALYSIS_CLUSTER"
CLUSTERS = ("auto", "local", "remote", "sync")
RELATION_ENV = "ADOS2_RELATION"
SCORING_ENV = "ADOS2_SCORING"
def cluster() -> str:
@@ -42,3 +45,15 @@ def live_ados2_relation(domain: str) -> Callable[[], Any] | None:
from models.ados2_relation import relate
return relate
def live_ados2_scoring(domain: str) -> Callable[[], Any] | None:
"""The domain's ADOS-2 scoring for the cycle, or none: only TEA has one, and `off` leaves it out."""
value = os.environ.get(SCORING_ENV, "on")
if value not in ("on", "off"):
raise ValueError(f"{SCORING_ENV} must be on or off, not {value!r}")
if domain != "tea" or value == "off":
return None
from models.ados2_scoring import score_pending
return score_pending