strat-gameplay-webapp/backend/app/config/league_configs.py
Cal Corum a4b99ee53e CLAUDE: Replace black and flake8 with ruff for formatting and linting
Migrated to ruff for faster, modern code formatting and linting:

Configuration changes:
- pyproject.toml: Added ruff 0.8.6, removed black/flake8
- Configured ruff with black-compatible formatting (88 chars)
- Enabled comprehensive linting rules (pycodestyle, pyflakes, isort,
  pyupgrade, bugbear, comprehensions, simplify, return)
- Updated CLAUDE.md: Changed code quality commands to use ruff

Code improvements (490 auto-fixes):
- Modernized type hints: List[T] → list[T], Dict[K,V] → dict[K,V],
  Optional[T] → T | None
- Sorted all imports (isort integration)
- Removed unused imports
- Fixed whitespace issues
- Reformatted 38 files for consistency

Bug fixes:
- app/core/play_resolver.py: Fixed type hint bug (any → Any)
- tests/unit/core/test_runner_advancement.py: Removed obsolete random mock

Testing:
- All 739 unit tests passing (100%)
- No regressions introduced

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 15:33:21 -06:00

180 lines
5.0 KiB
Python

"""
League-specific configuration implementations.
Provides concrete configs for SBA and PD leagues with their unique rules,
API endpoints, and feature flags.
Author: Claude
Date: 2025-10-28
"""
import logging
from collections.abc import Callable
from app.config.base_config import BaseGameConfig
from app.config.common_x_check_tables import (
CATCHER_DEFENSE_TABLE,
INFIELD_DEFENSE_TABLE,
OUTFIELD_DEFENSE_TABLE,
get_error_chart_for_position,
get_fielders_holding_runners,
)
logger = logging.getLogger(f"{__name__}.LeagueConfigs")
class SbaConfig(BaseGameConfig):
"""
SBA League configuration.
Features:
- Manual result selection after dice roll
- Simple player data model
- Standard baseball rules
"""
league_id: str = "sba"
# SBA-specific features
player_selection_mode: str = "manual" # Players manually select from chart
# X-Check defense tables (shared common tables)
x_check_defense_tables: dict[str, list[list[str]]] = {
"infield": INFIELD_DEFENSE_TABLE,
"outfield": OUTFIELD_DEFENSE_TABLE,
"catcher": CATCHER_DEFENSE_TABLE,
}
# X-Check error chart lookup function
x_check_error_charts: Callable[[str], dict[int, dict[str, list[int]]]] = (
get_error_chart_for_position
)
# Holding runners function
x_check_holding_runners: Callable[[list[int], str], list[str]] = (
get_fielders_holding_runners
)
def get_result_chart_name(self) -> str:
"""Use SBA standard result chart."""
return "sba_standard_v1"
def supports_manual_result_selection(self) -> bool:
"""SBA players manually pick results from chart."""
return True
def supports_auto_mode(self) -> bool:
"""SBA does not support auto mode - cards are not digitized."""
return False
def supports_position_ratings(self) -> bool:
"""
Check if this league supports position ratings for X-Check resolution.
Returns:
False for SBA (uses manual entry only)
Phase 3E-Main: SBA players manually enter defensive ratings
"""
return False
def get_api_base_url(self) -> str:
"""SBA API base URL."""
return "https://api.sba.manticorum.com"
class PdConfig(BaseGameConfig):
"""
Paper Dynasty League configuration.
Features:
- Flexible result selection (manual or auto via scouting)
- Complex scouting data model
- Cardset validation
- Advanced analytics
"""
league_id: str = "pd"
# PD-specific features
player_selection_mode: str = "flexible" # Manual or auto via scouting model
use_scouting_model: bool = True # Use detailed ratings for auto-resolution
cardset_validation: bool = True # Validate cards against approved cardsets
# Advanced features
detailed_analytics: bool = True # Track advanced stats (WPA, RE24, etc.)
wpa_calculation: bool = True # Calculate win probability added
# X-Check defense tables (shared common tables)
x_check_defense_tables: dict[str, list[list[str]]] = {
"infield": INFIELD_DEFENSE_TABLE,
"outfield": OUTFIELD_DEFENSE_TABLE,
"catcher": CATCHER_DEFENSE_TABLE,
}
# X-Check error chart lookup function
x_check_error_charts: Callable[[str], dict[int, dict[str, list[int]]]] = (
get_error_chart_for_position
)
# Holding runners function
x_check_holding_runners: Callable[[list[int], str], list[str]] = (
get_fielders_holding_runners
)
def get_result_chart_name(self) -> str:
"""Use PD standard result chart."""
return "pd_standard_v1"
def supports_manual_result_selection(self) -> bool:
"""PD supports manual selection (though auto is also available)."""
return True
def supports_auto_mode(self) -> bool:
"""PD supports auto mode via digitized scouting data."""
return True
def supports_position_ratings(self) -> bool:
"""
Check if this league supports position ratings for X-Check resolution.
Returns:
True for PD (has position ratings API)
Phase 3E-Main: PD fetches ratings from API with Redis caching
"""
return True
def get_api_base_url(self) -> str:
"""PD API base URL."""
return "https://pd.manticorum.com/api/"
# ==================== Config Registry ====================
LEAGUE_CONFIGS: dict[str, BaseGameConfig] = {"sba": SbaConfig(), "pd": PdConfig()}
def get_league_config(league_id: str) -> BaseGameConfig:
"""
Get configuration for specified league.
Args:
league_id: League identifier ('sba' or 'pd')
Returns:
League-specific config instance
Raises:
ValueError: If league_id is not recognized
"""
config = LEAGUE_CONFIGS.get(league_id)
if not config:
logger.error(f"Unknown league ID: {league_id}")
raise ValueError(
f"Unknown league: {league_id}. Valid leagues: {list(LEAGUE_CONFIGS.keys())}"
)
logger.debug(f"Retrieved config for league: {league_id}")
return config