From b40409e844fd3608c7be30b021c84a16f6ba646d Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sat, 21 Oct 2023 15:30:46 -0500 Subject: [PATCH] Update card_creation.py Calculate slash line once card creation is complete --- app/card_creation.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/card_creation.py b/app/card_creation.py index 42860ad..e0e98c2 100644 --- a/app/card_creation.py +++ b/app/card_creation.py @@ -127,6 +127,21 @@ class BattingCardRatingsModel(pydantic.BaseModel): self.groundout_a, self.groundout_b, self.groundout_c ])) + def update_slash_lines(self): + self.avg = Decimal( + (self.homerun + self.bp_homerun / 2 + self.triple + self.double_three + + self.double_two + self.double_pull + self.single_two + self.single_one + + self.single_center + self.bp_single / 2) / Decimal(108) + ) + + self.obp = Decimal(((self.hbp + self.walk) / 108) + self.avg) + + self.slg = Decimal( + (self.homerun * 4 + self.bp_homerun * 2 + self.triple * 3 + self.double_three * 2 + + self.double_two * 2 + self.double_pull * 2 + self.single_two + self.single_one + + self.single_center + self.bp_single / 2) / 108 + ) + class PitchingCardRatingsModel(pydantic.BaseModel): pitchingcard: int @@ -171,6 +186,20 @@ class PitchingCardRatingsModel(pydantic.BaseModel): self.xcheck_cf, self.xcheck_rf ])) + def update_slash_lines(self): + self.avg = Decimal( + (self.homerun + self.bp_homerun / 2 + self.triple + self.double_three + + self.double_two + self.double_cf + self.single_two + self.single_one + + self.single_center + self.bp_single / 2) / Decimal(108) + ) + + self.obp = Decimal(((self.hbp + self.walk) / 108) + self.avg) + + self.slg = Decimal( + (self.homerun * 4 + self.bp_homerun * 2 + self.triple * 3 + self.double_three * 2 + + self.double_two * 2 + self.double_cf * 2 + self.single_two + self.single_one + + self.single_center + self.bp_single / 2) / 108) + class CardResult(pydantic.BaseModel): result_one: str = None @@ -2036,6 +2065,7 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions full_log(new_ratings, card) + new_ratings.update_slash_lines() new_battingratings.append(new_ratings) vl_output = vl.card_output() @@ -2901,6 +2931,7 @@ def get_pitcher_card_data(player, pitching_card, ratings_vl, ratings_vr, positio full_log(new_ratings, card) card.add_fatigue() + new_ratings.update_slash_lines() new_pitchingratings.append(new_ratings) vl_output = vl.card_output()