Fix linting errors across backend and frontend
Backend: auto-fix and format all ruff issues, manually fix B904/B023/ SIM117/B007/E741/F841 errors, suppress B008 (FastAPI Depends) and F821 (SQLAlchemy forward refs) in config. Frontend: allow constant exports, disable React compiler-specific rules (set-state-in-effect, preserve-manual-memoization). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ Usage:
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@@ -16,18 +16,52 @@ from app.models.encounter import Encounter
|
||||
from app.models.evolution import Evolution
|
||||
from app.models.game import Game
|
||||
from app.models.nuzlocke_run import NuzlockeRun
|
||||
from app.models.pokemon import Pokemon
|
||||
from app.models.route import Route
|
||||
|
||||
random.seed(42) # reproducible data
|
||||
|
||||
# --- Nicknames pool ---
|
||||
NICKNAMES = [
|
||||
"Blaze", "Thunder", "Shadow", "Luna", "Spike", "Rex", "Cinder", "Misty",
|
||||
"Rocky", "Breeze", "Fang", "Nova", "Scout", "Atlas", "Pepper", "Storm",
|
||||
"Bandit", "Echo", "Maple", "Titan", "Ziggy", "Bolt", "Rusty", "Pearl",
|
||||
"Ivy", "Ghost", "Sunny", "Dash", "Ember", "Frost", "Jade", "Onyx",
|
||||
"Willow", "Tank", "Pip", "Mochi", "Salem", "Patches", "Bean", "Rocket",
|
||||
"Blaze",
|
||||
"Thunder",
|
||||
"Shadow",
|
||||
"Luna",
|
||||
"Spike",
|
||||
"Rex",
|
||||
"Cinder",
|
||||
"Misty",
|
||||
"Rocky",
|
||||
"Breeze",
|
||||
"Fang",
|
||||
"Nova",
|
||||
"Scout",
|
||||
"Atlas",
|
||||
"Pepper",
|
||||
"Storm",
|
||||
"Bandit",
|
||||
"Echo",
|
||||
"Maple",
|
||||
"Titan",
|
||||
"Ziggy",
|
||||
"Bolt",
|
||||
"Rusty",
|
||||
"Pearl",
|
||||
"Ivy",
|
||||
"Ghost",
|
||||
"Sunny",
|
||||
"Dash",
|
||||
"Ember",
|
||||
"Frost",
|
||||
"Jade",
|
||||
"Onyx",
|
||||
"Willow",
|
||||
"Tank",
|
||||
"Pip",
|
||||
"Mochi",
|
||||
"Salem",
|
||||
"Patches",
|
||||
"Bean",
|
||||
"Rocket",
|
||||
]
|
||||
|
||||
DEATH_CAUSES = [
|
||||
@@ -129,20 +163,18 @@ async def get_leaf_routes(session: AsyncSession, game_id: int) -> list[Route]:
|
||||
"""Get routes that can have encounters (no children)."""
|
||||
# Get all routes for the game
|
||||
result = await session.execute(
|
||||
select(Route)
|
||||
.where(Route.game_id == game_id)
|
||||
.order_by(Route.order)
|
||||
select(Route).where(Route.game_id == game_id).order_by(Route.order)
|
||||
)
|
||||
all_routes = result.scalars().all()
|
||||
|
||||
parent_ids = {r.parent_route_id for r in all_routes if r.parent_route_id is not None}
|
||||
parent_ids = {
|
||||
r.parent_route_id for r in all_routes if r.parent_route_id is not None
|
||||
}
|
||||
leaf_routes = [r for r in all_routes if r.id not in parent_ids]
|
||||
return leaf_routes
|
||||
|
||||
|
||||
async def get_encounterables(
|
||||
session: AsyncSession, game_id: int
|
||||
) -> list[int]:
|
||||
async def get_encounterables(session: AsyncSession, game_id: int) -> list[int]:
|
||||
"""Get pokemon IDs that appear in route encounters for this game."""
|
||||
from app.models.route_encounter import RouteEncounter
|
||||
|
||||
@@ -157,16 +189,16 @@ async def get_encounterables(
|
||||
|
||||
async def get_evolution_map(session: AsyncSession) -> dict[int, list[int]]:
|
||||
"""Return {from_pokemon_id: [to_pokemon_id, ...]} for all evolutions."""
|
||||
result = await session.execute(select(Evolution.from_pokemon_id, Evolution.to_pokemon_id))
|
||||
result = await session.execute(
|
||||
select(Evolution.from_pokemon_id, Evolution.to_pokemon_id)
|
||||
)
|
||||
evo_map: dict[int, list[int]] = {}
|
||||
for from_id, to_id in result:
|
||||
evo_map.setdefault(from_id, []).append(to_id)
|
||||
return evo_map
|
||||
|
||||
|
||||
def pick_routes_for_run(
|
||||
leaf_routes: list[Route], progress: float
|
||||
) -> list[Route]:
|
||||
def pick_routes_for_run(leaf_routes: list[Route], progress: float) -> list[Route]:
|
||||
"""Pick a subset of leaf routes respecting one-per-group.
|
||||
|
||||
For routes with a parent, only one sibling per parent_route_id is chosen.
|
||||
@@ -257,74 +289,73 @@ async def inject():
|
||||
"""Clear existing runs and inject test data."""
|
||||
print("Injecting test data...")
|
||||
|
||||
async with async_session() as session:
|
||||
async with session.begin():
|
||||
# Clear existing runs and encounters
|
||||
await session.execute(delete(Encounter))
|
||||
await session.execute(delete(NuzlockeRun))
|
||||
print("Cleared existing runs and encounters")
|
||||
async with async_session() as session, session.begin():
|
||||
# Clear existing runs and encounters
|
||||
await session.execute(delete(Encounter))
|
||||
await session.execute(delete(NuzlockeRun))
|
||||
print("Cleared existing runs and encounters")
|
||||
|
||||
evo_map = await get_evolution_map(session)
|
||||
now = datetime.now(timezone.utc)
|
||||
evo_map = await get_evolution_map(session)
|
||||
now = datetime.now(UTC)
|
||||
|
||||
total_runs = 0
|
||||
total_encounters = 0
|
||||
total_runs = 0
|
||||
total_encounters = 0
|
||||
|
||||
for run_def in RUN_DEFS:
|
||||
game = await get_game_by_slug(session, run_def["game_slug"])
|
||||
if game is None:
|
||||
print(f" Warning: game '{run_def['game_slug']}' not found, skipping")
|
||||
continue
|
||||
for run_def in RUN_DEFS:
|
||||
game = await get_game_by_slug(session, run_def["game_slug"])
|
||||
if game is None:
|
||||
print(f" Warning: game '{run_def['game_slug']}' not found, skipping")
|
||||
continue
|
||||
|
||||
# Build rules
|
||||
rules = {**DEFAULT_RULES, **run_def["rules"]}
|
||||
# Build rules
|
||||
rules = {**DEFAULT_RULES, **run_def["rules"]}
|
||||
|
||||
# Compute dates
|
||||
started_at = now - timedelta(days=run_def["started_days_ago"])
|
||||
completed_at = None
|
||||
if run_def["ended_days_ago"] is not None:
|
||||
completed_at = now - timedelta(days=run_def["ended_days_ago"])
|
||||
# Compute dates
|
||||
started_at = now - timedelta(days=run_def["started_days_ago"])
|
||||
completed_at = None
|
||||
if run_def["ended_days_ago"] is not None:
|
||||
completed_at = now - timedelta(days=run_def["ended_days_ago"])
|
||||
|
||||
run = NuzlockeRun(
|
||||
game_id=game.id,
|
||||
name=run_def["name"],
|
||||
status=run_def["status"],
|
||||
rules=rules,
|
||||
started_at=started_at,
|
||||
completed_at=completed_at,
|
||||
)
|
||||
session.add(run)
|
||||
await session.flush() # get run.id
|
||||
run = NuzlockeRun(
|
||||
game_id=game.id,
|
||||
name=run_def["name"],
|
||||
status=run_def["status"],
|
||||
rules=rules,
|
||||
started_at=started_at,
|
||||
completed_at=completed_at,
|
||||
)
|
||||
session.add(run)
|
||||
await session.flush() # get run.id
|
||||
|
||||
# Get routes and pokemon for this game
|
||||
leaf_routes = await get_leaf_routes(session, game.id)
|
||||
pokemon_ids = await get_encounterables(session, game.id)
|
||||
|
||||
if not leaf_routes or not pokemon_ids:
|
||||
print(f" {run_def['name']}: no routes or pokemon, skipping encounters")
|
||||
total_runs += 1
|
||||
continue
|
||||
|
||||
chosen_routes = pick_routes_for_run(leaf_routes, run_def["progress"])
|
||||
used_pokemon: set[int] = set()
|
||||
|
||||
run_encounters = 0
|
||||
for i, route in enumerate(chosen_routes):
|
||||
enc = generate_encounter(
|
||||
run.id, route, pokemon_ids, evo_map, used_pokemon, i
|
||||
)
|
||||
session.add(enc)
|
||||
run_encounters += 1
|
||||
# Get routes and pokemon for this game
|
||||
leaf_routes = await get_leaf_routes(session, game.id)
|
||||
pokemon_ids = await get_encounterables(session, game.id)
|
||||
|
||||
if not leaf_routes or not pokemon_ids:
|
||||
print(f" {run_def['name']}: no routes or pokemon, skipping encounters")
|
||||
total_runs += 1
|
||||
total_encounters += run_encounters
|
||||
continue
|
||||
|
||||
print(
|
||||
f" {run_def['name']} ({game.name}, {run_def['status']}): "
|
||||
f"{run_encounters} encounters across {len(chosen_routes)} routes"
|
||||
chosen_routes = pick_routes_for_run(leaf_routes, run_def["progress"])
|
||||
used_pokemon: set[int] = set()
|
||||
|
||||
run_encounters = 0
|
||||
for i, route in enumerate(chosen_routes):
|
||||
enc = generate_encounter(
|
||||
run.id, route, pokemon_ids, evo_map, used_pokemon, i
|
||||
)
|
||||
session.add(enc)
|
||||
run_encounters += 1
|
||||
|
||||
print(f"\nCreated {total_runs} runs with {total_encounters} total encounters")
|
||||
total_runs += 1
|
||||
total_encounters += run_encounters
|
||||
|
||||
print(
|
||||
f" {run_def['name']} ({game.name}, {run_def['status']}): "
|
||||
f"{run_encounters} encounters across {len(chosen_routes)} routes"
|
||||
)
|
||||
|
||||
print(f"\nCreated {total_runs} runs with {total_encounters} total encounters")
|
||||
|
||||
print("Test data injection complete!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user