feat: use better query

This commit is contained in:
julius 2025-03-24 14:18:40 +01:00
parent df16497476
commit 195d240a87
Signed by: julius
GPG Key ID: C80A63E6A5FD7092

View File

@ -6,7 +6,7 @@ from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field
from sqlmodel import Session, func, select
from sqlmodel.sql.expression import SelectOfScalar
from cutt.db import Chemistry, MVPRanking, Player, Team, engine
from cutt.db import Chemistry, MVPRanking, Player, PlayerTeamLink, Team, engine
import networkx as nx
import numpy as np
import matplotlib
@ -63,8 +63,12 @@ def graph_json(
edges = []
player_map = {}
with Session(engine) as session:
statement = select(Team).where(Team.id == request.team_id)
players = [t.players for t in session.exec(statement)][0]
players = session.exec(
select(P)
.join(PlayerTeamLink)
.join(Team)
.where(Team.id == request.team_id, P.disabled == False)
).all()
if not players:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
for p in players:
@ -227,8 +231,12 @@ def mvp(
):
ranks = dict()
with Session(engine) as session:
statement = select(Team).where(Team.id == request.team_id)
players = [t.players for t in session.exec(statement)][0]
players = session.exec(
select(P)
.join(PlayerTeamLink)
.join(Team)
.where(Team.id == request.team_id, P.disabled == False)
).all()
if not players:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
player_map = {p.id: p.display_name for p in players}
@ -268,8 +276,12 @@ async def turnout(
):
player_map = {}
with Session(engine) as session:
statement = select(Team).where(Team.id == request.team_id)
players = [t.players for t in session.exec(statement)][0]
players = session.exec(
select(P)
.join(PlayerTeamLink)
.join(Team)
.where(Team.id == request.team_id, P.disabled == False)
).all()
if not players:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
for p in players: