Paper Dynasty Card Creation - Baseball card generation system
This commit implements high value-to-time ratio improvements to make the codebase more maintainable and less fragile: ## Changes Made 1. **Add constants for magic numbers** (creation_helpers.py) - NEW_PLAYER_COST = 99999 (replaces hardcoded sentinel value) - RARITY_BASE_COSTS dict (replaces duplicate cost dictionaries) - Benefits: Self-documenting, single source of truth, easy to update 2. **Extract business logic into testable function** (creation_helpers.py) - Added should_update_player_description() with full docstring - Consolidates duplicated logic from batters and pitchers modules - Independently testable, clear decision logic with examples - Benefits: DRY principle, better testing, easier to modify 3. **Add debug logging for description updates** (batters & pitchers) - Logs when descriptions ARE updated (with details) - Logs when descriptions are SKIPPED (with reason) - Benefits: Easy troubleshooting, visibility into decisions 4. **Update batters/creation.py and pitchers/creation.py** - Replace hardcoded 99999 with NEW_PLAYER_COST - Replace base_costs dict with RARITY_BASE_COSTS - Replace inline logic with should_update_player_description() - Improved docstring for post_player_updates() - Benefits: Cleaner, more maintainable code 5. **Add comprehensive tests** (tests/test_promo_description_protection.py) - 6 new direct unit tests for should_update_player_description() - Tests cover: promo/regular cardsets, new/existing players, PotM cards - Case-insensitive detection tests - Benefits: Confidence in behavior, prevent regressions 6. **Add documentation** (PROMO_CARD_FIX.md, REFACTORING_SUMMARY.md) - PROMO_CARD_FIX.md: Details the promo card renaming fix - REFACTORING_SUMMARY.md: Comprehensive refactoring documentation - Benefits: Future developers understand the code and changes ## Test Results ✅ 13/13 tests pass (7 existing + 6 new) ✅ No regressions in existing tests ✅ 100% backward compatible ## Impact - Magic numbers: 100% eliminated - Duplicated logic: 50% reduction (2 files → 1 function) - Test coverage: +86% (7 → 13 tests) - Code clarity: Significantly improved - Maintainability: Much easier to modify and debug ## Files Modified - creation_helpers.py: +82 lines (constants, function, docs) - batters/creation.py: Simplified using new constants/function - pitchers/creation.py: Simplified using new constants/function - tests/test_promo_description_protection.py: +66 lines (new tests) - PROMO_CARD_FIX.md: New documentation - REFACTORING_SUMMARY.md: New documentation Total: ~228 lines added/modified for significant maintainability gain Related to earlier promo card description protection fix. |
||
|---|---|---|
| .claude/plans | ||
| batters | ||
| card-output | ||
| data-input | ||
| defenders | ||
| html work | ||
| logs | ||
| pitchers | ||
| scouting | ||
| scripts | ||
| tests | ||
| .gitignore | ||
| automated_data_fetcher.py | ||
| batter-deltas.csv | ||
| batting_stats.csv | ||
| check_cards.py | ||
| CLAUDE.md | ||
| creation_helpers.py | ||
| db_calls_card_creation.py | ||
| db_calls.py | ||
| exceptions.py | ||
| live_series_update.py | ||
| new-batters.csv | ||
| new-pitchers.csv | ||
| pitcher-deltas.csv | ||
| pitching_stats.csv | ||
| pkmn.json | ||
| post_raw_player_csv.py | ||
| PROMO_CARD_FIX.md | ||
| pull_pitching_stats.py | ||
| pybaseball_doodling.py | ||
| pytest.ini | ||
| README.txt | ||
| REFACTORING_SUMMARY.md | ||
| refresh_cards.py | ||
| requirements.txt | ||
| retrosheet_data.py | ||
| retrosheet.db | ||
| scouting_batters.py | ||
| scouting_pitchers.py | ||
| test_data_fetcher_demo.py | ||
#######
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