This commit is contained in:
leo
2023-11-04 18:10:56 +08:00
commit da3b1a9f34
34 changed files with 1082 additions and 0 deletions

44
app/api/bench.py Normal file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from fastapi import APIRouter, Body, Depends
from loguru import logger
from sqlalchemy.orm import Session
from app.db.base import get_db
from app.crud import form_crud, result_crud
from app.schemas import Bench
from app.schemas.form import Form
router = APIRouter()
@router.get("/forms", response_model=list[Form])
def read_bench_forms(db: Session = Depends(get_db), limit: int = 10):
return form_crud.form.get_last_bench(db, num=limit)
@router.post("/result")
def read_bench_forms(uuid: str = Body(), db: Session = Depends(get_db), ):
logger.debug(f"{uuid=}")
result_dbs = result_crud.result.get_by_uuid(db, uuid=uuid)
res = {
"百川": {"value": ""},
"ChatGPT": {"value": ""},
"MyTwins": {"value": ""},
}
for result in result_dbs:
res[result.name] = result
return res
@router.get("/", response_model=list[Bench])
def read_forms(db: Session = Depends(get_db), limit: int = 10):
res = []
form_dbs = form_crud.form.get_last_bench(db, num=limit)
for form_db in form_dbs:
res.append(
Bench(
form=form_db,
results=result_crud.result.get_by_uuid(db, uuid=form_db.uuid)
))
return res