Files
WebApi/webapi/orchestration/context.py
T

53 lines
2.9 KiB
Python

"""Lo que recibe cada paso del ciclo."""
import os
from collections.abc import Callable, Mapping
from dataclasses import dataclass, field
from datetime import date
from pathlib import Path
from typing import Any
def dbt_manifest_path() -> Path | None:
"""The deployment's dbt manifest, from `DBT_MANIFEST`."""
ruta = os.environ.get("DBT_MANIFEST")
return Path(ruta) if ruta else None
@dataclass(frozen=True)
class Context:
"""Lo que recibe un paso: el proyecto y las opciones del ciclo.
`anio_inicio` y `anio_fin` son los años de los periodos que se registran y
calculan. `corte` es la fecha hasta la que llegan los datos; sin ella, cada
paso del kit toma la de la última carga. `permitir_sin_definir` deja correr
con parámetros que nadie ha decidido: hay que pedirlo a propósito, como en
el kit. `parametros` es el archivo de parámetros que carga `registry`; sin
él, el `parametros.toml` del kit. `repos` es todo lo que el paso usa
para tocar la base: nunca abre una sesión por su cuenta (`repositories.py`).
"""
project: str
year_from: int
year_to: int
cutoff: date | None = None
allow_undecided: bool = False
parameters: Path | None = None
# The `manifest.json` of `dbt compile`: the measures are defined there (`webapi.metrics`), and from it the cycle
# creates their event models (`event_models`) and seeds the publication catalog (`definitions`).
dbt_manifest: Path | None = field(default_factory=dbt_manifest_path)
# Los estimadores de riesgo por cohorte (`cohorte_url` -> objeto con `estimate(columnas, filas)`, `procedencia()`
# y `desenlace`; ADR-MD-008). Sin ellos, el paso `estimate` no hace nada.
estimators: Mapping[str, Any] = field(default_factory=dict, compare=False, repr=False)
# 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)
# Los repositorios del proyecto (`repositorios.Repositorios`); el ejecutor los pone si faltan.
repos: Any = field(default=None, compare=False, repr=False)