Update stratplay.py
add catcher & defender checks
This commit is contained in:
parent
b259f8b693
commit
03956191ab
@ -118,7 +118,8 @@ class PlayList(BaseModel):
|
|||||||
@router.get('') # Want to add runner parameters
|
@router.get('') # Want to add runner parameters
|
||||||
async def get_plays(
|
async def get_plays(
|
||||||
game_id: list = Query(default=None), batter_id: list = Query(default=None), season: list = Query(default=None),
|
game_id: list = Query(default=None), batter_id: list = Query(default=None), season: list = Query(default=None),
|
||||||
week: list = Query(default=None),
|
week: list = Query(default=None), has_defender: Optional[bool] = None, has_catcher: Optional[bool] = None,
|
||||||
|
has_defenderorcatcher: Optional[bool] = None,
|
||||||
pitcher_id: list = Query(default=None), obc: list = Query(default=None), inning: list = Query(default=None),
|
pitcher_id: list = Query(default=None), obc: list = Query(default=None), inning: list = Query(default=None),
|
||||||
batting_order: list = Query(default=None), starting_outs: list = Query(default=None),
|
batting_order: list = Query(default=None), starting_outs: list = Query(default=None),
|
||||||
batter_pos: list = Query(default=None), catcher_id: list = Query(default=None),
|
batter_pos: list = Query(default=None), catcher_id: list = Query(default=None),
|
||||||
@ -132,6 +133,20 @@ async def get_plays(
|
|||||||
short_output: Optional[bool] = False, sort: Optional[str] = None, limit: Optional[int] = 200):
|
short_output: Optional[bool] = False, sort: Optional[str] = None, limit: Optional[int] = 200):
|
||||||
all_plays = StratPlay.select()
|
all_plays = StratPlay.select()
|
||||||
|
|
||||||
|
if season is not None:
|
||||||
|
s_games = StratGame.select().where(StratGame.season << season)
|
||||||
|
all_plays = all_plays.where(StratPlay.game << s_games)
|
||||||
|
if week is not None:
|
||||||
|
w_games = StratGame.select().where(StratGame.week << week)
|
||||||
|
all_plays = all_plays.where(StratPlay.game << w_games)
|
||||||
|
if has_defender is not None:
|
||||||
|
all_plays = all_plays.where(StratPlay.defender.is_null(False))
|
||||||
|
if has_catcher is not None:
|
||||||
|
all_plays = all_plays.where(StratPlay.catcher.is_null(False))
|
||||||
|
if has_defenderorcatcher is not None:
|
||||||
|
all_plays = all_plays.where(
|
||||||
|
(StratPlay.catcher.is_null(False)) | (StratPlay.defender.is_null(False))
|
||||||
|
)
|
||||||
if game_id is not None:
|
if game_id is not None:
|
||||||
all_plays = all_plays.where(StratPlay.game_id << game_id)
|
all_plays = all_plays.where(StratPlay.game_id << game_id)
|
||||||
if batter_id is not None:
|
if batter_id is not None:
|
||||||
@ -162,8 +177,7 @@ async def get_plays(
|
|||||||
if defense_team_id is not None:
|
if defense_team_id is not None:
|
||||||
all_teams = Team.select().where(Team.id << defense_team_id)
|
all_teams = Team.select().where(Team.id << defense_team_id)
|
||||||
all_plays = all_plays.where(
|
all_plays = all_plays.where(
|
||||||
(StratPlay.pitcher_team << all_teams) | (StratPlay.catcher_team << all_teams) |
|
(StratPlay.catcher_team << all_teams) | (StratPlay.defender_team << all_teams)
|
||||||
(StratPlay.defender_team << all_teams)
|
|
||||||
)
|
)
|
||||||
if double is not None:
|
if double is not None:
|
||||||
all_plays = all_plays.where(StratPlay.double == double)
|
all_plays = all_plays.where(StratPlay.double == double)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user