Added obc and risp as parameters to plays/batting and /pitching

This commit is contained in:
Cal Corum 2023-08-18 14:52:43 -05:00
parent 85c8b441fa
commit 3ebf9698b2

View File

@ -239,6 +239,7 @@ async def get_batting_totals(
s_type: Literal['regular', 'post', 'total', None] = None, position: list = Query(default=None), s_type: Literal['regular', 'post', 'total', None] = None, position: list = Query(default=None),
player_id: list = Query(default=None), group_by: Literal['team', 'player', 'playerteam'] = 'player', player_id: list = Query(default=None), group_by: Literal['team', 'player', 'playerteam'] = 'player',
min_pa: Optional[int] = 1, team_id: list = Query(default=None), manager_id: list = Query(default=None), min_pa: Optional[int] = 1, team_id: list = Query(default=None), manager_id: list = Query(default=None),
obc: list = Query(default=None), risp: Optional[bool] = None,
sort: Optional[str] = None, limit: Optional[int] = None, short_output: Optional[bool] = False): sort: Optional[str] = None, limit: Optional[int] = None, short_output: Optional[bool] = False):
season_games = StratGame.select() season_games = StratGame.select()
if season is not None: if season is not None:
@ -295,6 +296,11 @@ async def get_batting_totals(
if position is not None: if position is not None:
bat_plays = bat_plays.where(StratPlay.batter_pos << position) bat_plays = bat_plays.where(StratPlay.batter_pos << position)
if obc is not None:
bat_plays = bat_plays.where(StratPlay.on_base_code << obc)
if risp is not None:
bat_plays = bat_plays.where(StratPlay.on_base_code << ['100', '101', '110', '111', '010', '011'])
if group_by is not None: if group_by is not None:
if group_by == 'player': if group_by == 'player':
bat_plays = bat_plays.group_by(StratPlay.batter) bat_plays = bat_plays.group_by(StratPlay.batter)
@ -399,6 +405,7 @@ async def get_pitching_totals(
s_type: Literal['regular', 'post', 'total', None] = None, s_type: Literal['regular', 'post', 'total', None] = None,
player_id: list = Query(default=None), group_by: Literal['team', 'player', 'playerteam'] = 'player', player_id: list = Query(default=None), group_by: Literal['team', 'player', 'playerteam'] = 'player',
min_pa: Optional[int] = 1, team_id: list = Query(default=None), manager_id: list = Query(default=None), min_pa: Optional[int] = 1, team_id: list = Query(default=None), manager_id: list = Query(default=None),
obc: list = Query(default=None), risp: Optional[bool] = None,
sort: Optional[str] = None, limit: Optional[int] = None, short_output: Optional[bool] = False): sort: Optional[str] = None, limit: Optional[int] = None, short_output: Optional[bool] = False):
season_games = StratGame.select() season_games = StratGame.select()
if season is not None: if season is not None:
@ -445,6 +452,11 @@ async def get_pitching_totals(
all_teams = Team.select().where(Team.id << team_id) all_teams = Team.select().where(Team.id << team_id)
pit_plays = pit_plays.where(StratPlay.pitcher_team << all_teams) pit_plays = pit_plays.where(StratPlay.pitcher_team << all_teams)
if obc is not None:
pit_plays = pit_plays.where(StratPlay.on_base_code << obc)
if risp is not None:
pit_plays = pit_plays.where(StratPlay.on_base_code << ['100', '101', '110', '111', '010', '011'])
if group_by is not None: if group_by is not None:
if group_by == 'player': if group_by == 'player':
pit_plays = pit_plays.group_by(StratPlay.pitcher) pit_plays = pit_plays.group_by(StratPlay.pitcher)