Add result endpoints
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Result(BaseModel):
|
||||
song_id: int = Field(description="ID of the song", examples=[1])
|
||||
total_reviews: int = Field(0, description="Total number of reviews", examples=[10])
|
||||
avg_score_song: float = Field(
|
||||
description="Average score for song quality", examples=[85.5]
|
||||
)
|
||||
avg_score_show: float = Field(
|
||||
description="Average score for stage show", examples=[82.3]
|
||||
)
|
||||
avg_score_costume: float = Field(
|
||||
description="Average score for wardrobe/costumes", examples=[88.1]
|
||||
)
|
||||
avg_total_score: float = Field(description="Average total score", examples=[85.5])
|
||||
|
||||
|
||||
class TeamResult(Result):
|
||||
team_id: int = Field(description="ID of the team", examples=[1])
|
||||
@@ -1,3 +1,28 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from models.result import Result, TeamResult
|
||||
from lib.db import get_connection
|
||||
|
||||
router = APIRouter(prefix="/results", tags=["results"])
|
||||
|
||||
|
||||
@router.get("/", response_model=list[Result])
|
||||
async def list_results():
|
||||
with get_connection() as conn:
|
||||
df = conn.execute("SELECT * FROM ReviewSummaryGlobal").fetchdf()
|
||||
if df.empty:
|
||||
return []
|
||||
results = [Result(**row) for row in df.to_dict(orient="records")]
|
||||
return results
|
||||
|
||||
|
||||
@router.get("/team/{team_id}", response_model=list[TeamResult])
|
||||
async def list_team_results(team_id: int):
|
||||
with get_connection() as conn:
|
||||
df = conn.execute(
|
||||
"SELECT * FROM ReviewSummaryByTeam WHERE team_id = ?", (team_id,)
|
||||
).fetchdf()
|
||||
if df.empty:
|
||||
return []
|
||||
results = [TeamResult(**row) for row in df.to_dict(orient="records")]
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user