Added gauntlet query param
This commit is contained in:
parent
633db7f565
commit
58a0d10226
@ -326,7 +326,9 @@ async def get_plays(
|
||||
async def get_batting_totals(
|
||||
season: list = Query(default=None), week: list = Query(default=None), position: list = Query(default=None),
|
||||
player_id: list = Query(default=None), min_wpa: Optional[float] = -999, max_wpa: Optional[float] = 999,
|
||||
group_by: Literal['team', 'player', 'playerteam', 'playergame', 'teamgame', 'league', 'gametype'] = 'player',
|
||||
group_by: Literal[
|
||||
'team', 'player', 'playerteam', 'playergame', 'teamgame', 'league', 'gmtype', 'playergtype',
|
||||
'playerteamgtype'] = 'player', is_gauntlet: Optional[bool] = None,
|
||||
min_pa: Optional[int] = 1, team_id: list = Query(default=None), inning: list = Query(default=None),
|
||||
obc: list = Query(default=None), risp: Optional[bool] = None, game_type: list = Query(default=None),
|
||||
page_num: Optional[int] = 1, sort: Optional[str] = 'pa-desc', limit: Optional[int] = 500,
|
||||
@ -409,6 +411,9 @@ async def get_batting_totals(
|
||||
all_games = StratGame.select().where(fn.Lower(StratGame.game_type) << all_types)
|
||||
bat_plays = bat_plays.where(StratPlay.game << all_games)
|
||||
run_plays = run_plays.where(StratPlay.game << all_games)
|
||||
if is_gauntlet is not None:
|
||||
all_games = StratGame.select().where(fn.Lower(StratGame.game_type).contains('gauntlet'))
|
||||
bat_plays = bat_plays.where(StratPlay.game << all_games)
|
||||
|
||||
if group_by is not None:
|
||||
if group_by == 'player':
|
||||
@ -436,11 +441,18 @@ async def get_batting_totals(
|
||||
bat_plays = bat_plays.group_by(StratPlay.game.game_type)
|
||||
run_plays = run_plays.join(StratGame)
|
||||
run_plays = run_plays.group_by(StratPlay.game.game_type)
|
||||
elif group_by == 'playerteamgametype':
|
||||
elif group_by == 'playergtype':
|
||||
bat_plays = bat_plays.join(StratGame)
|
||||
bat_plays = bat_plays.group_by(StratPlay.batter, StratPlay.batter_team, StratPlay.game.game_type)
|
||||
bat_plays = bat_plays.group_by(StratPlay.batter, StratPlay.game.game_type)
|
||||
run_plays = run_plays.join(StratGame)
|
||||
run_plays = run_plays.group_by(StratPlay.runner, StratPlay.runner_team, StratPlay.game.game_type)
|
||||
run_plays = run_plays.group_by(StratPlay.runner, StratPlay.game.game_type)
|
||||
elif group_by == 'playerteamgtype':
|
||||
bat_plays = bat_plays.join(StratGame)
|
||||
bat_plays = bat_plays.group_by(
|
||||
StratPlay.batter, StratPlay.batter_team, StratPlay.game.game_type)
|
||||
run_plays = run_plays.join(StratGame)
|
||||
run_plays = run_plays.group_by(
|
||||
StratPlay.runner, StratPlay.runner_team, StratPlay.game.game_type)
|
||||
|
||||
if sort is not None:
|
||||
if sort == 'player':
|
||||
@ -488,6 +500,10 @@ async def get_batting_totals(
|
||||
this_run = this_run.where(StratPlay.runner == x.batter)
|
||||
if 'game' in group_by:
|
||||
this_run = this_run.where(StratPlay.game == x.game)
|
||||
if 'team' in group_by:
|
||||
this_run = this_run.where(StratPlay.runner_team == x.batter_team)
|
||||
if 'gtype' in group_by:
|
||||
this_run = this_run.where(StratPlay.game.game_type == x.game.game_type)
|
||||
|
||||
if this_run.count() > 0:
|
||||
sum_sb = this_run[0].sum_sb
|
||||
@ -515,6 +531,8 @@ async def get_batting_totals(
|
||||
this_game = 'TOT'
|
||||
if group_by in ['playergame', 'teamgame']:
|
||||
this_game = x.game_id if short_output else model_to_dict(x.game, recurse=False)
|
||||
elif 'gtype' in group_by:
|
||||
this_game = x.game.game_type
|
||||
|
||||
lob_all_rate, lob_2outs_rate, rbi_rate = 0, 0, 0
|
||||
if x.count_runner1 + x.count_runner2 + x.count_runner3 > 0:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user