Standings updates
Added /standings/team/{id} endpoint
Fixed pythag calculation
This commit is contained in:
parent
5110d8b497
commit
f6e9e6c7fd
@ -1,4 +1,6 @@
|
||||
import copy
|
||||
import datetime
|
||||
import logging
|
||||
import math
|
||||
from typing import Literal
|
||||
|
||||
@ -14,6 +16,13 @@ db = SqliteDatabase(
|
||||
}
|
||||
)
|
||||
|
||||
date = f'{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}'
|
||||
logging.basicConfig(
|
||||
filename=f'logs/database/{date}.log',
|
||||
format='%(asctime)s - database - %(levelname)s - %(message)s',
|
||||
level=logging.INFO
|
||||
)
|
||||
|
||||
|
||||
"""
|
||||
Per season updates:
|
||||
@ -529,16 +538,18 @@ class Team(BaseModel):
|
||||
|
||||
runs_scored, runs_allowed = 0, 0
|
||||
away_games = StratGame.select(
|
||||
fn.SUM(StratGame.away_score).alias('r_us'), fn.SUM(StratGame.home_score).alias('r_them')
|
||||
).where(StratGame.away_team == self & StratGame.game_num.is_null(False))
|
||||
StratGame.away_team, fn.SUM(StratGame.away_score).alias('r_us'),
|
||||
fn.SUM(StratGame.home_score).alias('r_them')
|
||||
).where((StratGame.away_team == self) & StratGame.game_num.is_null(False))
|
||||
if away_games.count() > 0:
|
||||
runs_scored += away_games[0].r_us
|
||||
runs_allowed += away_games[0].r_them
|
||||
|
||||
home_games = StratGame.select(
|
||||
fn.SUM(StratGame.home_score).alias('r_us'), fn.SUM(StratGame.away_score).alias('r_them')
|
||||
).where(StratGame.home_team == self & StratGame.game_num.is_null(False))
|
||||
if away_games.count() > 0:
|
||||
StratGame.home_team, fn.SUM(StratGame.home_score).alias('r_us'),
|
||||
fn.SUM(StratGame.away_score).alias('r_them')
|
||||
).where((StratGame.home_team == self) & StratGame.game_num.is_null(False))
|
||||
if home_games.count() > 0:
|
||||
runs_scored += home_games[0].r_them
|
||||
runs_allowed += home_games[0].r_us
|
||||
|
||||
|
||||
@ -59,6 +59,15 @@ async def get_standings(
|
||||
return return_standings
|
||||
|
||||
|
||||
@router.get('/team/{team_id}')
|
||||
async def get_team_standings(team_id: int):
|
||||
this_stan = Standings.get_or_none(Standings.team_id == team_id)
|
||||
if this_stan is None:
|
||||
raise HTTPException(status_code=404, detail=f'No standings found for team id {team_id}')
|
||||
|
||||
return model_to_dict(this_stan)
|
||||
|
||||
|
||||
@router.patch('/{stan_id}')
|
||||
async def patch_standings(
|
||||
stan_id, wins: Optional[int] = None, losses: Optional[int] = None, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user