Paper Dynasty Card Creation - Baseball card generation system
Go to file
Cal Corum db2d81a6d1 CLAUDE: Add default OPS constants and type hints to improve code clarity
This commit adds default OPS value constants and type hints to key functions,
improving code documentation and IDE support.

## Changes Made

1. **Add default OPS constants** (creation_helpers.py)
   - DEFAULT_BATTER_OPS: Default OPS by rarity (1-5)
   - DEFAULT_STARTER_OPS: Default OPS-against for starters (99, 1-5)
   - DEFAULT_RELIEVER_OPS: Default OPS-against for relievers (99, 1-5)
   - Comprehensive comments explaining usage
   - Single source of truth for fallback values

2. **Update batters/creation.py**
   - Import DEFAULT_BATTER_OPS
   - Replace 6 hardcoded if-checks with clean loop over constants
   - Add type hints to post_player_updates function
   - Import Dict from typing

3. **Update pitchers/creation.py**
   - Import DEFAULT_STARTER_OPS and DEFAULT_RELIEVER_OPS
   - Replace 12 hardcoded if-checks with clean loops over constants
   - Add type hints to post_player_updates function
   - Import Dict from typing

4. **Add typing import** (creation_helpers.py)
   - Import Dict, List, Tuple, Optional for type hints
   - Enables type hints throughout helper functions

## Impact

### Before
```python
# Scattered hardcoded values (batters)
if 1 not in average_ops:
    average_ops[1] = 1.066
if 2 not in average_ops:
    average_ops[2] = 0.938
# ... 4 more if-checks

# Scattered hardcoded values (pitchers)
if 99 not in sp_average_ops:
    sp_average_ops[99] = 0.388
# ... 5 more if-checks for starters
# ... 6 more if-checks for relievers
```

### After
```python
# Clean, data-driven approach (batters)
for rarity, default_ops in DEFAULT_BATTER_OPS.items():
    if rarity not in average_ops:
        average_ops[rarity] = default_ops

# Clean, data-driven approach (pitchers)
for rarity, default_ops in DEFAULT_STARTER_OPS.items():
    if rarity not in sp_average_ops:
        sp_average_ops[rarity] = default_ops

for rarity, default_ops in DEFAULT_RELIEVER_OPS.items():
    if rarity not in rp_average_ops:
        rp_average_ops[rarity] = default_ops
```

### Benefits
 Eliminates 18 if-checks across batters and pitchers
 Single source of truth for default OPS values
 Easy to modify values (change constant, not scattered code)
 Self-documenting with clear constant names and comments
 Type hints improve IDE support and catch errors early
 Function signatures now document expected types
 Consistent with other recent refactorings

## Test Results
 42/42 tests pass
 All existing functionality preserved
 100% backward compatible

## Files Modified
- creation_helpers.py: +35 lines (3 constants + typing import)
- batters/creation.py: -4 lines net (cleaner code + type hints)
- pitchers/creation.py: -8 lines net (cleaner code + type hints)

**Net change:** More constants, less scattered magic numbers, better types.

