Browse Source

- More accounting for nearly all pokemon having gendered forms now

master
Dan 1 year ago
parent
commit
4e8c81ebbf
  1. 18
      ui/workers/gather_encounter_locations.py
  2. 32
      ui/workers/gather_evolutions_worker.py

18
ui/workers/gather_encounter_locations.py

@ -395,7 +395,7 @@ class GatherEncountersWorker(QRunnable):
if form.lower() in ["spring form", "summer form", "autumn form", "winter form"] and main_form == None: if form.lower() in ["spring form", "summer form", "autumn form", "winter form"] and main_form == None:
return True return True
if main_form is None: if form and main_form is None:
return False return False
if main_form in ["All Forms", "All Sizes"]: if main_form in ["All Forms", "All Sizes"]:
@ -551,11 +551,25 @@ class GatherEncountersWorker(QRunnable):
for result in results: for result in results:
if compare_pokemon_forms(result["form_name"], form): if compare_pokemon_forms(result["form_name"], form):
details["evolve_from"] = result["pfic"] details["evolve_from"] = result["pfic"]
break
if results and "evolve_from" not in details: if results and "evolve_from" not in details:
for result in results: for result in results:
if compare_pokemon_forms(result["form_name"], search_form if search_form != form else "Male"): if compare_pokemon_forms(result["form_name"], search_form if search_form != form else None):
details["evolve_from"] = result["pfic"] details["evolve_from"] = result["pfic"]
break
if search_form and results and "evolve_from" not in details:
if "female" in search_form.lower():
form = "Female"
elif "male" in search_form.lower():
form = "Male"
if form:
for result in results:
if compare_pokemon_forms(result["form_name"], form):
details["evolve_from"] = result["pfic"]
break
return details return details

32
ui/workers/gather_evolutions_worker.py

@ -57,7 +57,14 @@ class GatherEvolutions(QRunnable):
gender = None gender = None
if search_form and "male" in search_form.lower(): if search_form and "male" in search_form.lower():
gender = search_form if "female" in search_form.lower():
search_form = search_form.replace("Female", "").replace("female", "").strip()
gender = "Female"
else:
search_form = search_form.replace("Male", "").replace("male", "").strip()
gender = "Male"
if search_form == "":
search_form = None search_form = None
if pokemon_name == "Flabébé": if pokemon_name == "Flabébé":
@ -79,6 +86,7 @@ class GatherEvolutions(QRunnable):
evolution_table = evolution_section.parent.find_next('table') evolution_table = evolution_section.parent.find_next('table')
if form: if form:
form_without_form = form.replace('Form', '').replace('form', '').strip() form_without_form = form.replace('Form', '').replace('form', '').strip()
form_without_form = self.strip_gender_from_form(form_without_form)
for tag in evolution_section.parent.find_next_siblings(): for tag in evolution_section.parent.find_next_siblings():
if tag.name == 'h4' and form_without_form in tag.get_text(strip=True): if tag.name == 'h4' and form_without_form in tag.get_text(strip=True):
evolution_table = tag.find_next('table') evolution_table = tag.find_next('table')
@ -358,11 +366,19 @@ class GatherEvolutions(QRunnable):
"form_name" "form_name"
] ]
results = db.get_pokemon_details_by_name(name, fields) results = db.get_pokemon_details_by_name(name, fields)
#results = db_controller.execute_query('SELECT PFIC, name, form_name FROM pokemon_forms WHERE name = ?', (name,))
if not results: if not results:
return None return None
if gender:
gender_filtered_results = []
for entry in results:
if gender.lower() == "male" and entry["pfic"][-1] == "1":
gender_filtered_results.append(entry)
elif gender.lower() == "female" and entry["pfic"][-1] == "2":
gender_filtered_results.append(entry)
results = gender_filtered_results
results.sort(key=lambda x: parse_pfic(x["pfic"])) results.sort(key=lambda x: parse_pfic(x["pfic"]))
if form is None and gender is None: if form is None and gender is None:
@ -374,7 +390,7 @@ class GatherEvolutions(QRunnable):
else: else:
return results[0]["pfic"] # Return the PFIC of the first result if no form is specified return results[0]["pfic"] # Return the PFIC of the first result if no form is specified
if gender: if form is None and gender:
gendered_form = self.get_pokemon_form_by_name(name, gender, threshold=100) gendered_form = self.get_pokemon_form_by_name(name, gender, threshold=100)
if gendered_form: if gendered_form:
return gendered_form return gendered_form
@ -386,6 +402,10 @@ class GatherEvolutions(QRunnable):
if self.fuzzy_match_form(stripped_form, stripped_db_form, threshold): if self.fuzzy_match_form(stripped_form, stripped_db_form, threshold):
return entry["pfic"] return entry["pfic"]
stripped_db_form = self.strip_gender_from_form(stripped_db_form)
if self.fuzzy_match_form(stripped_form, stripped_db_form, threshold):
return entry["pfic"]
# Some times we get a form for a pokemon that doesn't really have one. # Some times we get a form for a pokemon that doesn't really have one.
#if len(results) > 1 and form != None and gender and threshold != 100: #if len(results) > 1 and form != None and gender and threshold != 100:
# return results[0]["pfic"] # return results[0]["pfic"]
@ -400,6 +420,12 @@ class GatherEvolutions(QRunnable):
return form_name return form_name
return form_name return form_name
def strip_gender_from_form(seld, form_name: str) -> str:
if form_name:
form_name = form_name.replace("Female", "").replace("female", "").strip()
form_name = form_name.replace("Male", "").replace("male", "").strip()
return form_name
def fuzzy_match_form(self, form1: str, form2: str, threshold: int = 80) -> bool: def fuzzy_match_form(self, form1: str, form2: str, threshold: int = 80) -> bool:
if form1 is None or form2 is None: if form1 is None or form2 is None:
return form1 == form2 return form1 == form2

Loading…
Cancel
Save