Files
WebApi/webapi/eeg.py
T

81 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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 Site(BaseModel):
site: str # a zone (frontal_left …) or an electrode (Fp1 …)
value: float
z: float | None # against the age curve of that site, when one is trained
class Metric(BaseModel):
code: str
value: float
z: float | None
outside: float | None # how far outside the age band (0: inside; <0 below, >0 above)
p5: float | None = None # the age curve's band at her age
median: float | None = None
p95: float | None = None
model: str | None
zones: list[Site] = []
electrodes: list[Site] = []
class Relation(BaseModel):
"""One pair of the champion EEG–ADOS-2 association, for this EEG (models.tea.association)."""
biomarker: str
metric: str
zone: str
outcome_code: str # ados2_item_NN or CSS
kind: str # item or domain
event: str # what counts as altered (>=1 for an item, >=8 for the CSS)
z: float
probability: float
reference_probability: float # a child of her age and module with z = 0
observed: float | None = None # what her ADOS-2 shows: the item's score, or the CSS
odds_ratio: float
ci_low: float | None
ci_high: float | None
q: float | None
n: float
model: str
class Analysis(BaseModel):
id: str
valid: bool | None
level: str | None
age_months: float | None
metrics: list[Metric]
relation: list[Relation] = []
@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)