Part of ongoing refactoring to reduce code fragility.
2025-10-31 23:28:49 -05:00
.claude/plans Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
batters CLAUDE: Add default OPS constants and type hints to improve code clarity 2025-10-31 23:28:49 -05:00
card-output August '23 PotM Cards 2023-09-07 13:14:15 -05:00
data-input Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
defenders Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
html work fielding and batting functional 2023-09-24 18:58:44 -05:00
logs Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
pitchers CLAUDE: Add default OPS constants and type hints to improve code clarity 2025-10-31 23:28:49 -05:00
scouting Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
scripts Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
tests CLAUDE: Extract rarity cost adjustment logic into data-driven function 2025-10-31 22:49:35 -05:00
.gitignore Batter stat generation complete 2024-10-19 01:05:23 -05:00
automated_data_fetcher.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
batter-deltas.csv Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
batting_stats.csv Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
check_cards.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
CLAUDE.md Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
creation_helpers.py CLAUDE: Add default OPS constants and type hints to improve code clarity 2025-10-31 23:28:49 -05:00
db_calls_card_creation.py Consolidated db preparation 2023-09-07 13:14:32 -05:00
db_calls.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
exceptions.py Migrate to rotating file logger 2024-11-10 14:42:12 -06:00
live_series_update.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
new-batters.csv Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
new-pitchers.csv Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
pitcher-deltas.csv Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
pitching_stats.csv Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
pkmn.json 1996 Data 2024-12-23 09:57:51 -06:00
post_raw_player_csv.py 1996 Data 2024-12-23 09:57:51 -06:00
PROMO_CARD_FIX.md CLAUDE: Refactor to reduce code fragility - extract business logic and add constants 2025-10-31 22:03:22 -05:00
pull_pitching_stats.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
pybaseball_doodling.py Batter stat generation complete 2024-10-19 01:05:23 -05:00
pytest.ini Moving older scripts into holding cell 2024-10-17 09:28:02 -05:00
README.txt Migrate db calls to aiohttp 2023-11-19 12:27:40 -06:00
REFACTORING_SUMMARY.md CLAUDE: Refactor to reduce code fragility - extract business logic and add constants 2025-10-31 22:03:22 -05:00
refresh_cards.py Refactor refresh_cards 2025-02-09 01:17:58 -06:00
requirements.txt Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
retrosheet_data.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
retrosheet.db Add retrosheet db 2024-10-17 09:28:59 -05:00
scouting_batters.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
scouting_pitchers.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00
test_data_fetcher_demo.py Claude introduction & Live Series Update 2025-07-22 09:24:34 -05:00











#######
CARD CREATION PROCESS
#######

1) Download stats
    FanGraphs / https://www.fangraphs.com/leaders/splits-leaderboards
    - Batting
        - vL Standard / vlhp-basic.csv
        - vL Batted Balls / vlhp-rate.csv
        - vR Standard / vrhp-basic.csv
        - vR Batted Balls / vrhp-rate.csv
    - Pitching
        - vL Standard / vlhh-basic.csv
        - vL Batted Balls / vlhh-rate.csv
        - vR Standard / vrhh-basic.csv
        - vR Batted Balls / vrhh-rate.csv
    Baseball Reference
    - running.csv
        - https://www.baseball-reference.com/leagues/majors/2023-baserunning-batting.shtml
        - Remove header lines
    - pitching.csv
        - https://www.baseball-reference.com/leagues/majors/2023-standard-pitching.shtml
2) Run Card Updates (Python Configuration)
3) Check Card Validity (Python Configuration)



























#######
OLD DATA REQUIREMENTS
#######

- Add any new players to players.csv for import
- Create directory in /data-input in format `XXXX Season Cardset`
- Upload the following csv files:
    - baserunning-data.csv
        - https://www.baseball-reference.com/leagues/majors/2023-baserunning-batting.shtml
        - Remove header lines
    - batter-stats.csv
        - https://www.fangraphs.com/leaders/splits-leaderboards
        - Remove header lines
        - 20 PA vL / 40 PA vR for Live || 50 PA vL / 75 PA vR for legacy seasons
    - defense-X.csv (each position)
        - https://www.baseball-reference.com/leagues/majors/2023-specialpos_p-fielding.shtml
        - replace the `p` in `p-fielding` with 1b/2b/lf
        - Column Changes (pre-2013)
            - Catchers: add column between Rgood and RsbC
            - 1b/2b/3b/ss: add 3 columns between Rgood and Rbnt
    - defense-of.csv (don't forget combined OF)
        - https://www.baseball-reference.com/leagues/majors/2023-specialpos_of-fielding.shtml
        - replace the `p` in `p-fielding` with of
    - pitcher-data.csv
        - https://www.baseball-reference.com/leagues/majors/2023-standard-pitching.shtml
    - pitcher-stats.csv
        - https://www.fangraphs.com/leaders/splits-leaderboards
        - Remove header lines
        - 20 TBF vL / 40 TBF vR for Live || 50 TBF vL / 75 TBF vR for legacy seasons

#######
OLD CARD CREATION PROCESS
#######

1) Import new players for sba_id with `1. Import Players`
2) Confirm cardset exists; if not, create now
3) Create cards with `3. Card Creation`
4) Generate csv output with `4. Card Output`
5) Upload output files into Sheets for Component Studio import
6) Upload ratings output files into Sheets for PD Ratings Guide
7) Import cards into Component Studio
8) Export -> Download All from Component Studio
9) Rename image files to <first>.<last>.png