From 8e24b4e686d1cd152fd1e5fc904cc2510961a709 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 20 Mar 2026 21:32:14 -0500 Subject: [PATCH 1/3] fix: return default 8 on XBT% parse error in running() (#8) Closes #8 Co-Authored-By: Claude Sonnet 4.6 --- batters/calcs_batter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/batters/calcs_batter.py b/batters/calcs_batter.py index 0693d0f..b039041 100644 --- a/batters/calcs_batter.py +++ b/batters/calcs_batter.py @@ -573,7 +573,7 @@ def stealing_line(steal_data: dict): else: good_jump = "2-12" - return f'{"*" if sd[2] else ""}{good_jump}/- ({sd[1] if sd[1] else "-"}-{sd[0] if sd[0] else "-"})' + return f"{'*' if sd[2] else ''}{good_jump}/- ({sd[1] if sd[1] else '-'}-{sd[0] if sd[0] else '-'})" def running(extra_base_pct: str): @@ -583,7 +583,7 @@ def running(extra_base_pct: str): xb_pct = float(extra_base_pct.strip("%")) / 80 except Exception as e: logger.error(f"calcs_batter running - {e}") - xb_pct = 20 + return 8 return max(min(round(6 + (10 * xb_pct)), 17), 8) @@ -693,11 +693,11 @@ def get_batter_ratings(df_data) -> List[dict]: logger.debug( f"all on base: {vl.hbp + vl.walk + vl.total_hits()} / all chances: {vl.total_chances()}" - f'{"*******ERROR ABOVE*******" if vl.hbp + vl.walk + vl.total_hits() != vl.total_chances() else ""}' + f"{'*******ERROR ABOVE*******' if vl.hbp + vl.walk + vl.total_hits() != vl.total_chances() else ''}" ) logger.debug( f"all on base: {vr.hbp + vr.walk + vr.total_hits()} / all chances: {vr.total_chances()}" - f'{"*******ERROR ABOVE*******" if vr.hbp + vr.walk + vr.total_hits() != vr.total_chances() else ""}' + f"{'*******ERROR ABOVE*******' if vr.hbp + vr.walk + vr.total_hits() != vr.total_chances() else ''}" ) vl.calculate_strikeouts(df_data["SO_vL"], df_data["AB_vL"], df_data["H_vL"]) From b52c5418dbde29208ce8e193152ed372915e17b7 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 20 Mar 2026 23:33:06 -0500 Subject: [PATCH 2/3] fix: resolve unreachable duplicate elif 'DO*' branch in result_string() (#6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The second `elif "DO*" in data_string` was dead code — the first always matched, so `spaces -= 2` for the DO** variant was silently skipped. Fix: check "DO**" first (spaces -= 2), then "DO*" (spaces -= 1). Closes #6 Co-Authored-By: Claude Sonnet 4.6 --- creation_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/creation_helpers.py b/creation_helpers.py index f1081e0..cb626e5 100644 --- a/creation_helpers.py +++ b/creation_helpers.py @@ -618,10 +618,10 @@ def result_string(tba_data, row_num, split_min=None, split_max=None): spaces -= 3 elif "SI**" in data_string: spaces += 1 + elif "DO**" in data_string: + spaces -= 2 elif "DO*" in data_string: spaces -= 1 - elif "DO*" in data_string: - spaces -= 2 elif "so" in data_string: spaces += 3 elif "gb" in data_string: From a2e374cd4fe168b3089ecee316f22407031f6718 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sat, 21 Mar 2026 00:02:01 -0500 Subject: [PATCH 3/3] fix: correct get_of() opposite-field direction for switch hitters Switch hitters batting vs LHP hit right-handed (pull=lf, oppo=rf). Switch hitters batting vs RHP hit left-handed (pull=rf, oppo=lf). Copy-paste error had both pull_side branches returning the same value. Closes #5 Co-Authored-By: Claude Sonnet 4.6 --- creation_helpers.py | 48 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/creation_helpers.py b/creation_helpers.py index f1081e0..53d0535 100644 --- a/creation_helpers.py +++ b/creation_helpers.py @@ -595,21 +595,21 @@ def legal_splits(tot_chances): def result_string(tba_data, row_num, split_min=None, split_max=None): - bold1 = f'{"" if tba_data["bold"] else ""}' - bold2 = f'{"" if tba_data["bold"] else ""}' - row_string = f'{" " if int(row_num) < 10 else ""}{row_num}' + bold1 = f"{'' if tba_data['bold'] else ''}" + bold2 = f"{'' if tba_data['bold'] else ''}" + row_string = f"{' ' if int(row_num) < 10 else ''}{row_num}" if TESTING: print( - f'adding {tba_data["string"]} to row {row_num} / ' + f"adding {tba_data['string']} to row {row_num} / " f"split_min: {split_min} / split_max: {split_max}" ) # No splits; standard result if not split_min: - return f'{bold1}{row_string}-{tba_data["string"]}{bold2}' + return f"{bold1}{row_string}-{tba_data['string']}{bold2}" # With splits - split_nums = f'{split_min if split_min != 20 else ""}{"-" if split_min != 20 else ""}{split_max}' + split_nums = f"{split_min if split_min != 20 else ''}{'-' if split_min != 20 else ''}{split_max}" data_string = ( tba_data["sm-string"] if "sm-string" in tba_data.keys() else tba_data["string"] ) @@ -638,41 +638,39 @@ def result_string(tba_data, row_num, split_min=None, split_max=None): row_output = " " if TESTING: print(f"row_output: {row_output}") - return f'{bold1}{row_output}{data_string}{" " * spaces}{split_nums}{bold2}' + return f"{bold1}{row_output}{data_string}{' ' * spaces}{split_nums}{bold2}" def result_data( tba_data, row_num, tba_data_bottom=None, top_split_max=None, fatigue=False ): ret_data = {} - top_bold1 = f'{"" if tba_data["bold"] else ""}' - top_bold2 = f'{"" if tba_data["bold"] else ""}' + top_bold1 = f"{'' if tba_data['bold'] else ''}" + top_bold2 = f"{'' if tba_data['bold'] else ''}" bot_bold1 = None bot_bold2 = None if tba_data_bottom: - bot_bold1 = f'{"" if tba_data_bottom["bold"] else ""}' - bot_bold2 = f'{"" if tba_data_bottom["bold"] else ""}' + bot_bold1 = f"{'' if tba_data_bottom['bold'] else ''}" + bot_bold2 = f"{'' if tba_data_bottom['bold'] else ''}" if tba_data_bottom is None: ret_data["2d6"] = f"{top_bold1}{int(row_num)}-{top_bold2}" ret_data["splits"] = f"{top_bold1}‎{top_bold2}" ret_data["result"] = ( - f"{top_bold1}" - f'{tba_data["string"]}{" •" if fatigue else ""}' - f"{top_bold2}" + f"{top_bold1}{tba_data['string']}{' •' if fatigue else ''}{top_bold2}" ) else: ret_data["2d6"] = f"{top_bold1}{int(row_num)}-{top_bold2}\n" ret_data["splits"] = ( - f'{top_bold1}1{"-" if top_split_max != 1 else ""}' - f'{top_split_max if top_split_max != 1 else ""}{top_bold2}\n' - f'{bot_bold1}{top_split_max+1}{"-20" if top_split_max != 19 else ""}{bot_bold2}' + f"{top_bold1}1{'-' if top_split_max != 1 else ''}" + f"{top_split_max if top_split_max != 1 else ''}{top_bold2}\n" + f"{bot_bold1}{top_split_max + 1}{'-20' if top_split_max != 19 else ''}{bot_bold2}" ) ret_data["result"] = ( - f'{top_bold1}{tba_data["sm-string"] if "sm-string" in tba_data.keys() else tba_data["string"]}' + f"{top_bold1}{tba_data['sm-string'] if 'sm-string' in tba_data.keys() else tba_data['string']}" f"{top_bold2}\n" f"{bot_bold1}" - f'{tba_data_bottom["sm-string"] if "sm-string" in tba_data_bottom.keys() else tba_data_bottom["string"]}' + f"{tba_data_bottom['sm-string'] if 'sm-string' in tba_data_bottom.keys() else tba_data_bottom['string']}" f"{bot_bold2}" ) @@ -688,9 +686,9 @@ def get_of(batter_hand, pitcher_hand, pull_side=True): if batter_hand == "S": if pitcher_hand == "L": - return "rf" if pull_side else "rf" + return "lf" if pull_side else "rf" else: - return "lf" if pull_side else "lf" + return "rf" if pull_side else "lf" def get_col(col_num): @@ -729,7 +727,7 @@ def get_position_string(all_pos: list, inc_p: bool): for x in all_pos: if x.position == "OF": - of_arm = f'{"+" if "-" not in x.arm else ""}{x.arm}' + of_arm = f"{'+' if '-' not in x.arm else ''}{x.arm}" of_error = x.error of_innings = x.innings elif x.position == "CF": @@ -744,7 +742,7 @@ def get_position_string(all_pos: list, inc_p: bool): elif x.position == "C": all_def.append( ( - f'c-{x.range}({"+" if int(x.arm) >= 0 else ""}{x.arm}) e{x.error} T-{x.overthrow}(pb-{x.pb})', + f"c-{x.range}({'+' if int(x.arm) >= 0 else ''}{x.arm}) e{x.error} T-{x.overthrow}(pb-{x.pb})", x.innings, ) ) @@ -1079,7 +1077,7 @@ def mlbteam_and_franchise(mlbam_playerid): p_data["franchise"] = normalize_franchise(data["currentTeam"]["name"]) else: logger.error( - f'Could not set team for {mlbam_playerid}; received {data["currentTeam"]["name"]}' + f"Could not set team for {mlbam_playerid}; received {data['currentTeam']['name']}" ) else: logger.error( @@ -1222,5 +1220,5 @@ def get_hand(df_data): else: return "R" except Exception: - logger.error(f'Error in get_hand for {df_data["Name"]}') + logger.error(f"Error in get_hand for {df_data['Name']}") return "R"