Merge parity/F1h
This commit is contained in:
@@ -1,36 +0,0 @@
|
|||||||
from io import BytesIO
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
from fastapi import HTTPException, UploadFile
|
|
||||||
|
|
||||||
from core.domains import Domain
|
|
||||||
from webapi.models import training_inputs, upload_training_inputs
|
|
||||||
|
|
||||||
|
|
||||||
def test_training_inputs(tmp_path, monkeypatch):
|
|
||||||
root = tmp_path / "reference"
|
|
||||||
monkeypatch.setenv("TEA_REFERENCE_ROOT", str(root))
|
|
||||||
assert training_inputs(Domain.TEA, "curve_x") == {"allowed": ["*.edf", "edades.csv"]}
|
|
||||||
with pytest.raises(HTTPException) as undefined:
|
|
||||||
training_inputs(Domain.TEA, "ados2_association")
|
|
||||||
assert undefined.value.status_code == 404
|
|
||||||
|
|
||||||
def upload(name, files):
|
|
||||||
return upload_training_inputs(
|
|
||||||
Domain.TEA,
|
|
||||||
"curve_x",
|
|
||||||
name,
|
|
||||||
[UploadFile(BytesIO(content), filename=filename) for filename, content in files],
|
|
||||||
)
|
|
||||||
|
|
||||||
expected = {"name": "cohort", "edf_files": 1, "has_ages": True, "bytes": 7}
|
|
||||||
assert upload("cohort", [("one.EDF", b"edf"), ("edades.csv", b"ages")]) == expected
|
|
||||||
|
|
||||||
for invalid in ("bad.txt", "../x"):
|
|
||||||
with pytest.raises(HTTPException) as rejected:
|
|
||||||
upload("cohort", [("two.edf", b"edf"), (invalid, b"bad")])
|
|
||||||
assert rejected.value.status_code == 422
|
|
||||||
with pytest.raises(HTTPException) as rejected:
|
|
||||||
upload("bad set", [("one.edf", b"edf")])
|
|
||||||
assert rejected.value.status_code == 422
|
|
||||||
assert {path.name for path in (root / "cohort").iterdir()} == {"one.EDF", "edades.csv"}
|
|
||||||
+4
-40
@@ -4,18 +4,16 @@ scoring runs (Dagster). The API starts runs and reads the registry; it never tra
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
import zipfile
|
import zipfile
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from pathlib import Path
|
|
||||||
from typing import Annotated, Any, Literal
|
from typing import Annotated, Any, Literal
|
||||||
|
|
||||||
from dagster_graphql import DagsterGraphQLClient
|
from dagster_graphql import DagsterGraphQLClient
|
||||||
from fastapi import APIRouter, Depends, File, HTTPException, Query, UploadFile
|
from fastapi import APIRouter, Depends, HTTPException, Query, UploadFile
|
||||||
from fastapi.responses import Response
|
from fastapi.responses import Response
|
||||||
from pydantic import BaseModel, Field, WithJsonSchema
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from core import tea
|
from core.domains import Domain
|
||||||
from core.domains import Domain, InputSpec
|
|
||||||
from core.models import title
|
from core.models import title
|
||||||
from persistance import bundle, cluster, inputs, registry
|
from persistance import bundle, cluster, registry
|
||||||
from persistance.cluster import Execution, TrainingSource
|
from persistance.cluster import Execution, TrainingSource
|
||||||
from webapi.runs import dagster, execution_config, submit
|
from webapi.runs import dagster, execution_config, submit
|
||||||
|
|
||||||
@@ -183,40 +181,6 @@ def lineage(domain: Domain, name: str, version: int) -> dict:
|
|||||||
raise HTTPException(404, detail=str(e)) from e
|
raise HTTPException(404, detail=str(e)) from e
|
||||||
|
|
||||||
|
|
||||||
def _training_inputs(domain: Domain, name: str) -> tuple[InputSpec, Path]:
|
|
||||||
declared = tea.TRAINING_INPUTS if domain == Domain.TEA else {}
|
|
||||||
spec = declared.get(name, declared.get("*"))
|
|
||||||
if spec is None:
|
|
||||||
raise HTTPException(404, detail=f"no training inputs for {domain.value}.{name}")
|
|
||||||
try:
|
|
||||||
return spec, inputs.root(spec)
|
|
||||||
except LookupError as e:
|
|
||||||
raise HTTPException(503, detail=str(e)) from e
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{domain}/{name}/inputs")
|
|
||||||
def training_inputs(domain: Domain, name: str) -> dict[str, list[str]]:
|
|
||||||
spec, _ = _training_inputs(domain, name)
|
|
||||||
return {"allowed": spec.allowed}
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{domain}/{name}/inputs/{set}/files")
|
|
||||||
def upload_training_inputs(
|
|
||||||
domain: Domain,
|
|
||||||
name: str,
|
|
||||||
set: str,
|
|
||||||
files: Annotated[
|
|
||||||
list[Annotated[UploadFile, WithJsonSchema({"type": "string", "format": "binary"})]],
|
|
||||||
File(min_length=1),
|
|
||||||
],
|
|
||||||
) -> dict:
|
|
||||||
spec, root = _training_inputs(domain, name)
|
|
||||||
try:
|
|
||||||
return inputs.upload(root, set, spec.allowed, [(f.filename or "", f.file) for f in files])
|
|
||||||
except ValueError as e:
|
|
||||||
raise HTTPException(422, detail=str(e)) from e
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{domain}/{name}/versions/{version}/curve")
|
@router.get("/{domain}/{name}/versions/{version}/curve")
|
||||||
def curve(domain: Domain, name: str, version: int, feature: str = "value") -> list[dict]:
|
def curve(domain: Domain, name: str, version: int, feature: str = "value") -> list[dict]:
|
||||||
if domain != Domain.TEA:
|
if domain != Domain.TEA:
|
||||||
|
|||||||
Reference in New Issue
Block a user