Browse Source

- More improvements to the site

master
Dan 1 year ago
parent
commit
0b087af3ff
  1. 81
      Site/OriginDex.py

81
Site/OriginDex.py

@ -3,6 +3,21 @@ from flask import Flask, render_template, jsonify
from collections import defaultdict
import os
import json
import wordninja
POKEMON_PROPER_NOUNS = {
"Alola",
"Kanto",
"Johto",
"Hoenn",
"Sinnoh",
"Unova",
"Kalos",
"Galar",
"Hisui",
"Paldea",
# Add any other proper nouns that should be preserved
}
app = Flask(__name__)
@ -110,26 +125,68 @@ def load_pokemon_data():
def index():
pokemon_list = load_pokemon_data()
# Load the efficiency plan
try:
with open('efficiency_plan.json', 'r', encoding='utf-8') as f:
efficiency_plan = json.load(f)
# Enhance the plan with evolution methods
conn = sqlite3.connect('pokemon_forms.db')
cursor = conn.cursor()
def get_evolution_methods(from_pfic, to_pfic):
# Get direct evolution method
cursor.execute('''
SELECT method, to_pfic
FROM evolution_chains
WHERE from_pfic = ? AND to_pfic = ?
''', (from_pfic, to_pfic))
direct = cursor.fetchone()
if direct:
words = wordninja.split(direct[0])
cleaned_method = ' '.join(words)
return [cleaned_method]
# Try to find indirect evolution path
cursor.execute('''
WITH RECURSIVE evolution_path AS (
-- Base case: direct evolutions from start
SELECT from_pfic, to_pfic, method, 1 as depth
FROM evolution_chains
WHERE from_pfic = ?
UNION ALL
-- Recursive case: follow chain
SELECT e.from_pfic, e.to_pfic, e.method, ep.depth + 1
FROM evolution_chains e
JOIN evolution_path ep ON e.from_pfic = ep.to_pfic
WHERE ep.depth < 3 -- Prevent infinite loops
)
SELECT method
FROM evolution_path
WHERE to_pfic = ?
ORDER BY depth;
''', (from_pfic, to_pfic))
methods = cursor.fetchall()
if methods:
# Clean up each method string
cleaned_methods = []
for method in methods:
# Split and rejoin with spaces
words = wordninja.split(method[0])
cleaned_method = ' '.join(words)
cleaned_methods.append(cleaned_method)
return cleaned_methods
return ['Evolution']
# Enhance the plan with evolution methods
for game in efficiency_plan:
for pokemon in game['pokemon']:
if pokemon.get('evolve_to'):
for evolution in pokemon['evolve_to']:
cursor.execute('''
SELECT method
FROM evolution_chains
WHERE from_pfic = ? AND to_pfic = ?
''', (pokemon['pfic'], evolution['pfic']))
result = cursor.fetchone()
evolution['method'] = result[0] if result else 'Evolution'
methods = get_evolution_methods(pokemon['pfic'], evolution['pfic'])
evolution['method'] = ''.join(methods)
conn.close()
@ -181,6 +238,12 @@ def pokemon_details(pfic):
return jsonify(encounters)
if __name__ == '__main__':
# Add the custom words to wordninja's word list
#wordninja.DEFAULT_WEIGHT_MULTIPLIER = 2 # Make default words twice as likely
#for word in POKEMON_PROPER_NOUNS:
# wordninja.addWords([word], weight=10) # Higher weight makes these words more likely to be kept together
extra_files = ['.']
extra_dirs = ['./templates/', './static/']
for extra_dir in extra_dirs:

Loading…
Cancel
Save