TEA: the cycle's relate_ados2 step between the EEG analysis and the load, and the ADOS-2 relation in FHIR
This commit is contained in:
@@ -6,7 +6,9 @@ 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
|
||||
migrate -> catalogs, registry, definitions, analyze_eeg
|
||||
analyze_eeg -> relate_ados2, load (TEA: the EEG analysis)
|
||||
relate_ados2 -> load (TEA: the ADOS-2 association)
|
||||
catalogs -> load, check_silver
|
||||
load -> views, event_models, observe, check_silver
|
||||
registry -> observe
|
||||
|
||||
@@ -13,7 +13,7 @@ from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
from webapi.orchestration.context import Context
|
||||
from webapi.orchestration.eeg import live_eeg_analysis
|
||||
from webapi.orchestration.eeg import live_ados2_relation, live_eeg_analysis
|
||||
from webapi.orchestration.estimators import live_estimators
|
||||
from webapi.orchestration.runner import run
|
||||
|
||||
@@ -45,7 +45,8 @@ def main(argv: list[str] | None = None) -> None:
|
||||
return
|
||||
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))
|
||||
estimators=live_estimators(args.project), eeg_analysis=live_eeg_analysis(args.project),
|
||||
ados2_relation=live_ados2_relation(args.project))
|
||||
for paso in run(ctx, only=args.only):
|
||||
print(f"{paso.name:20} {paso.seconds:6.1f} s")
|
||||
|
||||
|
||||
@@ -42,5 +42,8 @@ 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 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)
|
||||
# Los repositorios del proyecto (`repositorios.Repositorios`); el ejecutor los pone si faltan.
|
||||
repos: Any = field(default=None, compare=False, repr=False)
|
||||
|
||||
@@ -84,15 +84,26 @@ def catalogs(migrate: str, ctx: Context) -> dict[str, int]:
|
||||
|
||||
def analyze_eeg(migrate: str, 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` and `eeg_metrica_electrodo`.
|
||||
it: the verdict, quality checks and metrics in `eeg`, `eeg_criterio`, `eeg_metrica`, `eeg_metrica_electrodo`
|
||||
and `eeg_metrica_zona`.
|
||||
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 load(catalogs: dict[str, int], analyze_eeg: dict[str, int], ctx: Context) -> SQLModel:
|
||||
"""`carga`, `persona`, `procedimiento` y `observacion_clinica` desde staging (T-20c), after the EEG analysis.
|
||||
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
|
||||
the version and its counts; nothing without an association (every domain but TEA)."""
|
||||
if ctx.ados2_relation is None:
|
||||
return {}
|
||||
return asdict(ctx.ados2_relation())
|
||||
|
||||
|
||||
def load(catalogs: dict[str, int], analyze_eeg: dict[str, int], relate_ados2: dict, ctx: Context) -> SQLModel:
|
||||
"""`carga`, `persona`, `procedimiento` y `observacion_clinica` desde staging (T-20c), after the EEG analysis and
|
||||
the ADOS-2 association.
|
||||
|
||||
Incremental por la llave lógica de cada procedimiento (`save_load_in`): repetir no cambia nada.
|
||||
"""
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
"""TEA's EEG analysis as the cycle runs it: the `tea` library over each stored EDF, before the silver load.
|
||||
"""TEA's EEG analysis as the cycle runs it: the `tea` library over each stored EDF, before the silver load, and the
|
||||
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_RELATION=off` leaves the association out (`python -m models tea relate-ados2` still runs it).
|
||||
"""
|
||||
import os
|
||||
from collections.abc import Callable
|
||||
@@ -11,6 +13,7 @@ from typing import Any
|
||||
|
||||
CLUSTER_ENV = "EEG_ANALYSIS_CLUSTER"
|
||||
CLUSTERS = ("auto", "local", "remote", "sync")
|
||||
RELATION_ENV = "ADOS2_RELATION"
|
||||
|
||||
|
||||
def cluster() -> str:
|
||||
@@ -27,3 +30,15 @@ def live_eeg_analysis(domain: str) -> Callable[[], Any] | None:
|
||||
from models.eeg_analysis import analyze_pending
|
||||
|
||||
return partial(analyze_pending, cluster=cluster())
|
||||
|
||||
|
||||
def live_ados2_relation(domain: str) -> Callable[[], Any] | None:
|
||||
"""The domain's ADOS-2 association for the cycle, or none: only TEA has one, and `off` leaves it out."""
|
||||
value = os.environ.get(RELATION_ENV, "on")
|
||||
if value not in ("on", "off"):
|
||||
raise ValueError(f"{RELATION_ENV} must be on or off, not {value!r}")
|
||||
if domain != "tea" or value == "off":
|
||||
return None
|
||||
from models.ados2_relation import relate
|
||||
|
||||
return relate
|
||||
|
||||
Reference in New Issue
Block a user