Spaces:
Sleeping
Sleeping
Create compare.py
Browse files- backend/app/api/compare.py +40 -0
backend/app/api/compare.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
from fastapi import APIRouter, Depends, Query
|
| 4 |
+
from sqlalchemy.orm import Session
|
| 5 |
+
|
| 6 |
+
from backend.app.db import get_db
|
| 7 |
+
from backend.app.models.experiment import Experiment
|
| 8 |
+
|
| 9 |
+
router = APIRouter(tags=["compare"])
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@router.get("/compare")
|
| 13 |
+
def compare_experiments(
|
| 14 |
+
experiment_ids: str = Query(...),
|
| 15 |
+
db: Session = Depends(get_db),
|
| 16 |
+
):
|
| 17 |
+
ids = [x.strip() for x in experiment_ids.split(",") if x.strip()]
|
| 18 |
+
|
| 19 |
+
experiments = (
|
| 20 |
+
db.query(Experiment)
|
| 21 |
+
.filter(Experiment.id.in_(ids))
|
| 22 |
+
.all()
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
return {
|
| 26 |
+
"experiments": [
|
| 27 |
+
{
|
| 28 |
+
"experiment_id": exp.id,
|
| 29 |
+
"dataset_id": exp.dataset_id,
|
| 30 |
+
"algorithm": exp.algorithm,
|
| 31 |
+
"status": exp.status,
|
| 32 |
+
"config": json.loads(exp.config_json or "{}"),
|
| 33 |
+
"metrics": json.loads(exp.metrics_json or "{}"),
|
| 34 |
+
"summary": json.loads(exp.summary_json or "[]"),
|
| 35 |
+
"runtime_ms": exp.runtime_ms,
|
| 36 |
+
"error_message": exp.error_message,
|
| 37 |
+
}
|
| 38 |
+
for exp in experiments
|
| 39 |
+
]
|
| 40 |
+
}
|