fix: gender and previous state for DEMO

This commit is contained in:
julius 2025-05-18 16:01:05 +02:00
parent 48f282423f
commit a6ebc28d47
Signed by: julius
GPG Key ID: C80A63E6A5FD7092
3 changed files with 26 additions and 18 deletions

View File

@ -2,16 +2,16 @@ import random
from cutt.db import Player from cutt.db import Player
names = [ names = [
"August", ("August", "mmp"),
"Beate", ("Beate", "fmp"),
"Ceasar", ("Ceasar", "mmp"),
"Daedalus", ("Daedalus", "mmp"),
"Elli", ("Elli", "fmp"),
"Ford P.", ("Ford P.", ""),
"Gabriel", ("Gabriel", "mmp"),
"Hugo", ("Hugo", "mmp"),
"Ivar Johansson", ("Ivar Johansson", "mmp"),
"Jürgen Gordon Malinauskas", ("Jürgen Gordon Malinauskas", "mmp"),
] ]
demo_players = [ demo_players = [
Player.model_validate( Player.model_validate(
@ -19,9 +19,10 @@ demo_players = [
"id": i, "id": i,
"display_name": name, "display_name": name,
"username": name.lower().replace(" ", "").replace(".", ""), "username": name.lower().replace(" ", "").replace(".", ""),
"gender": gender,
"number": str(random.randint(0, 100)), "number": str(random.randint(0, 100)),
"email": name.lower().replace(" ", "").replace(".", "") + "@example.org", "email": name.lower().replace(" ", "").replace(".", "") + "@example.org",
} }
) )
for i, name in enumerate(names) for i, (name, gender) in enumerate(names)
] ]

View File

@ -114,7 +114,7 @@ def get_mvps(
return mvps return mvps
else: else:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, status_code=status.HTTP_400_BAD_REQUEST,
detail="no previous state was found", detail="no previous state was found",
) )
@ -158,11 +158,11 @@ def get_chemistry(
subquery, (C.user == subquery.c.user) & (C.time == subquery.c.latest) subquery, (C.user == subquery.c.user) & (C.time == subquery.c.latest)
) )
chemistry = session.exec(statement2).one_or_none() chemistry = session.exec(statement2).one_or_none()
if chemistry: if chemistry is not None:
return chemistry return chemistry
else: else:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, status_code=status.HTTP_400_BAD_REQUEST,
detail="no previous state was found", detail="no previous state was found",
) )

View File

@ -87,8 +87,12 @@ function ChemistryDnD({ user, teams, players }: PlayerInfoProps) {
async function handleGet() { async function handleGet() {
setLoading(true); setLoading(true);
const data = await apiAuth(`chemistry/${teams.activeTeam}`, null, "GET"); const data = await apiAuth(`chemistry/${teams.activeTeam}`, null, "GET");
if (data.detail) alert(data.detail); if (data.detail) {
else { console.log(data.detail);
setPlayersRight([]);
setPlayersMiddle(otherPlayers);
setPlayersLeft([]);
} else {
const chemistry = data as Chemistry; const chemistry = data as Chemistry;
setPlayersLeft(filterSort(otherPlayers, chemistry.hate)); setPlayersLeft(filterSort(otherPlayers, chemistry.hate));
setPlayersMiddle( setPlayersMiddle(
@ -198,8 +202,11 @@ function MVPDnD({ user, teams, players }: PlayerInfoProps) {
async function handleGet() { async function handleGet() {
setLoading(true); setLoading(true);
const data = await apiAuth(`mvps/${teams.activeTeam}`, null, "GET"); const data = await apiAuth(`mvps/${teams.activeTeam}`, null, "GET");
if (data.detail) alert(data.detail); if (data.detail) {
else { console.log(data.detail);
setAvailablePlayers(players);
setRankedPlayers([]);
} else {
const mvps = data as MVPRanking; const mvps = data as MVPRanking;
setRankedPlayers(filterSort(players, mvps.mvps)); setRankedPlayers(filterSort(players, mvps.mvps));
setAvailablePlayers( setAvailablePlayers(