From 6f0fe247014f6621479b2c881a04f5f454507a92 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 19 Nov 2025 16:30:29 -0600 Subject: [PATCH] CLAUDE: Add test game creation utilities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test_game_data.py: Static lineup data based on real SBA Game 2519 - West Virginia Black Bears vs Columbus Hydra - Complete lineup data with player info - create_test_game.py: Script to end active games and create fresh test game - Usage: uv run python scripts/create_test_game.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- backend/app/config/test_game_data.py | 100 +++++++++++++++++++ backend/scripts/create_test_game.py | 142 +++++++++++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 backend/app/config/test_game_data.py create mode 100644 backend/scripts/create_test_game.py diff --git a/backend/app/config/test_game_data.py b/backend/app/config/test_game_data.py new file mode 100644 index 0000000..5207bd2 --- /dev/null +++ b/backend/app/config/test_game_data.py @@ -0,0 +1,100 @@ +""" +Test Game Data - Static lineup data for test game creation. + +Based on SBA Game 2519 (Season 12, Week 1): +- West Virginia Black Bears (499) vs Columbus Hydra (544) +- Final Score: WV 4 - CLS 3 + +Author: Claude +Date: 2025-01-10 +""" + +# Team Information +AWAY_TEAM = { + "id": 499, + "abbrev": "WV", + "short_name": "Black Bears", + "long_name": "West Virginia Black Bears", + "manager_id": 3, + "manager_name": "Cal", +} + +HOME_TEAM = { + "id": 544, + "abbrev": "CLS", + "short_name": "Hydra", + "long_name": "Columbus Hydra", + "manager_id": 14, + "manager_name": "Mason", +} + +# Away Team Lineup - West Virginia Black Bears (Team 499) +# Pitcher: Zac Gallen +AWAY_LINEUP = [ + # Batters (batting_order 1-9) + {"player_id": 12288, "name": "Ronald Acuna Jr", "position": "RF", "batting_order": 1}, + {"player_id": 12395, "name": "Trea Turner", "position": "SS", "batting_order": 2}, + {"player_id": 11483, "name": "Alec Burleson", "position": "1B", "batting_order": 3}, + {"player_id": 11487, "name": "Alex Bregman", "position": "3B", "batting_order": 4}, + {"player_id": 12262, "name": "Ramon Urias", "position": "2B", "batting_order": 5}, + {"player_id": 12356, "name": "Steven Kwan", "position": "LF", "batting_order": 6}, + {"player_id": 12339, "name": "Shea Langeliers", "position": "C", "batting_order": 7}, + {"player_id": 11706, "name": "David Fry", "position": "DH", "batting_order": 8}, + {"player_id": 11545, "name": "Blake Perkins", "position": "CF", "batting_order": 9}, + # Starting Pitcher + {"player_id": 12479, "name": "Zac Gallen", "position": "P", "batting_order": None}, +] + +# Home Team Lineup - Columbus Hydra (Team 544) +# Pitcher: Tanner Houck +HOME_LINEUP = [ + # Batters (batting_order 1-9) + {"player_id": 12154, "name": "Michael Busch", "position": "2B", "batting_order": 1}, + {"player_id": 12455, "name": "Willy Adames", "position": "SS", "batting_order": 2}, + {"player_id": 12110, "name": "Luke Raley", "position": "LF", "batting_order": 3}, + {"player_id": 12135, "name": "Matt Chapman", "position": "3B", "batting_order": 4}, + {"player_id": 11768, "name": "Eric Haase", "position": "C", "batting_order": 5}, + {"player_id": 11523, "name": "Anthony Santander", "position": "RF", "batting_order": 6}, + {"player_id": 11611, "name": "Cal Raleigh", "position": "DH", "batting_order": 7}, + {"player_id": 12250, "name": "Pete Alonso", "position": "1B", "batting_order": 8}, + {"player_id": 11927, "name": "JJ Bleday", "position": "CF", "batting_order": 9}, + # Starting Pitcher + {"player_id": 12366, "name": "Tanner Houck", "position": "P", "batting_order": None}, +] + + +def get_test_game_config() -> dict: + """ + Get complete test game configuration. + + Returns: + Dictionary with away_team, home_team, away_lineup, home_lineup + """ + return { + "away_team": AWAY_TEAM, + "home_team": HOME_TEAM, + "away_lineup": AWAY_LINEUP, + "home_lineup": HOME_LINEUP, + "league_id": "sba", + } + + +def get_lineup_for_team(team_id: int) -> list[dict]: + """ + Get lineup for a specific team. + + Args: + team_id: Team identifier (499 or 544) + + Returns: + List of player lineup entries + + Raises: + ValueError: If team_id is not recognized + """ + if team_id == 499: + return AWAY_LINEUP + elif team_id == 544: + return HOME_LINEUP + else: + raise ValueError(f"Unknown team_id: {team_id}. Use 499 (WV) or 544 (CLS)") diff --git a/backend/scripts/create_test_game.py b/backend/scripts/create_test_game.py new file mode 100644 index 0000000..ef154fa --- /dev/null +++ b/backend/scripts/create_test_game.py @@ -0,0 +1,142 @@ +""" +Create Test Game Script + +Ends all active games and creates a new test game using real SBA lineup data. + +Usage: + uv run python scripts/create_test_game.py +""" + +import asyncio +import sys +from uuid import uuid4, UUID +from pathlib import Path + +# Add backend to path +sys.path.insert(0, str(Path(__file__).parent.parent)) + +from app.database.session import AsyncSessionLocal +from app.database.operations import DatabaseOperations +from app.models.db_models import Game +from app.config.test_game_data import get_test_game_config +from app.services.lineup_service import lineup_service +from sqlalchemy import select, update + + +async def end_all_active_games(db_ops: DatabaseOperations) -> int: + """End all active games by setting status to 'completed'.""" + async with AsyncSessionLocal() as session: + # Find all active games + result = await session.execute( + select(Game).where(Game.status == 'active') + ) + active_games = result.scalars().all() + + count = len(active_games) + + if count > 0: + # Update all to completed + await session.execute( + update(Game).where(Game.status == 'active').values(status='completed') + ) + await session.commit() + print(f"Ended {count} active game(s)") + else: + print("No active games to end") + + return count + + +async def create_test_game(db_ops: DatabaseOperations) -> UUID: + """Create a new test game with real SBA lineup data.""" + + # Get test game configuration + config = get_test_game_config() + away_team = config["away_team"] + home_team = config["home_team"] + away_lineup = config["away_lineup"] + home_lineup = config["home_lineup"] + + # Create game ID + game_id = uuid4() + + print(f"\nCreating game: {game_id}") + print(f"Away: {away_team['long_name']} ({away_team['id']})") + print(f"Home: {home_team['long_name']} ({home_team['id']})") + + # Create game in database + await db_ops.create_game( + game_id=game_id, + league_id="sba", + home_team_id=home_team["id"], + away_team_id=away_team["id"], + game_mode="friendly", + visibility="public" + ) + + # Add away team lineup (using lineup_service to fetch player data) + print(f"\nAway lineup ({away_team['abbrev']}):") + for player in away_lineup: + entry = await lineup_service.add_sba_player_to_lineup( + game_id=game_id, + team_id=away_team["id"], + player_id=player["player_id"], + position=player["position"], + batting_order=player["batting_order"], + is_starter=True + ) + order = player["batting_order"] if player["batting_order"] else "P" + print(f" {order}. {entry.player_name} ({entry.position})") + + # Add home team lineup (using lineup_service to fetch player data) + print(f"\nHome lineup ({home_team['abbrev']}):") + for player in home_lineup: + entry = await lineup_service.add_sba_player_to_lineup( + game_id=game_id, + team_id=home_team["id"], + player_id=player["player_id"], + position=player["position"], + batting_order=player["batting_order"], + is_starter=True + ) + order = player["batting_order"] if player["batting_order"] else "P" + print(f" {order}. {entry.player_name} ({entry.position})") + + # Update game status to active + async with AsyncSessionLocal() as session: + await session.execute( + update(Game).where(Game.id == game_id).values( + status="active", + current_inning=1, + current_half="top" + ) + ) + await session.commit() + + print(f"\nGame created and activated: {game_id}") + return game_id + + +async def main(): + """Main function to end active games and create a new test game.""" + print("=" * 60) + print("Test Game Creator") + print("=" * 60) + + db_ops = DatabaseOperations() + + # End all active games + await end_all_active_games(db_ops) + + # Create new test game + game_id = await create_test_game(db_ops) + + print("\n" + "=" * 60) + print(f"SUCCESS! Test game ready: {game_id}") + print("=" * 60) + + return game_id + + +if __name__ == "__main__": + game_id = asyncio.run(main())