Files
WebApi/webapi/eeg.py
T
alberto c326f4901d C1a: code only, no comments, no Markdown
Remove 64 Python docstrings and 39 comments, and trim prose from three noqa pragmas. The submodule had zero tracked Markdown files.

Move published route descriptions into decorator arguments and the Correction schema description into ConfigDict. Drop internal docstrings, including the OAuth callback excluded from OpenAPI. Published route descriptions are unchanged in the before-and-after comparison of the nine application routers. The full application OpenAPI check requires fastapi-users, which is missing from the shared environment.
2026-12-01 16:55:32 -06:00

71 lines
1.7 KiB
Python

from typing import Any
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel
from persistance import eeg
from persistance.cluster import Execution
from persistance.eeg import Scope
from webapi.runs import dagster, execution_config, submit
router = APIRouter(prefix="/tea/eegs", tags=["eeg"])
class Study(BaseModel):
id: str
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]
checks: list[dict[str, Any]]
regions: list[dict[str, Any]]
class AnalyzeRequest(BaseModel):
scope: Scope = Scope()
execution: Execution | None = None
@router.get("")
def studies() -> list[Study]:
return [Study(**s) for s in eeg.studies()]
@router.post(
"/analyze",
description="Starts `tea_eeg`: analyse the EEGs in scope, score the curves, rebuild gold.",
)
def analyze_eegs(request: AnalyzeRequest, client=Depends(dagster)) -> dict[str, str]:
config = {"scope": request.scope.model_dump(), "execution": execution_config(request.execution)}
return submit(client, "tea_eeg", "tea_analyze_studies", config, domain="tea")
@router.get("/summary")
def eeg_studies_summary() -> dict[str, int]:
return eeg.summary()
@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)