From 48ec7375a1e36c3ba8c5602e6d6a7d097eee2d55 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 7 Jan 2026 12:01:12 -0600 Subject: [PATCH] Normalize franchise values in card generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add FRANCHISE_NORMALIZE dict and helper function - Update FRANCHISE_LIST to return city-agnostic values - Update mlbteam_and_franchise() to normalize franchise Ensures new cards use normalized franchise format for AI roster matching 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- creation_helpers.py | 113 ++++++++++++++++++++++++++++++-------------- 1 file changed, 77 insertions(+), 36 deletions(-) diff --git a/creation_helpers.py b/creation_helpers.py index 375223b..cd7ecb2 100644 --- a/creation_helpers.py +++ b/creation_helpers.py @@ -107,6 +107,47 @@ DEFAULT_RELIEVER_OPS = { 5: 0.702, # Common } +# Franchise normalization: Convert city+team names to city-agnostic team names +# This enables cross-era player matching (e.g., 'Oakland Athletics' -> 'Athletics') +FRANCHISE_NORMALIZE = { + 'Arizona Diamondbacks': 'Diamondbacks', + 'Atlanta Braves': 'Braves', + 'Baltimore Orioles': 'Orioles', + 'Boston Red Sox': 'Red Sox', + 'Chicago Cubs': 'Cubs', + 'Chicago White Sox': 'White Sox', + 'Cincinnati Reds': 'Reds', + 'Cleveland Guardians': 'Guardians', + 'Colorado Rockies': 'Rockies', + 'Detroit Tigers': 'Tigers', + 'Houston Astros': 'Astros', + 'Kansas City Royals': 'Royals', + 'Los Angeles Angels': 'Angels', + 'Los Angeles Dodgers': 'Dodgers', + 'Miami Marlins': 'Marlins', + 'Milwaukee Brewers': 'Brewers', + 'Minnesota Twins': 'Twins', + 'New York Mets': 'Mets', + 'New York Yankees': 'Yankees', + 'Oakland Athletics': 'Athletics', + 'Philadelphia Phillies': 'Phillies', + 'Pittsburgh Pirates': 'Pirates', + 'San Diego Padres': 'Padres', + 'San Francisco Giants': 'Giants', + 'Seattle Mariners': 'Mariners', + 'St Louis Cardinals': 'Cardinals', + 'St. Louis Cardinals': 'Cardinals', + 'Tampa Bay Rays': 'Rays', + 'Texas Rangers': 'Rangers', + 'Toronto Blue Jays': 'Blue Jays', + 'Washington Nationals': 'Nationals', +} + + +def normalize_franchise(franchise: str) -> str: + """Convert city+team name to team-only (e.g., 'Oakland Athletics' -> 'Athletics')""" + return FRANCHISE_NORMALIZE.get(franchise, franchise) + D20_CHANCES = { '2': { 'chances': 1, @@ -554,41 +595,41 @@ CLUB_LIST = { '4TM': 'None' } FRANCHISE_LIST = { - 'ANA': 'Los Angeles Angels', - 'ARI': 'Arizona Diamondbacks', - 'ATH': 'Oakland Athletics', - 'ATL': 'Atlanta Braves', - 'BAL': 'Baltimore Orioles', - 'BOS': 'Boston Red Sox', - 'CHC': 'Chicago Cubs', - 'CHW': 'Chicago White Sox', - 'CIN': 'Cincinnati Reds', - 'CLE': 'Cleveland Guardians', - 'COL': 'Colorado Rockies', - 'DET': 'Detroit Tigers', - 'FLA': 'Miami Marlins', - 'HOU': 'Houston Astros', - 'KCR': 'Kansas City Royals', - 'LAA': 'Los Angeles Angels', - 'LAD': 'Los Angeles Dodgers', - 'MIA': 'Miami Marlins', - 'MIL': 'Milwaukee Brewers', - 'MIN': 'Minnesota Twins', - 'MON': 'Washington Nationals', - 'NYM': 'New York Mets', - 'NYY': 'New York Yankees', - 'OAK': 'Oakland Athletics', - 'PHI': 'Philadelphia Phillies', - 'PIT': 'Pittsburgh Pirates', - 'SDP': 'San Diego Padres', - 'SEA': 'Seattle Mariners', - 'SFG': 'San Francisco Giants', - 'STL': 'St Louis Cardinals', - 'TBD': 'Tampa Bay Rays', - 'TBR': 'Tampa Bay Rays', - 'TEX': 'Texas Rangers', - 'TOR': 'Toronto Blue Jays', - 'WSN': 'Washington Nationals', + 'ANA': 'Angels', + 'ARI': 'Diamondbacks', + 'ATH': 'Athletics', + 'ATL': 'Braves', + 'BAL': 'Orioles', + 'BOS': 'Red Sox', + 'CHC': 'Cubs', + 'CHW': 'White Sox', + 'CIN': 'Reds', + 'CLE': 'Guardians', + 'COL': 'Rockies', + 'DET': 'Tigers', + 'FLA': 'Marlins', + 'HOU': 'Astros', + 'KCR': 'Royals', + 'LAA': 'Angels', + 'LAD': 'Dodgers', + 'MIA': 'Marlins', + 'MIL': 'Brewers', + 'MIN': 'Twins', + 'MON': 'Nationals', # Expos -> Nationals franchise + 'NYM': 'Mets', + 'NYY': 'Yankees', + 'OAK': 'Athletics', + 'PHI': 'Phillies', + 'PIT': 'Pirates', + 'SDP': 'Padres', + 'SEA': 'Mariners', + 'SFG': 'Giants', + 'STL': 'Cardinals', + 'TBD': 'Rays', + 'TBR': 'Rays', + 'TEX': 'Rangers', + 'TOR': 'Blue Jays', + 'WSN': 'Nationals', 'TOT': 'None', '2 Tms': 'None', '2TM': 'None', @@ -1176,7 +1217,7 @@ def mlbteam_and_franchise(mlbam_playerid): logger.debug(f'data: {data}') if data['currentTeam']['name'] in CLUB_LIST.values(): p_data['mlbclub'] = data['currentTeam']['name'] - p_data['franchise'] = data['currentTeam']['name'] + p_data['franchise'] = normalize_franchise(data['currentTeam']['name']) else: logger.error(f'Could not set team for {mlbam_playerid}; received {data["currentTeam"]["name"]}') else: