Browse Source

- Updates to the plan tab

master
Quildra 1 year ago
parent
commit
adbb64a3f3
  1. 49
      Site/OriginDex.py
  2. 70
      Site/templates/index.html

49
Site/OriginDex.py

@ -3,7 +3,38 @@ from flask import Flask, render_template, jsonify
from collections import defaultdict from collections import defaultdict
import os import os
import json import json
import re
import wordninja import wordninja
from typing import List, Set
class CustomWordNinja:
def __init__(self, custom_words: List[str] = None):
self.custom_words = []
if custom_words:
# Store custom words with original capitalization, sorted by length
self.custom_words = sorted(custom_words, key=len, reverse=True)
def split(self, text: str) -> str:
working_text = text
# First handle exact custom words to preserve capitalization
for word in self.custom_words:
pattern = re.compile(word, re.IGNORECASE)
working_text = pattern.sub(f' {word} ', working_text)
# Clean up spaces
working_text = ' '.join(working_text.split())
# For remaining text, use wordninja
parts = []
for part in working_text.split():
if part in self.custom_words:
parts.append(part)
else:
split_parts = wordninja.split(part)
parts.extend(split_parts)
return ' '.join(parts)
POKEMON_PROPER_NOUNS = { POKEMON_PROPER_NOUNS = {
"Alola", "Alola",
@ -125,6 +156,8 @@ def load_pokemon_data():
def index(): def index():
pokemon_list = load_pokemon_data() pokemon_list = load_pokemon_data()
splitter = CustomWordNinja(POKEMON_PROPER_NOUNS)
try: try:
with open('efficiency_plan.json', 'r', encoding='utf-8') as f: with open('efficiency_plan.json', 'r', encoding='utf-8') as f:
efficiency_plan = json.load(f) efficiency_plan = json.load(f)
@ -142,9 +175,8 @@ def index():
direct = cursor.fetchone() direct = cursor.fetchone()
if direct: if direct:
words = wordninja.split(direct[0]) words = splitter.split(direct[0])
cleaned_method = ' '.join(words) return [words]
return [cleaned_method]
# Try to find indirect evolution path # Try to find indirect evolution path
cursor.execute(''' cursor.execute('''
@ -174,9 +206,8 @@ def index():
cleaned_methods = [] cleaned_methods = []
for method in methods: for method in methods:
# Split and rejoin with spaces # Split and rejoin with spaces
words = wordninja.split(method[0]) words = splitter.split(method[0])
cleaned_method = ' '.join(words) cleaned_methods.append(words)
cleaned_methods.append(cleaned_method)
return cleaned_methods return cleaned_methods
return ['Evolution'] return ['Evolution']
@ -238,12 +269,6 @@ def pokemon_details(pfic):
return jsonify(encounters) return jsonify(encounters)
if __name__ == '__main__': 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_files = ['.']
extra_dirs = ['./templates/', './static/'] extra_dirs = ['./templates/', './static/']
for extra_dir in extra_dirs: for extra_dir in extra_dirs:

70
Site/templates/index.html

@ -320,6 +320,24 @@
align-items: center; align-items: center;
} }
.catch-count-container {
display: flex;
align-items: center;
gap: 5px;
}
.catch-count-pokeball {
width: 20px;
height: 20px;
object-fit: contain;
}
.catch-count {
color: #666;
font-size: 1.1em;
font-weight: bold;
}
.pokemon-details { .pokemon-details {
display: none; display: none;
padding: 15px; padding: 15px;
@ -336,11 +354,6 @@
object-fit: contain; object-fit: contain;
} }
.catch-count {
color: #666;
font-size: 0.9em;
}
.evolution-list, .breeding-list { .evolution-list, .breeding-list {
margin: 10px 0; margin: 10px 0;
padding: 10px; padding: 10px;
@ -406,6 +419,38 @@
font-size: 0.8em; font-size: 0.8em;
color: #4CAF50; color: #4CAF50;
} }
.accordion-button-static {
position: relative;
display: flex;
align-items: center;
width: 100%;
padding: var(--bs-accordion-btn-padding-y) var(--bs-accordion-btn-padding-x);
font-size: 1rem;
color: var(--bs-accordion-btn-color);
text-align: left;
background-color: var(--bs-accordion-btn-bg);
border: 0;
border-radius: 0;
overflow-anchor: none;
}
.accordion-button-static img {
margin-right: 0.5rem;
}
/* Remove hover effects if desired */
.accordion-button-static:hover {
z-index: 2;
}
.pokemon-header-right {
display: flex;
align-items: center;
min-width: 80px; /* Adjust this value to match your needs */
justify-content: space-between;
gap: 10px;
}
</style> </style>
</head> </head>
<body> <body>
@ -472,7 +517,7 @@
<div class="game-content"> <div class="game-content">
{% for pokemon in game.pokemon %} {% for pokemon in game.pokemon %}
<div class="pokemon-entry"> <div class="pokemon-entry">
<div class="pokemon-header" onclick="togglePokemonDetails(this)"> <div class="pokemon-header" {% if (pokemon.evolve_to|length > 0) or (pokemon.breed_for|length > 0) %}onclick="togglePokemonDetails(this)"{% endif %}>
<img src="{{ url_for('static', filename='images/pokemon/' + pokemon.pfic + '.png') }}" <img src="{{ url_for('static', filename='images/pokemon/' + pokemon.pfic + '.png') }}"
alt="{{ pokemon.name }}" alt="{{ pokemon.name }}"
class="pokemon-thumbnail"> class="pokemon-thumbnail">
@ -480,8 +525,17 @@
<h3 style="margin: 0;"> <h3 style="margin: 0;">
{{ pokemon.name }}{% if pokemon.form_name %} ({{ pokemon.form_name }}){% endif %} {{ pokemon.name }}{% if pokemon.form_name %} ({{ pokemon.form_name }}){% endif %}
</h3> </h3>
<span class="catch-count">Catch: {{ pokemon.catch_count }}</span> <div class="pokemon-header-right">
<span class="toggle-icon"></span> <div class="catch-count-container">
<img src="{{ url_for('static', filename='images/pokeball_color.png') }}"
alt="Catch count"
class="catch-count-pokeball">
<span class="catch-count">{{ pokemon.catch_count }}</span>
</div>
{% if (pokemon.evolve_to|length > 0) or (pokemon.breed_for|length > 0) %}
<span class="toggle-icon"></span>
{% endif %}
</div>
</div> </div>
</div> </div>
<div class="pokemon-details"> <div class="pokemon-details">

Loading…
Cancel
Save