Update stratplay.py

This commit is contained in:
Cal Corum 2023-08-03 23:05:20 -05:00
parent 6396250bf6
commit 474448556e

View File

@ -114,7 +114,7 @@ class PlayList(BaseModel):
plays: List[PlayModel]
@router.get('')
@router.get('') # Want to add runner parameters
async def get_plays(
game_id: list = Query(default=None), batter_id: list = Query(default=None),
pitcher_id: list = Query(default=None), obc: list = Query(default=None), inning: list = Query(default=None),
@ -124,7 +124,8 @@ async def get_plays(
offense_team_id: list = Query(default=None), defense_team_id: list = Query(default=None),
double: Optional[int] = None, triple: Optional[int] = None, homerun: Optional[int] = None,
sb: Optional[int] = None, cs: Optional[int] = None, manager_id: list = Query(default=None),
outs: list = Query(default=None), wild_pitch: Optional[int] = None,
outs: list = Query(default=None), wild_pitch: Optional[int] = None, is_final_out: Optional[bool] = None,
is_go_ahead: Optional[bool] = None, is_tied: Optional[bool] = None, is_new_inning: Optional[bool] = None,
short_output: Optional[bool] = False, sort: Optional[str] = None, limit: Optional[int] = 200):
all_plays = StratPlay.select()
@ -180,6 +181,14 @@ async def get_plays(
(StratGame.away_manager_id << manager_id) | (StratGame.home_manager_id << manager_id)
)
all_plays = all_plays.where(StratPlay.game << all_games)
if is_final_out is not None:
all_plays = all_plays.where(StratPlay.starting_outs + StratPlay.outs == 3)
if is_go_ahead is not None:
all_plays = all_plays.where(StratPlay.is_go_ahead == is_go_ahead)
if is_tied is not None:
all_plays = all_plays.where(StratPlay.is_tied == is_tied)
if is_new_inning is not None:
all_plays = all_plays.where(StratPlay.is_new_inning == is_new_inning)
if limit > 5000:
limit = 5000
@ -332,7 +341,13 @@ async def get_totalplays(
'bpfo': x.sum_bpfo,
'bp1b': x.sum_bp1b,
'bplo': x.sum_bplo,
'wpa': x.sum_wpa + sum_wpa
'wpa': x.sum_wpa + sum_wpa,
'avg': x.sum_hit / x.sum_ab,
'obp': (x.sum_hit + x.sum_bb + x.sum_hbp + x.sum_ibb) / x.sum_pa,
'slg': (x.sum_hr * 4 + x.sum_triple * 3 + x.sum_double * 2 +
(x.sum_hit - x.sum_double - x.sum_triple - x.sum_hr)) / x.sum_ab,
'woba': (.69 * x.sum_bb + .72 * x.sum_hbp + .89 * (x.sum_hit - x.sum_double - x.sum_triple - x.sum_hr) +
1.27 * x.sum_double + 1.62 * x.sum_triple + 2.1 * x.sum_hr) / (x.sum_pa - x.sum_ibb)
})
# Get Running Stats