424b7da78d
Merge branch 'main' into ai/paper-dynasty-card-creation#21
2026-03-23 13:24:40 +00:00
Cal Corum
5b8d027d46
fix: remove test_positions_df non-test that always passes ( #16 )
...
Closes #16
Deleted test_positions_df which called an async function synchronously
(returning a coroutine, not a DataFrame) and asserted True == True.
Zero coverage. Also removed the now-unused pd_positions_df import.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 02:02:10 -05:00
Cal Corum
ee4dae0985
fix: add @pytest.mark.asyncio to async test methods ( #21 )
...
Closes #21
All 14 async test methods in tests/test_automated_data_fetcher.py were
missing @pytest.mark.asyncio. Without it, pytest collects them and
silently passes without executing the coroutine body, providing no
coverage.
Added explicit @pytest.mark.asyncio to each async def test_* method.
This makes the async intent unambiguous and is robust against any
future asyncio_mode configuration changes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 14:33:52 -05:00
Cal Corum
0a17745389
Run black and ruff across entire codebase
...
Standardize formatting with black and apply ruff auto-fixes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 14:24:33 -05:00
Cal Corum
2bf3a6cee7
Fix SLG formula drift in extracted rating models
...
The extracted batting and pitching models used malformed SLG equations that double-counted and omitted outcomes, skewing slash lines. Align formulas with canonical weighting and add regression tests to prevent recurrence.
Co-Authored-By: Claude GPT-5.3-Codex <noreply@anthropic.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-26 07:47:15 -06:00
Cal Corum
39c652e55c
Extract BattingCardRatingsModel and PitchingCardRatingsModel into models.py files
...
Move each ratings model class (and, for batters, the helper functions it
depends on) into a dedicated models.py so that calcs_*.py can import from
card_builder.py at module level without circular imports.
- batters/models.py: BattingCardRatingsModel + bp_singles, wh_singles,
one_singles, bp_homeruns, triples, two_doubles, hit_by_pitch, strikeouts,
flyout_a, flyout_bq, flyout_b, groundball_a, groundball_c
- pitchers/models.py: PitchingCardRatingsModel (no helper deps needed)
- batters/calcs_batter.py: imports model + build_batter_full_cards at top
- pitchers/calcs_pitcher.py: imports model + build_pitcher_full_cards at top
- batters/card_builder.py: imports from batters.models
- pitchers/card_builder.py: imports from pitchers.models
- tests/test_batter_calcs.py: import bp_singles, wh_singles from batters.models
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-25 16:42:51 -06:00
Cal Corum
cb471d8057
CLAUDE: Extract rarity cost adjustment logic into data-driven function
...
This commit eliminates 150+ lines of duplicated, error-prone nested if/elif
logic by extracting rarity cost calculations into a lookup table and function.
## Changes Made
1. **Add RARITY_COST_ADJUSTMENTS lookup table** (creation_helpers.py)
- Maps (old_rarity, new_rarity) → (cost_adjustment, minimum_cost)
- Covers all 30 possible rarity transitions
- Self-documenting with comments for each rarity tier
- Single source of truth for all cost adjustments
2. **Add calculate_rarity_cost_adjustment() function** (creation_helpers.py)
- Takes old_rarity, new_rarity, old_cost
- Returns new cost with adjustments and minimums applied
- Includes comprehensive docstring with examples
- Handles edge cases (same rarity, undefined transitions)
- Logs warnings for undefined transitions
3. **Update batters/creation.py**
- Import calculate_rarity_cost_adjustment
- Replace 75-line nested if/elif block with 7-line function call
- Identical behavior, much cleaner code
4. **Update pitchers/creation.py**
- Import calculate_rarity_cost_adjustment
- Replace 75-line nested if/elif block with 7-line function call
- Eliminates duplication between batters and pitchers
5. **Add comprehensive tests** (tests/test_rarity_cost_adjustments.py)
- 22 tests covering all scenarios
- Tests individual transitions (Diamond→Gold, Common→Bronze, etc.)
- Tests all upward and downward transitions
- Tests minimum cost enforcement
- Tests edge cases (zero cost, very high cost, negative cost)
- Tests symmetry (up then down returns close to original)
## Impact
### Lines Eliminated
- **Batters:** 75 lines → 7 lines (89% reduction)
- **Pitchers:** 75 lines → 7 lines (89% reduction)
- **Total:** 150 lines of nested logic eliminated
### Benefits
✅ Eliminates 150+ lines of duplicated code
✅ Data-driven approach makes adjustments clear and modifiable
✅ Single source of truth prevents inconsistencies
✅ Independently testable business logic
✅ 22 comprehensive tests ensure correctness
✅ Easy to add new rarity tiers or modify costs
✅ Reduced risk of typos in magic numbers
## Test Results
✅ 22/22 new tests pass
✅ All existing tests still pass
✅ 100% backward compatible - identical behavior
## Files Modified
- creation_helpers.py: +104 lines (table + function + docs)
- batters/creation.py: -68 lines (replaced nested logic)
- pitchers/creation.py: -68 lines (replaced nested logic)
- tests/test_rarity_cost_adjustments.py: +174 lines (new tests)
**Net change:** 150+ lines of complex logic replaced with simple,
tested, data-driven approach.
Part of ongoing refactoring to reduce code fragility.
2025-10-31 22:49:35 -05:00
Cal Corum
bd1cc7e90b
CLAUDE: Refactor to reduce code fragility - extract business logic and add constants
...
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.
2025-10-31 22:03:22 -05:00
Cal Corum
c89e1eb507
Claude introduction & Live Series Update
2025-07-22 09:24:34 -05:00
Cal Corum
d69d7e6103
Added exceptions.py, added date_math, error checks for promos
2024-11-02 19:00:39 -05:00
Cal Corum
cdb5820dbc
Pitchers are complete
2024-11-01 08:50:29 -05:00
Cal Corum
b3102201c8
Added Devil Rays to club and franchise lists
...
Fixed bphr fraction bug
Removed player post limit
2024-10-25 12:24:08 -05:00
Cal Corum
0de2239100
Updated mround to return float
...
Counting stats nearly complete for batters
2024-10-18 12:12:40 -05:00
Cal Corum
639e032586
Moving older scripts into holding cell
2024-10-17 09:28:02 -05:00