S7 cleanup and SSS bug fixes

This commit is contained in:
Cal Corum 2024-04-28 15:32:05 -05:00
parent 63b5487c44
commit 0c77f3971d
4 changed files with 20 additions and 17 deletions

View File

@ -112,7 +112,7 @@ class BattingCardRatingsModel(pydantic.BaseModel):
self.double_pull = sanitize_chance_output(tot_doubles - self.double_two) self.double_pull = sanitize_chance_output(tot_doubles - self.double_two)
self.rem_xbh -= Decimal(self.double_two + self.double_pull) 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.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.homerun = sanitize_chance_output(self.rem_xbh - self.bp_homerun, min_chances=0.5)
self.rem_xbh -= Decimal(self.bp_homerun + self.homerun) 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 st_auto = False
# chance_odds = [x / 36 for x in range(1, 36)] # chance_odds = [x / 36 for x in range(1, 36)]
st_jump = 0 if attempt_pct * 1.5 >= 1.0:
for x in range(1, 37): st_jump = 1.0
if attempt_pct * 1.5 <= x / 36: else:
st_jump = x / 36 st_jump = 0
break 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))) st_high = mround(20 * (sb2s / (sb2s + cs2s + cs2s)))
if st_high <= 10: if st_high <= 10:

View File

@ -151,11 +151,11 @@ async def calculate_batting_cards(offense_stats: pd.DataFrame, cardset: dict, se
def create_batting_card(df_data): def create_batting_card(df_data):
logging.info(df_data['player_id']) logging.info(df_data['player_id'])
s_data = cba.stealing( s_data = cba.stealing(
chances=df_data['SBO'], chances=int(df_data['SBO']),
sb2s=df_data['SB2'], sb2s=int(df_data['SB2']),
cs2s=df_data['CS2'], cs2s=int(df_data['CS2']),
sb3s=df_data['SB3'], sb3s=int(df_data['SB3']),
cs3s=df_data['CS3'], cs3s=int(df_data['CS3']),
season_pct=season_pct season_pct=season_pct
) )
batting_cards.append({ batting_cards.append({

View File

@ -14,7 +14,7 @@ async def create_positions(
df_rf: pd.DataFrame, df_of: pd.DataFrame): df_rf: pd.DataFrame, df_of: pd.DataFrame):
position_payload = [] position_payload = []
def create_positions(df_data): def process_pos(df_data):
no_data = True no_data = True
for pos_data in [(df_1b, '1b'), (df_2b, '2b'), (df_3b, '3b'), (df_ss, 'ss')]: 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: if df_data['key_bbref'] in pos_data[0].index:
@ -127,7 +127,7 @@ async def create_positions(
}) })
print(f'Calculating fielding lines now...') 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...') print(f'Fielding is complete.\n\nPosting positions now...')
if post_pos: if post_pos:
resp = await db_put('cardpositions', payload={'positions': position_payload}, timeout=30) 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): def raw_error(errors: int, chances: int, season_pct: float, chance_max: int):
if errors == 0 or chances == 0: if errors == 0 or chances == 0:
return 0 return 0
c_max = max(round(chance_max * season_pct), 1) # c_max = max(round(chance_max * season_pct), 1)
# c_max = chance_max c_max = chance_max
return errors * c_max / chances return errors * c_max / chances

View File

@ -540,13 +540,13 @@ def groundball_a(all_gb, dp_rate):
def balks(total_balks: int, innings: float, season_pct): def balks(total_balks: int, innings: float, season_pct):
if innings == 0: if innings == 0:
return 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): def wild_pitches(total_wps: int, innings: float, season_pct):
if innings == 0: if innings == 0:
return 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): def closer_rating(gf: int, saves: int, games: int):