init
This commit is contained in:
44
app/api/bench.py
Normal file
44
app/api/bench.py
Normal 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
|
||||
Reference in New Issue
Block a user