From 0c77f3971da408b0aadbe24156703742b1740ac9 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sun, 28 Apr 2024 15:32:05 -0500 Subject: [PATCH] S7 cleanup and SSS bug fixes --- batters/calcs_batter.py | 15 +++++++++------ batters/creation.py | 10 +++++----- defenders/calcs_defense.py | 8 ++++---- pitchers/calcs_pitcher.py | 4 ++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/batters/calcs_batter.py b/batters/calcs_batter.py index f1ced48..5e67959 100644 --- a/batters/calcs_batter.py +++ b/batters/calcs_batter.py @@ -112,7 +112,7 @@ class BattingCardRatingsModel(pydantic.BaseModel): self.double_pull = sanitize_chance_output(tot_doubles - self.double_two) self.rem_xbh -= Decimal(self.double_two + self.double_pull) - if self.rem_xbh > Decimal(0): + if (self.rem_xbh > Decimal(0)) and szn_hr > 0: self.bp_homerun = bp_homeruns(self.rem_xbh, hr_per_fb) self.homerun = sanitize_chance_output(self.rem_xbh - self.bp_homerun, min_chances=0.5) self.rem_xbh -= Decimal(self.bp_homerun + self.homerun) @@ -354,11 +354,14 @@ def stealing(chances: int, sb2s: int, cs2s: int, sb3s: int, cs3s: int, season_pc st_auto = False # chance_odds = [x / 36 for x in range(1, 36)] - st_jump = 0 - for x in range(1, 37): - if attempt_pct * 1.5 <= x / 36: - st_jump = x / 36 - break + if attempt_pct * 1.5 >= 1.0: + st_jump = 1.0 + else: + st_jump = 0 + for x in range(1, 37): + if attempt_pct * 1.5 <= x / 36: + st_jump = x / 36 + break st_high = mround(20 * (sb2s / (sb2s + cs2s + cs2s))) if st_high <= 10: diff --git a/batters/creation.py b/batters/creation.py index d1ff273..535fa9b 100644 --- a/batters/creation.py +++ b/batters/creation.py @@ -151,11 +151,11 @@ async def calculate_batting_cards(offense_stats: pd.DataFrame, cardset: dict, se def create_batting_card(df_data): logging.info(df_data['player_id']) s_data = cba.stealing( - chances=df_data['SBO'], - sb2s=df_data['SB2'], - cs2s=df_data['CS2'], - sb3s=df_data['SB3'], - cs3s=df_data['CS3'], + chances=int(df_data['SBO']), + sb2s=int(df_data['SB2']), + cs2s=int(df_data['CS2']), + sb3s=int(df_data['SB3']), + cs3s=int(df_data['CS3']), season_pct=season_pct ) batting_cards.append({ diff --git a/defenders/calcs_defense.py b/defenders/calcs_defense.py index ed536fb..e4e5e02 100644 --- a/defenders/calcs_defense.py +++ b/defenders/calcs_defense.py @@ -14,7 +14,7 @@ async def create_positions( df_rf: pd.DataFrame, df_of: pd.DataFrame): position_payload = [] - def create_positions(df_data): + def process_pos(df_data): no_data = True for pos_data in [(df_1b, '1b'), (df_2b, '2b'), (df_3b, '3b'), (df_ss, 'ss')]: if df_data['key_bbref'] in pos_data[0].index: @@ -127,7 +127,7 @@ async def create_positions( }) print(f'Calculating fielding lines now...') - all_stats.apply(create_positions, axis=1) + all_stats.apply(process_pos, axis=1) print(f'Fielding is complete.\n\nPosting positions now...') if post_pos: resp = await db_put('cardpositions', payload={'positions': position_payload}, timeout=30) @@ -301,8 +301,8 @@ def valid_error_ratings(err_num: int, position: str) -> int: def raw_error(errors: int, chances: int, season_pct: float, chance_max: int): if errors == 0 or chances == 0: return 0 - c_max = max(round(chance_max * season_pct), 1) - # c_max = chance_max + # c_max = max(round(chance_max * season_pct), 1) + c_max = chance_max return errors * c_max / chances diff --git a/pitchers/calcs_pitcher.py b/pitchers/calcs_pitcher.py index aaf41ce..f722561 100644 --- a/pitchers/calcs_pitcher.py +++ b/pitchers/calcs_pitcher.py @@ -540,13 +540,13 @@ def groundball_a(all_gb, dp_rate): def balks(total_balks: int, innings: float, season_pct): if innings == 0: return 0 - return min(round((total_balks * 290 * season_pct) / innings), 20) + return min(round((int(total_balks) * 290 * season_pct) / float(innings)), 20) def wild_pitches(total_wps: int, innings: float, season_pct): if innings == 0: return 0 - return min(round((total_wps * 200 * season_pct) / innings), 20) + return min(round((int(total_wps) * 200 * season_pct) / float(innings)), 20) def closer_rating(gf: int, saves: int, games: int):