Fix loop on batter cards

This commit is contained in:
Cal Corum 2023-10-22 13:53:27 -05:00
parent 714345c589
commit 22bbb3e3bb

View File

@ -1434,8 +1434,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.bp_homerun += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.hbp
while res_chances > 0:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
r_val = assign_bchances(card, PlayResult(full_name='HBP', short_name='HBP'), ch)
logging.info(f'Returned batting chances: {r_val[0]} / {r_val[1]}\n')
@ -1443,10 +1447,14 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
res_chances -= r_val[0]
new_ratings.hbp += r_val[0]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.homerun
while res_chances > 0:
if res_chances < 1:
if res_chances < 1 or retries > 0:
if data.double_pull > 0:
data.double_pull += res_chances
elif data.double_two > 0:
@ -1504,10 +1512,14 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.triple -= r_val[1]
new_ratings.triple += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.triple
while res_chances > 0:
if res_chances < 1:
if res_chances < 1 or retries > 0:
if data.double_pull > 0:
data.double_pull += res_chances
elif data.double_two > 0:
@ -1561,10 +1573,14 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.double_two -= r_val[1]
new_ratings.double_two += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.double_three
while res_chances > 0:
if res_chances < 1:
if res_chances < 1 or retries > 0:
if data.double_pull > 0:
data.double_pull += res_chances
elif data.double_two > 0:
@ -1613,10 +1629,14 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.double_two -= r_val[1]
new_ratings.double_two += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.double_pull
while res_chances > 0:
if res_chances < 1:
if res_chances < 1 or retries > 0:
if data.double_two > 0:
data.double_two += res_chances
elif data.single_two > 0:
@ -1661,10 +1681,14 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.double_two -= r_val[1]
new_ratings.double_two += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.double_two
while res_chances > 0:
if res_chances < 1:
if res_chances < 1 or retries > 0:
if data.single_two > 0:
data.single_two += res_chances
elif data.single_center > 0:
@ -1703,10 +1727,14 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.single_two -= r_val[1]
new_ratings.single_two += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.single_two
while res_chances > 0:
if res_chances < 1:
if res_chances < 1 or retries > 0:
if data.single_center > 0:
data.single_center += res_chances
elif data.single_one > 0:
@ -1746,10 +1774,14 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.lineout -= r_val[1]
new_ratings.lineout += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.single_center
while res_chances > 0:
if res_chances < 1:
if res_chances < 1 or retries > 0:
if data.single_one > 0:
data.single_one += res_chances
elif data.walk > 0:
@ -1789,10 +1821,14 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.lineout -= r_val[1]
new_ratings.lineout += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.single_one
while res_chances > 0:
if res_chances < 1:
if res_chances < 1 or retries > 0:
if data.walk > 0:
data.walk += res_chances
break
@ -1828,9 +1864,16 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.lineout -= r_val[1]
new_ratings.lineout += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.walk
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
if data.strikeout > max(1 - ch, 0):
secondary = PlayResult(full_name=f'strikeout', short_name=f'so')
@ -1846,9 +1889,16 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
data.strikeout -= r_val[1]
new_ratings.strikeout += r_val[1]
if r_val[0] == 0:
retries += 1
full_log(new_ratings, card)
retries = 0
res_chances = data.bp_single
while res_chances > 0:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
r_val = assign_bchances(card, PLAY_RESULTS['bp-si'], ch)
logging.info(f'Returned batting chances: {r_val[0]} / {r_val[1]}\n')
@ -1856,6 +1906,9 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
res_chances -= r_val[0]
new_ratings.bp_single += r_val[0]
if r_val[0] == 0:
retries += 1
# Special lomax result
full_log(new_ratings, card)
r_val = assign_bchances(
@ -1866,8 +1919,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.lineout += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.popout
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
this_if = '2b' if pref_mif == 'ss' else 'ss'
r_val = assign_bchances(
@ -1885,8 +1942,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.popout += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.flyout_a
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
r_val = assign_bchances(
card, PlayResult(full_name=f'fly (cf) A', short_name=f'fly (cf) A'), Decimal(math.floor(ch)))
@ -1900,8 +1961,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.flyout_a += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.flyout_lf_b
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
r_val = assign_bchances(
card, PlayResult(full_name=f'fly (lf) B', short_name=f'fly (lf) B'), Decimal(math.floor(ch)))
@ -1915,8 +1980,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.flyout_lf_b += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.flyout_rf_b
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
r_val = assign_bchances(
card, PlayResult(full_name=f'fly (rf) B', short_name=f'fly (rf) B'), Decimal(math.floor(ch)))
@ -1942,8 +2011,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
return '3b' if pref_mif == 'ss' else 'p'
full_log(new_ratings, card)
retries = 0
res_chances = data.groundout_a
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
count_gb += 1
this_if = get_gb_if()
ch = get_chances(res_chances)
@ -1960,8 +2033,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.groundout_a += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.groundout_b
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
count_gb += 1
this_if = get_gb_if()
ch = get_chances(res_chances)
@ -1978,8 +2055,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.groundout_b += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.groundout_c
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
count_gb += 1
this_if = get_gb_if()
ch = get_chances(res_chances)
@ -1996,8 +2077,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.groundout_c += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.lineout
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
this_if = '3b' if pref_mif == 'ss' else '1b'
r_val = assign_bchances(
@ -2014,8 +2099,12 @@ def get_batter_card_data(player, batting_card, ratings_vl, ratings_vr, positions
new_ratings.lineout += r_val[0]
full_log(new_ratings, card)
retries = 0
res_chances = data.strikeout
while res_chances >= 1:
if res_chances < 1 or retries > 0:
break
ch = get_chances(res_chances)
r_val = assign_bchances(
card, PlayResult(full_name=f'strikeout', short_name=f'strikeout'), Decimal(math.floor(ch)))