feat: use better query
This commit is contained in:
parent
df16497476
commit
195d240a87
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user