Update teams.py

Add abbrev to PATCH /teams
Fix standings bug
This commit is contained in:
Cal Corum 2023-10-26 21:46:07 -05:00
parent c62d0fc60e
commit 633db7f565

View File

@ -581,20 +581,20 @@ async def get_team_record(team_id: int, season: int):
for game in all_games:
run_diff = game.away_score - game.home_score
if run_diff > 0:
if game.away_team_id == team_id:
if run_diff > 0: # Away team won
if game.away_team_id == team_id: # Human is away team
standings[game.game_type][game.home_team.abbrev][0] += 1
standings[game.game_type][game.home_team.abbrev][2] += run_diff
else:
else: # Human is home team
standings[game.game_type][game.away_team.abbrev][1] += 1
standings[game.game_type][game.away_team.abbrev][2] -= run_diff
elif run_diff < 0: # Home team won
if game.away_team_id == team_id: # Human is away team
standings[game.game_type][game.home_team.abbrev][1] += 1
standings[game.game_type][game.home_team.abbrev][2] += run_diff
else:
if game.away_team_id == team_id:
standings[game.game_type][game.home_team.abbrev][1] += 1
standings[game.game_type][game.home_team.abbrev][2] += run_diff
else:
standings[game.game_type][game.home_team.abbrev][0] += 1
standings[game.game_type][game.home_team.abbrev][2] += run_diff
standings[game.game_type][game.home_team.abbrev][2] -= run_diff
else: # Human is home team
standings[game.game_type][game.away_team.abbrev][0] += 1
standings[game.game_type][game.away_team.abbrev][2] -= run_diff
# for lg_query in [minor_games, major_games, hof_games]:
# this_lg = copy.deepcopy(template)
@ -963,7 +963,7 @@ async def patch_team(
collection_value: Optional[int] = None, logo: Optional[str] = None, color: Optional[str] = None,
season: Optional[int] = None, ps_shiny: Optional[int] = None, wallet_delta: Optional[int] = None,
has_guide: Optional[bool] = None, is_ai: Optional[bool] = None, ranking: Optional[int] = None,
token: str = Depends(oauth2_scheme)):
token: str = Depends(oauth2_scheme), abbrev: Optional[str] = None):
if not valid_token(token):
logging.warning(f'Bad Token: {token}')
db.close()
@ -977,6 +977,8 @@ async def patch_team(
db.close()
raise HTTPException(status_code=404, detail=f'No team found with id {team_id}')
if abbrev is not None:
this_team.abbrev = abbrev
if sname is not None:
this_team.sname = sname
if lname is not None: