Merge pull request #3 from calcorum/fix-pythag-record

Align home_score with runs_scored for pythag record
This commit is contained in:
Cal Corum 2024-11-16 11:49:43 -06:00 committed by GitHub
commit 856f804b0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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_them
runs_allowed += home_games[0].r_us
runs_scored += home_games[0].r_scored
runs_allowed += home_games[0].r_allowed
if runs_allowed == 0:
pythag_win_pct = 1