Add fatigue to pitcher cards
This commit is contained in:
parent
ed6e73528f
commit
47d7a7cad4
@ -313,10 +313,9 @@ class CardColumn(pydantic.BaseModel):
|
||||
if chances > Decimal(1.0):
|
||||
chances = Decimal(math.floor(chances))
|
||||
else:
|
||||
return False
|
||||
logging.error(f'Must have secondary play for fractional chances; could not round down to an integer\n'
|
||||
f'Play: {play}\nChances: {chances}\nSecondary Play: {secondary_play}')
|
||||
raise ValueError(f'Cannot assign fractional chances without secondary play')
|
||||
return False
|
||||
|
||||
# Chances is whole number
|
||||
if math.floor(chances) == chances:
|
||||
@ -945,6 +944,40 @@ class CardColumn(pydantic.BaseModel):
|
||||
total += 1 if self.twelve.is_full() else 0
|
||||
return total
|
||||
|
||||
def add_fatigue(self, num_chances: int, k_only: bool = False):
|
||||
def is_valid_result(this_result: CardResult):
|
||||
if k_only:
|
||||
if this_result.result_one == 'strikeout':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
if this_result.result_two is None and not this_result.bold_one and 'X' not in this_result.result_one:
|
||||
return True
|
||||
return False
|
||||
|
||||
if num_chances == 6:
|
||||
if is_valid_result(self.seven):
|
||||
self.seven.result_one += ' •'
|
||||
return 6
|
||||
elif num_chances == 5:
|
||||
if is_valid_result(self.six):
|
||||
self.six.result_one += ' •'
|
||||
return 5
|
||||
if is_valid_result(self.eight):
|
||||
self.eight.result_one += ' •'
|
||||
return 5
|
||||
|
||||
elif num_chances == 4:
|
||||
if is_valid_result(self.five):
|
||||
self.five.result_one += ' •'
|
||||
return 4
|
||||
if is_valid_result(self.nine):
|
||||
self.nine.result_one += ' •'
|
||||
return 4
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
class FullCard(pydantic.BaseModel):
|
||||
col_one: CardColumn = CardColumn()
|
||||
@ -959,6 +992,60 @@ class FullCard(pydantic.BaseModel):
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def get_columns(self, is_offense: bool):
|
||||
if is_offense:
|
||||
if self.offense_col == 1:
|
||||
first = self.col_one
|
||||
if self.alt_direction:
|
||||
second = self.col_two
|
||||
third = self.col_three
|
||||
else:
|
||||
second = self.col_three
|
||||
third = self.col_two
|
||||
elif self.offense_col == 2:
|
||||
first = self.col_two
|
||||
if self.alt_direction:
|
||||
second = self.col_three
|
||||
third = self.col_one
|
||||
else:
|
||||
second = self.col_one
|
||||
third = self.col_three
|
||||
else:
|
||||
first = self.col_three
|
||||
if self.alt_direction:
|
||||
second = self.col_one
|
||||
third = self.col_two
|
||||
else:
|
||||
second = self.col_two
|
||||
third = self.col_one
|
||||
else:
|
||||
if self.offense_col == 1:
|
||||
third = self.col_one
|
||||
if self.alt_direction:
|
||||
first = self.col_two
|
||||
second = self.col_three
|
||||
else:
|
||||
first = self.col_three
|
||||
second = self.col_two
|
||||
elif self.offense_col == 2:
|
||||
third = self.col_two
|
||||
if self.alt_direction:
|
||||
first = self.col_three
|
||||
second = self.col_one
|
||||
else:
|
||||
first = self.col_one
|
||||
second = self.col_three
|
||||
else:
|
||||
third = self.col_three
|
||||
if self.alt_direction:
|
||||
first = self.col_one
|
||||
second = self.col_two
|
||||
else:
|
||||
first = self.col_two
|
||||
second = self.col_one
|
||||
|
||||
return first, second, third
|
||||
|
||||
def is_complete(self):
|
||||
return self.col_one.is_full() and self.col_two.is_full() and self.col_three.is_full()
|
||||
|
||||
@ -969,56 +1056,7 @@ class FullCard(pydantic.BaseModel):
|
||||
f'Column 3\n{self.col_three}'
|
||||
|
||||
def add_result(self, play: PlayResult, chances: Decimal, secondary_play: Optional[PlayResult] = None):
|
||||
if play.is_offense:
|
||||
if self.offense_col == 1:
|
||||
first = self.col_one
|
||||
if self.alt_direction:
|
||||
second = self.col_two
|
||||
third = self.col_three
|
||||
else:
|
||||
second = self.col_three
|
||||
third = self.col_two
|
||||
elif self.offense_col == 2:
|
||||
first = self.col_two
|
||||
if self.alt_direction:
|
||||
second = self.col_three
|
||||
third = self.col_one
|
||||
else:
|
||||
second = self.col_one
|
||||
third = self.col_three
|
||||
else:
|
||||
first = self.col_three
|
||||
if self.alt_direction:
|
||||
second = self.col_one
|
||||
third = self.col_two
|
||||
else:
|
||||
second = self.col_two
|
||||
third = self.col_one
|
||||
else:
|
||||
if self.offense_col == 1:
|
||||
third = self.col_one
|
||||
if self.alt_direction:
|
||||
first = self.col_two
|
||||
second = self.col_three
|
||||
else:
|
||||
first = self.col_three
|
||||
second = self.col_two
|
||||
elif self.offense_col == 2:
|
||||
third = self.col_two
|
||||
if self.alt_direction:
|
||||
first = self.col_three
|
||||
second = self.col_one
|
||||
else:
|
||||
first = self.col_one
|
||||
second = self.col_three
|
||||
else:
|
||||
third = self.col_three
|
||||
if self.alt_direction:
|
||||
first = self.col_one
|
||||
second = self.col_two
|
||||
else:
|
||||
first = self.col_two
|
||||
second = self.col_one
|
||||
first, second, third = self.get_columns(is_offense=play.is_offense)
|
||||
|
||||
if 'gb' in play.full_name and chances + self.num_plusgb <= 6 and self.is_batter:
|
||||
play.full_name += '+'
|
||||
@ -1062,6 +1100,54 @@ class FullCard(pydantic.BaseModel):
|
||||
def total_chances(self):
|
||||
return self.col_one.total_chances() + self.col_two.total_chances() + self.col_three.total_chances()
|
||||
|
||||
def add_fatigue(self):
|
||||
first, second, third = self.get_columns(is_offense=False)
|
||||
|
||||
total_added = 0
|
||||
for x in [first, second, third]:
|
||||
resp = x.add_fatigue(6, k_only=True)
|
||||
if resp:
|
||||
total_added += resp
|
||||
break
|
||||
|
||||
if total_added == 0:
|
||||
for x in [first, second, third]:
|
||||
resp = x.add_fatigue(6, k_only=False)
|
||||
if resp:
|
||||
total_added += resp
|
||||
break
|
||||
|
||||
if total_added == 0:
|
||||
for x in [first, second, third]:
|
||||
resp = x.add_fatigue(5, k_only=True)
|
||||
if resp:
|
||||
total_added += resp
|
||||
break
|
||||
|
||||
if total_added == 0:
|
||||
for x in [first, second, third]:
|
||||
resp = x.add_fatigue(5, k_only=False)
|
||||
if resp:
|
||||
total_added += resp
|
||||
break
|
||||
|
||||
if total_added != 10:
|
||||
for x in [first, second, third]:
|
||||
resp = x.add_fatigue(10 - total_added, k_only=True)
|
||||
if resp:
|
||||
total_added += resp
|
||||
break
|
||||
|
||||
if total_added != 10:
|
||||
for x in [first, second, third]:
|
||||
resp = x.add_fatigue(10 - total_added, k_only=False)
|
||||
if resp:
|
||||
total_added += resp
|
||||
break
|
||||
|
||||
if total_added != 10:
|
||||
logging.error(f'FullCard add_fatigue - Could not add all fatigue results / total_added: {total_added}')
|
||||
|
||||
|
||||
class FullBattingCard(FullCard):
|
||||
ratings: BattingCardRatingsModel
|
||||
@ -2814,6 +2900,7 @@ def get_pitcher_card_data(player, pitching_card, ratings_vl, ratings_vr, positio
|
||||
|
||||
full_log(new_ratings, card)
|
||||
|
||||
card.add_fatigue()
|
||||
new_pitchingratings.append(new_ratings)
|
||||
|
||||
vl_output = vl.card_output()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user