"""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_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 from collections.abc import Callable from functools import partial 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: value = os.environ.get(CLUSTER_ENV, "auto") if value not in (*CLUSTERS, "off"): raise ValueError(f"{CLUSTER_ENV} must be one of {', '.join((*CLUSTERS, 'off'))}, not {value!r}") return value def live_eeg_analysis(domain: str) -> Callable[[], Any] | None: """The domain's EEG analysis for the cycle, or none: only TEA has one, and `off` leaves it out.""" if domain != "tea" or cluster() == "off": return 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 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