Files
nuzlocke-tracker/tools/import-pokedb/import_pokedb/models.py
Julian Tabel 5240236759
Some checks failed
CI / backend-lint (pull_request) Successful in 9s
CI / actions-lint (pull_request) Failing after 6s
CI / frontend-lint (pull_request) Successful in 21s
Add per-condition encounter rates to seed data
Add a `condition` column to RouteEncounter so encounters can store
per-condition rates (time of day, season, weather) instead of flattening
to max(). Update the seed loader, API schemas, and frontend to support
the new `conditions` dict format in seed JSON.

Port the PoC branch's condition-aware EncounterModal UI with filter
tabs that let players see encounter rates for specific conditions.
Add horde/SOS as distinct encounter methods with their own badges.

Update the import tool to extract per-condition rates instead of
flattening, and add a merge script (tools/merge-conditions.py) that
enriches existing curated seed files with condition data from PokeDB.

Seed data updated for 22 games (5,684 encounters):
- Gen 2: Gold, Silver, Crystal (morning/day/night)
- Gen 4: HG, SS, Diamond, Pearl, Platinum, BD, SP (morning/day/night)
- Gen 5: Black, White, Black 2, White 2 (spring/summer/autumn/winter)
- Gen 7: Sun, Moon, Ultra Sun, Ultra Moon (day/night)
- Gen 8: Sword, Shield (weather)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 18:52:35 +01:00

88 lines
2.0 KiB
Python

"""Output data models matching the existing seed JSON format."""
from __future__ import annotations
from dataclasses import dataclass, field
@dataclass
class Encounter:
pokeapi_id: int
pokemon_name: str
method: str
encounter_rate: int
min_level: int
max_level: int
conditions: dict[str, int] | None = None
def to_dict(self) -> dict:
d: dict = {
"pokeapi_id": self.pokeapi_id,
"pokemon_name": self.pokemon_name,
"method": self.method,
"min_level": self.min_level,
"max_level": self.max_level,
}
if self.conditions:
d["encounter_rate"] = None
d["conditions"] = self.conditions
else:
d["encounter_rate"] = self.encounter_rate
return d
@dataclass
class Route:
name: str
order: int
encounters: list[Encounter] = field(default_factory=list)
children: list[Route] = field(default_factory=list)
def to_dict(self) -> dict:
d: dict = {
"name": self.name,
"order": self.order,
"encounters": [e.to_dict() for e in self.encounters],
}
if self.children:
d["children"] = [c.to_dict() for c in self.children]
return d
@dataclass
class Game:
name: str
slug: str
generation: int
region: str
release_year: int
color: str | None = None
def to_dict(self) -> dict:
return {
"name": self.name,
"slug": self.slug,
"generation": self.generation,
"region": self.region,
"release_year": self.release_year,
"color": self.color,
}
@dataclass
class Pokemon:
pokeapi_id: int
national_dex: int
name: str
types: list[str]
sprite_url: str
def to_dict(self) -> dict:
return {
"pokeapi_id": self.pokeapi_id,
"national_dex": self.national_dex,
"name": self.name,
"types": self.types,
"sprite_url": self.sprite_url,
}