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 pydantic import BaseModel, Field
|
||||||
from sqlmodel import Session, func, select
|
from sqlmodel import Session, func, select
|
||||||
from sqlmodel.sql.expression import SelectOfScalar
|
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 networkx as nx
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib
|
import matplotlib
|
||||||
@ -63,8 +63,12 @@ def graph_json(
|
|||||||
edges = []
|
edges = []
|
||||||
player_map = {}
|
player_map = {}
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
statement = select(Team).where(Team.id == request.team_id)
|
players = session.exec(
|
||||||
players = [t.players for t in session.exec(statement)][0]
|
select(P)
|
||||||
|
.join(PlayerTeamLink)
|
||||||
|
.join(Team)
|
||||||
|
.where(Team.id == request.team_id, P.disabled == False)
|
||||||
|
).all()
|
||||||
if not players:
|
if not players:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
for p in players:
|
for p in players:
|
||||||
@ -227,8 +231,12 @@ def mvp(
|
|||||||
):
|
):
|
||||||
ranks = dict()
|
ranks = dict()
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
statement = select(Team).where(Team.id == request.team_id)
|
players = session.exec(
|
||||||
players = [t.players for t in session.exec(statement)][0]
|
select(P)
|
||||||
|
.join(PlayerTeamLink)
|
||||||
|
.join(Team)
|
||||||
|
.where(Team.id == request.team_id, P.disabled == False)
|
||||||
|
).all()
|
||||||
if not players:
|
if not players:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
player_map = {p.id: p.display_name for p in players}
|
player_map = {p.id: p.display_name for p in players}
|
||||||
@ -268,8 +276,12 @@ async def turnout(
|
|||||||
):
|
):
|
||||||
player_map = {}
|
player_map = {}
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
statement = select(Team).where(Team.id == request.team_id)
|
players = session.exec(
|
||||||
players = [t.players for t in session.exec(statement)][0]
|
select(P)
|
||||||
|
.join(PlayerTeamLink)
|
||||||
|
.join(Team)
|
||||||
|
.where(Team.id == request.team_id, P.disabled == False)
|
||||||
|
).all()
|
||||||
if not players:
|
if not players:
|
||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
for p in players:
|
for p in players:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user