|
|
|
@ -11,57 +11,86 @@ def load_pokemon_data(): |
|
|
|
conn = sqlite3.connect('pokemon_forms.db') |
|
|
|
cursor = conn.cursor() |
|
|
|
|
|
|
|
# First query: Get all Pokémon data |
|
|
|
cursor.execute(''' |
|
|
|
WITH RECURSIVE EvolutionChain AS ( |
|
|
|
SELECT PFIC, from_pfic |
|
|
|
FROM evolution_chains |
|
|
|
UNION ALL |
|
|
|
SELECT ec.PFIC, e.from_pfic |
|
|
|
FROM evolution_chains ec |
|
|
|
JOIN EvolutionChain e ON ec.from_pfic = e.PFIC |
|
|
|
), |
|
|
|
BaseForm AS ( |
|
|
|
SELECT PFIC, MIN(from_pfic) AS base_pfic |
|
|
|
FROM EvolutionChain |
|
|
|
GROUP BY PFIC |
|
|
|
), |
|
|
|
EarliestGamePerPokemon AS ( |
|
|
|
SELECT e.pfic, MIN(g.generation) as min_generation, g.name as earliest_game |
|
|
|
WITH EarliestGamePerPokemon AS ( |
|
|
|
SELECT e.pfic, MIN(g.generation) as min_generation, MIN(g.id) as earliest_game_id |
|
|
|
FROM encounters e |
|
|
|
JOIN games g ON e.game = g.name |
|
|
|
JOIN games g ON e.game_id = g.id |
|
|
|
GROUP BY e.pfic |
|
|
|
), |
|
|
|
FirstGameInEarliestGen AS ( |
|
|
|
SELECT eg.pfic, MIN(g.id) as first_game_id |
|
|
|
FROM EarliestGamePerPokemon eg |
|
|
|
JOIN games g ON eg.min_generation = g.generation |
|
|
|
GROUP BY eg.pfic |
|
|
|
) |
|
|
|
SELECT |
|
|
|
pf.national_dex, pf.name, pf.form_name, pf.PFIC, pf.generation, |
|
|
|
ps.storable_in_home, eg.earliest_game, |
|
|
|
m.icon_path as mark_icon, m.id as mark_id |
|
|
|
ps.storable_in_home, g.name as earliest_game, |
|
|
|
m.icon_path as mark_icon, m.id as mark_id, pf.is_baby_form |
|
|
|
FROM pokemon_forms pf |
|
|
|
JOIN pokemon_storage ps ON pf.PFIC = ps.PFIC |
|
|
|
LEFT JOIN BaseForm bf ON pf.PFIC = bf.PFIC |
|
|
|
LEFT JOIN EarliestGamePerPokemon eg ON COALESCE(bf.base_pfic, pf.PFIC) = eg.pfic |
|
|
|
LEFT JOIN FirstGameInEarliestGen fg ON COALESCE(bf.base_pfic, pf.PFIC) = fg.pfic |
|
|
|
LEFT JOIN games g ON fg.first_game_id = g.id |
|
|
|
LEFT JOIN EarliestGamePerPokemon eg ON pf.PFIC = eg.pfic |
|
|
|
LEFT JOIN games g ON eg.earliest_game_id = g.id |
|
|
|
LEFT JOIN mark_game_associations mga ON g.id = mga.game_id |
|
|
|
LEFT JOIN marks m ON mga.mark_id = m.id |
|
|
|
WHERE ps.storable_in_home = 1 |
|
|
|
ORDER BY pf.PFIC |
|
|
|
''') |
|
|
|
|
|
|
|
pokemon_data = cursor.fetchall() |
|
|
|
|
|
|
|
# Second query: Get evolution chain with generation info |
|
|
|
cursor.execute(''' |
|
|
|
WITH RECURSIVE EvolutionChain AS ( |
|
|
|
SELECT to_pfic AS PFIC, from_pfic, pf.generation |
|
|
|
FROM evolution_chains ec |
|
|
|
JOIN pokemon_forms pf ON ec.to_pfic = pf.PFIC |
|
|
|
UNION ALL |
|
|
|
SELECT ec.to_pfic, e.from_pfic, pf.generation |
|
|
|
FROM evolution_chains ec |
|
|
|
JOIN EvolutionChain e ON ec.from_pfic = e.PFIC |
|
|
|
JOIN pokemon_forms pf ON ec.to_pfic = pf.PFIC |
|
|
|
) |
|
|
|
SELECT PFIC, MIN(from_pfic) AS base_pfic, MIN(generation) AS base_generation |
|
|
|
FROM EvolutionChain |
|
|
|
GROUP BY PFIC |
|
|
|
''') |
|
|
|
|
|
|
|
evolution_data = {row[0]: (row[1], row[2]) for row in cursor.fetchall()} |
|
|
|
|
|
|
|
# Process the data |
|
|
|
current_group = [] |
|
|
|
current_generation = None |
|
|
|
current_dex_number = None |
|
|
|
pokemon_forms = [] |
|
|
|
|
|
|
|
for row in cursor.fetchall(): |
|
|
|
national_dex, name, form_name, pfic, generation, storable_in_home, earliest_game, mark_icon, mark_id = row |
|
|
|
for row in pokemon_data: |
|
|
|
national_dex, name, form_name, pfic, generation, storable_in_home, earliest_game, mark_icon, mark_id, is_baby_form = row |
|
|
|
|
|
|
|
# Find the base form for the mark, considering generation |
|
|
|
base_pfic = pfic |
|
|
|
base_generation = generation |
|
|
|
while base_pfic in evolution_data: |
|
|
|
prev_pfic, prev_generation = evolution_data[base_pfic] |
|
|
|
if prev_pfic is not None and prev_generation == base_generation: |
|
|
|
base_pfic = prev_pfic |
|
|
|
else: |
|
|
|
break |
|
|
|
|
|
|
|
# If the base form is different, we need to fetch its earliest game and mark |
|
|
|
if base_pfic != pfic: |
|
|
|
cursor.execute(''' |
|
|
|
SELECT g.name, m.icon_path, m.id |
|
|
|
FROM encounters e |
|
|
|
JOIN games g ON e.game_id = g.id |
|
|
|
LEFT JOIN mark_game_associations mga ON g.id = mga.game_id |
|
|
|
LEFT JOIN marks m ON mga.mark_id = m.id |
|
|
|
WHERE e.pfic = ? AND g.generation = ? |
|
|
|
ORDER BY g.id |
|
|
|
LIMIT 1 |
|
|
|
''', (base_pfic, base_generation)) |
|
|
|
base_data = cursor.fetchone() |
|
|
|
if base_data: |
|
|
|
earliest_game, mark_icon, mark_id = base_data |
|
|
|
|
|
|
|
pokemon = { |
|
|
|
'pfic': pfic, |
|
|
|
'ID': national_dex, |
|
|
|
'Name': name, |
|
|
|
'Form': form_name if form_name else "Default", |
|
|
|
@ -118,25 +147,27 @@ def index(): |
|
|
|
pokemon_list = load_pokemon_data() |
|
|
|
return render_template('index.html', grouped_pokemon=pokemon_list) |
|
|
|
|
|
|
|
@app.route('/pokemon/<int:dex_number>') |
|
|
|
def pokemon_details(dex_number): |
|
|
|
conn = sqlite3.connect('pokemon_forms.db') # Updated database name |
|
|
|
@app.route('/pokemon/<string:pfic>') |
|
|
|
def pokemon_details(pfic): |
|
|
|
conn = sqlite3.connect('pokemon_forms.db') |
|
|
|
cursor = conn.cursor() |
|
|
|
|
|
|
|
cursor.execute(''' |
|
|
|
SELECT pf.form_name, e.game, e.location, e.day, e.time, |
|
|
|
SELECT pf.form_name, g.name, g.id as game_id, e.location, e.day, e.time, |
|
|
|
e.dual_slot, e.static_encounter, e.static_encounter_count, |
|
|
|
e.extra_text, e.stars, e.fishing, e.rods, e.starter |
|
|
|
FROM pokemon_forms pf |
|
|
|
JOIN encounters e ON pf.PFIC = e.pfic |
|
|
|
WHERE pf.national_dex = ? |
|
|
|
ORDER BY pf.form_name, e.game, e.location |
|
|
|
''', (dex_number,)) |
|
|
|
JOIN games g ON e.game_id = g.id |
|
|
|
WHERE pf.pfic = ? |
|
|
|
ORDER BY g.id, pf.form_name, e.location |
|
|
|
''', (pfic,)) |
|
|
|
|
|
|
|
encounters = [ |
|
|
|
{ |
|
|
|
'form': form, |
|
|
|
'game': game, |
|
|
|
'game_id': game_id, |
|
|
|
'location': location, |
|
|
|
'day': day, |
|
|
|
'time': time, |
|
|
|
@ -149,7 +180,7 @@ def pokemon_details(dex_number): |
|
|
|
'rods': rods, |
|
|
|
'starter': starter |
|
|
|
} |
|
|
|
for form, game, location, day, time, dual_slot, static_encounter, static_encounter_count, |
|
|
|
for form, game, game_id, location, day, time, dual_slot, static_encounter, static_encounter_count, |
|
|
|
extra_text, stars, fishing, rods, starter in cursor.fetchall() |
|
|
|
] |
|
|
|
|
|
|
|
|