TEA gate, EEG pages, analyze and named training runs
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""TEA's EEGs for model governance: every study with its analysis verdict, and one study's
|
||||
metrics with their age curves' scores."""
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
from persistance import eeg
|
||||
|
||||
router = APIRouter(prefix="/tea/eegs", tags=["eeg"])
|
||||
|
||||
|
||||
class Study(BaseModel):
|
||||
id: str # person and study date
|
||||
person_id: str
|
||||
study_date: str
|
||||
lab_record_id: str | None
|
||||
analysed: bool
|
||||
valid: bool | None
|
||||
level: str | None
|
||||
|
||||
|
||||
class Metric(BaseModel):
|
||||
code: str
|
||||
value: float
|
||||
z: float | None
|
||||
outside: float | None
|
||||
model: str | None
|
||||
|
||||
|
||||
class Analysis(BaseModel):
|
||||
id: str
|
||||
valid: bool | None
|
||||
level: str | None
|
||||
age_months: float | None
|
||||
metrics: list[Metric]
|
||||
|
||||
|
||||
@router.get("")
|
||||
def studies() -> list[Study]:
|
||||
return [Study(**s) for s in eeg.studies()]
|
||||
|
||||
|
||||
@router.get("/{eeg_id}")
|
||||
def study(eeg_id: str) -> Analysis:
|
||||
if (found := eeg.study(eeg_id)) is None:
|
||||
raise HTTPException(404, detail=f"no analysed EEG {eeg_id}")
|
||||
return Analysis(**found)
|
||||
+2
-1
@@ -3,7 +3,7 @@ from fastapi.exception_handlers import http_exception_handler
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from core.domains import Domain
|
||||
from webapi import fhir, ingest, models, review, runs
|
||||
from webapi import eeg, fhir, ingest, models, review, runs
|
||||
from webapi.auth import caller
|
||||
|
||||
app = FastAPI(
|
||||
@@ -16,6 +16,7 @@ app.include_router(ingest.router)
|
||||
app.include_router(review.router)
|
||||
app.include_router(runs.router)
|
||||
app.include_router(models.router)
|
||||
app.include_router(eeg.router)
|
||||
app.include_router(fhir.router)
|
||||
|
||||
|
||||
|
||||
+11
-1
@@ -75,6 +75,7 @@ def promote(domain: Domain, name: str, version: int) -> dict:
|
||||
|
||||
class Training(BaseModel):
|
||||
as_of: date | None = None # the date the data are taken up to (default: today)
|
||||
models: list[str] = [] # which (default: all but the slow ones, like CaMa's recurrence)
|
||||
|
||||
|
||||
def _submit(client: DagsterGraphQLClient, job: str, op: str, config: dict) -> dict[str, str]:
|
||||
@@ -89,12 +90,21 @@ def _submit(client: DagsterGraphQLClient, job: str, op: str, config: dict) -> di
|
||||
def train(domain: Domain, request: Training,
|
||||
client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]: # fmt: skip
|
||||
"""Starts training a new version of every model of the domain; follow it at /runs."""
|
||||
config = {"domain": domain.value}
|
||||
config: dict = {"domain": domain.value}
|
||||
if request.as_of:
|
||||
config["as_of"] = request.as_of.isoformat()
|
||||
if request.models:
|
||||
config["models"] = request.models
|
||||
return _submit(client, "train", "train_models", config)
|
||||
|
||||
|
||||
@router.post("/{domain}/analyze")
|
||||
def analyze(domain: Domain, client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]:
|
||||
"""Starts analysing the studies the domain's models read whole (TEA: its EEGs); follow
|
||||
it at /runs."""
|
||||
return _submit(client, "analyze", "analyze_studies", {"domain": domain.value})
|
||||
|
||||
|
||||
@router.post("/{domain}/score")
|
||||
def score(domain: Domain, client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]:
|
||||
"""Starts a risk batch from each model's champion; follow it at /runs."""
|
||||
|
||||
Reference in New Issue
Block a user