diff --git a/app/routers_v3/stratplay.py b/app/routers_v3/stratplay.py index 380d2e6..f9a4544 100644 --- a/app/routers_v3/stratplay.py +++ b/app/routers_v3/stratplay.py @@ -1,3 +1,4 @@ +import copy from itertools import groupby from tokenize import group @@ -1000,14 +1001,24 @@ async def get_fielding_totals( # sum_error = x.sum_error this_pos = 'TOT' - this_cat = StratPlay.select().where(StratPlay.play_num < 0) if 'position' in group_by: this_pos = x.check_pos - if this_pos == 'C' and 'player' in group_by: - if 'player' in group_by: - this_cat = cat_plays.where(StratPlay.catcher == x.defender) - if 'game' in group_by: - this_cat = cat_plays.where(StratPlay.game == x.game) + + this_cat = cat_plays.order_by(StratPlay.id) + if group_by in ['player', 'playerposition']: + this_cat = this_cat.where(StratPlay.catcher == x.defender) + elif group_by in ['team', 'teamposition']: + this_cat = this_cat.where(StratPlay.catcher_team == x.defender_team) + elif group_by in ['playerteam', 'playerteamposition']: + this_cat = this_cat.where((StratPlay.catcher == x.defender) & (StratPlay.catcher_team == x.defender_team)) + elif group_by in ['playergame', 'playerpositiongame']: + this_cat = this_cat.where((StratPlay.catcher == x.defender) & (StratPlay.game == x.game)) + elif group_by == 'playerweek': + this_cat = this_cat.where((StratPlay.catcher == x.defender) & (StratPlay.game.week == x.game.week)) + elif group_by == 'teamweek': + this_cat = this_cat.where((StratPlay.catcher_team == x.defender_team) & (StratPlay.game.week == x.game.week)) + + this_cat = this_cat.where(StratPlay.game == x.game) if this_cat.count() > 0: sum_sb = this_cat[0].sum_sb @@ -1022,9 +1033,9 @@ async def get_fielding_totals( sum_pb = 0 sum_error = x.sum_error - this_player = x.defender_id if short_output else model_to_dict(x.defender, recurse=False) - if group_by == 'teamposition': - this_player = 'TOT' + this_player = 'TOT' + if 'player' in group_by: + this_player = x.defender_id if short_output else model_to_dict(x.defender, recurse=False) this_game = 'TOT' if 'game' in group_by: