Normalize franchise values in card generation
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
78eb8862e1
commit
48ec7375a1
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user