From c5b546d0ed46967cf60cbd2109837efbd1d20b28 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 15 Nov 2024 16:52:29 -0600 Subject: [PATCH 1/2] Align home_score with runs_scored for pythag record --- app/db_engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/db_engine.py b/app/db_engine.py index 44bbfcd..807e7aa 100644 --- a/app/db_engine.py +++ b/app/db_engine.py @@ -608,8 +608,8 @@ class Team(BaseModel): fn.SUM(StratGame.away_score).alias('r_them') ).where((StratGame.home_team == self) & StratGame.game_num.is_null(False)) if home_games.count() > 0: - runs_scored += home_games[0].r_them - runs_allowed += home_games[0].r_us + runs_scored += home_games[0].r_us + runs_allowed += home_games[0].r_them if runs_allowed == 0: pythag_win_pct = 1 From df73e494061004d5ade2ee3fef565d9953127dbc Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 16 Nov 2024 09:12:30 -0600 Subject: [PATCH 2/2] Improve alias naming --- app/db_engine.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/db_engine.py b/app/db_engine.py index 807e7aa..ad6b32a 100644 --- a/app/db_engine.py +++ b/app/db_engine.py @@ -596,20 +596,20 @@ class Team(BaseModel): runs_scored, runs_allowed = 0, 0 away_games = StratGame.select( - StratGame.away_team, fn.SUM(StratGame.away_score).alias('r_us'), - fn.SUM(StratGame.home_score).alias('r_them') + StratGame.away_team, fn.SUM(StratGame.away_score).alias('r_scored'), + fn.SUM(StratGame.home_score).alias('r_allowed') ).where((StratGame.away_team == self) & StratGame.game_num.is_null(False)) if away_games.count() > 0: - runs_scored += away_games[0].r_us - runs_allowed += away_games[0].r_them + runs_scored += away_games[0].r_scored + runs_allowed += away_games[0].r_allowed home_games = StratGame.select( - StratGame.home_team, fn.SUM(StratGame.home_score).alias('r_us'), - fn.SUM(StratGame.away_score).alias('r_them') + StratGame.home_team, fn.SUM(StratGame.home_score).alias('r_scored'), + fn.SUM(StratGame.away_score).alias('r_allowed') ).where((StratGame.home_team == self) & StratGame.game_num.is_null(False)) if home_games.count() > 0: - runs_scored += home_games[0].r_us - runs_allowed += home_games[0].r_them + runs_scored += home_games[0].r_scored + runs_allowed += home_games[0].r_allowed if runs_allowed == 0: pythag_win_pct = 1