Calc rate stats on batting ratings for cost calcs

This commit is contained in:
Cal Corum 2024-10-20 22:56:58 -05:00
parent 2ef68915d1
commit eb79430de7
2 changed files with 10 additions and 7 deletions

View File

@ -167,14 +167,14 @@ class BattingCardRatingsModel(pydantic.BaseModel):
self.groundout_b = self.rem_outs() self.groundout_b = self.rem_outs()
def calculate_rate_stats(self): def calculate_rate_stats(self):
self.avg = mround(round(self.total_hits() / 108, 3)) self.avg = mround(self.total_hits() / 108, prec=5, base=0.0001)
self.obp = mround(round((self.total_hits() + self.hbp + self.walk) / 108, 3)) self.obp = mround((self.total_hits() + self.hbp + self.walk) / 108, prec=5, base=0.0001)
self.slg = mround(round( self.slg = mround((
self.homerun * 4 + self.triple * 3 + self.single_center + self.single_two + self.single_two + self.homerun * 4 + self.triple * 3 + self.single_center + self.single_two + self.single_two +
(self.double_two + self.double_three + self.double_two + self.bp_homerun) * 2 + self.bp_single / 2 (self.double_two + self.double_three + self.double_two + self.bp_homerun) * 2 + self.bp_single / 2) / 108, prec=5, base=0.0001)
))
def custom_to_dict(self): def custom_to_dict(self):
self.calculate_rate_stats()
return { return {
'battingcard_id': self.battingcard_id, 'battingcard_id': self.battingcard_id,
'vs_hand': self.vs_hand, 'vs_hand': self.vs_hand,
@ -202,7 +202,10 @@ class BattingCardRatingsModel(pydantic.BaseModel):
'groundout_c': self.groundout_c, 'groundout_c': self.groundout_c,
'pull_rate': self.pull_rate, 'pull_rate': self.pull_rate,
'center_rate': self.center_rate, 'center_rate': self.center_rate,
'slap_rate': self.slap_rate 'slap_rate': self.slap_rate,
'avg': self.avg,
'obp': self.obp,
'slg': self.slg
} }
# def total_chances(chance_data): # def total_chances(chance_data):

View File

@ -482,7 +482,7 @@ def hold_pitcher(raw_cs: str, picks: int, season_pct: float) -> str:
# return f'{"+" if final_hold >= 0 else ""}{final_hold}' # return f'{"+" if final_hold >= 0 else ""}{final_hold}'
def pow_ratings(innings: float, gs: int, games: int) -> (int, int): def pow_ratings(innings: float, gs: int, games: int) -> tuple[int, int]:
if innings <= 1 or games <= 1: if innings <= 1 or games <= 1:
return 1, 1 return 1, 1