feat(tea): EEG analysis before the silver load, and its verdict, quality checks and baselines through silver and FHIR
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""TEA's EEG analysis as the cycle runs it: the `tea` library over each stored EDF, before the silver load.
|
||||
|
||||
`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).
|
||||
"""
|
||||
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")
|
||||
|
||||
|
||||
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())
|
||||
Reference in New Issue
Block a user