|
|
|
@ -437,6 +437,25 @@ class DBEditor(QMainWindow): |
|
|
|
self.logger.info("Database reinitialized successfully.") |
|
|
|
QMessageBox.information(self, 'Database Reinitialized', 'The database has been cleared and reinitialized.') |
|
|
|
|
|
|
|
def determine_origin_mark(self, pfic, target_generation): |
|
|
|
encounters = event_system.call_sync('get_encounter_locations', pfic) |
|
|
|
if encounters: |
|
|
|
generation_encounters = [] |
|
|
|
for encounter in encounters: |
|
|
|
game_generation = event_system.call_sync('get_game_generation', encounter[0]) |
|
|
|
if game_generation == target_generation: |
|
|
|
generation_encounters.append(encounter) |
|
|
|
if len(generation_encounters) > 0: |
|
|
|
form_info = event_system.call_sync('get_pokemon_data', pfic) |
|
|
|
mark_id = event_system.call_sync('get_mark_for_game_name', generation_encounters[0][0]) |
|
|
|
if mark_id == None: |
|
|
|
self.logger.info(f"No mark found for {form_info[0]} {form_info[1]}") |
|
|
|
else: |
|
|
|
mark_details = event_system.call_sync('get_mark_details', mark_id) |
|
|
|
self.logger.info(f"Mark for {form_info[0]} {form_info[1]} is {mark_details[0]} - {mark_details[1]}") |
|
|
|
return mark_id |
|
|
|
return None |
|
|
|
|
|
|
|
def gather_marks_info(self, data): |
|
|
|
event_system.emit_sync('clear_log_display') |
|
|
|
self.logger.info("Starting to gather marks information...") |
|
|
|
@ -445,32 +464,118 @@ class DBEditor(QMainWindow): |
|
|
|
|
|
|
|
for pfic, name, form_name, national_dex in pokemon_list: |
|
|
|
pokemon_data = event_system.call_sync('get_pokemon_data', pfic) |
|
|
|
|
|
|
|
if pokemon_data[4] == False: |
|
|
|
continue; |
|
|
|
|
|
|
|
self.logger.info(f"Determining mark for {name} {form_name if form_name else ''}") |
|
|
|
|
|
|
|
target_generation = pokemon_data[3] |
|
|
|
#Rule 1 |
|
|
|
# 1. If a pokemon form has a previous evolution from within the same generation, |
|
|
|
# use the mark of the previous evolution. This should be recursive within the same generation. |
|
|
|
chain = event_system.call_sync('get_evolution_chain', pfic) |
|
|
|
if chain: |
|
|
|
find_me = lambda x: x[0] == pfic |
|
|
|
target_index = next((i for i, item in enumerate(chain) if find_me(item)), -1) |
|
|
|
base_form_in_generation = None |
|
|
|
last_pfic = pfic |
|
|
|
current_pfic = pfic |
|
|
|
while True: |
|
|
|
current_pfic = event_system.call_sync('get_evolution_parent', current_pfic) |
|
|
|
current_pfic = event_system.call_sync('get_evolution_parent', last_pfic) |
|
|
|
if current_pfic == None: |
|
|
|
base_form_in_generation = current_pfic |
|
|
|
base_form_in_generation = last_pfic |
|
|
|
break |
|
|
|
chain_pokemon_data = event_system.call_sync('get_pokemon_data', current_pfic) |
|
|
|
if chain_pokemon_data[3] == pokemon_data[3]: |
|
|
|
base_form_in_generation = current_pfic |
|
|
|
chain_pokemon_data = event_system.call_sync('get_pokemon_data', current_pfic[0]) |
|
|
|
if chain_pokemon_data[3] == target_generation: |
|
|
|
base_form_in_generation = current_pfic[0] |
|
|
|
else: |
|
|
|
base_form_in_generation = last_pfic |
|
|
|
break |
|
|
|
last_pfic = current_pfic[0] |
|
|
|
|
|
|
|
if base_form_in_generation: |
|
|
|
if base_form_in_generation and base_form_in_generation != pfic: |
|
|
|
self.logger.info(f"Base form in generation for {name} {form_name if form_name else ''} is {base_form_in_generation}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mark_id = self.determine_origin_mark(base_form_in_generation, target_generation) |
|
|
|
if mark_id != None: |
|
|
|
event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) |
|
|
|
continue; |
|
|
|
elif base_form_in_generation == pfic: |
|
|
|
mark_id = self.determine_origin_mark(pfic, target_generation) |
|
|
|
if mark_id != None: |
|
|
|
event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) |
|
|
|
continue; |
|
|
|
#Rule 2 |
|
|
|
# If a pokemon form has no previous evolution from within the same generation, |
|
|
|
# look at the encounters of the pokemon form from this generation and use the mark of the earliest |
|
|
|
# game you can encounter that form in from that generation |
|
|
|
mark_id = self.determine_origin_mark(pfic, target_generation) |
|
|
|
if mark_id != None: |
|
|
|
event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
# this bit doesn't work as we exclude eveolve encounters from our dataset. |
|
|
|
# this needs to change so we do include them, but filter them out of all our current queries |
|
|
|
# then make a new API that includes them to solve this problem. |
|
|
|
# We then find the earliest encounter in the for the base pokemon, that gets uus a game id |
|
|
|
# we then use that game id to get the generation and run the determine_origin_mark using that generation |
|
|
|
# for its evolution line. |
|
|
|
|
|
|
|
#Rule 3 |
|
|
|
# If there are no encounters for the pokemon form from this generation, |
|
|
|
# look to see if a previous evolution has an encounter from this generation, and use the mark of the earliest |
|
|
|
# game from this generation that the previous evolution is encounterable in. |
|
|
|
if chain: |
|
|
|
last_pfic = pfic |
|
|
|
mark_identified = False |
|
|
|
should_continue = True |
|
|
|
while should_continue: |
|
|
|
encounters = event_system.call_sync('get_encounter_locations', last_pfic) |
|
|
|
if encounters: |
|
|
|
earliest_game = 100 |
|
|
|
for encounter in encounters: |
|
|
|
game_id = event_system.call_sync('get_game_id_for_name', encounter[0]) |
|
|
|
if game_id <= earliest_game: |
|
|
|
earliest_game = game_id |
|
|
|
if earliest_game < 100: |
|
|
|
form_info = event_system.call_sync('get_pokemon_data', last_pfic) |
|
|
|
mark_id = event_system.call_sync('get_mark_for_game', earliest_game) |
|
|
|
if mark_id == None: |
|
|
|
self.logger.info(f"No mark found for {form_info[0]} {form_info[1]}") |
|
|
|
else: |
|
|
|
mark_details = event_system.call_sync('get_mark_details', mark_id) |
|
|
|
self.logger.info(f"Mark for {form_info[0]} {form_info[1]} is {mark_details[0]} - {mark_details[1]}") |
|
|
|
event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) |
|
|
|
should_continue = False |
|
|
|
mark_identified = True |
|
|
|
break; |
|
|
|
|
|
|
|
last_pfic = event_system.call_sync('get_evolution_parent', last_pfic) |
|
|
|
if last_pfic == None: |
|
|
|
should_continue = False |
|
|
|
break |
|
|
|
if mark_identified: |
|
|
|
continue; |
|
|
|
|
|
|
|
#Rule 4 |
|
|
|
# If there are no encounters for the pokemon form or its evolution line from this generation, |
|
|
|
# use the mark of the earliest game of the generation is marked as being introducted in. |
|
|
|
encounters = event_system.call_sync('get_encounter_locations', pfic) |
|
|
|
if encounters: |
|
|
|
earliest_game = 100 |
|
|
|
for encounter in encounters: |
|
|
|
game_id = event_system.call_sync('get_game_id_for_name', encounter[0]) |
|
|
|
if game_id <= earliest_game: |
|
|
|
earliest_game = game_id |
|
|
|
if earliest_game < 100: |
|
|
|
form_info = event_system.call_sync('get_pokemon_data', pfic) |
|
|
|
mark_id = event_system.call_sync('get_mark_for_game', earliest_game) |
|
|
|
if mark_id == None: |
|
|
|
self.logger.info(f"No mark found for {form_info[0]} {form_info[1]}") |
|
|
|
else: |
|
|
|
mark_details = event_system.call_sync('get_mark_details', mark_id) |
|
|
|
self.logger.info(f"Mark for {form_info[0]} {form_info[1]} is {mark_details[0]} - {mark_details[1]}") |
|
|
|
event_system.emit_sync('assign_mark_to_form', (pfic, mark_id)) |
|
|
|
continue; |
|
|
|
|
|
|
|
def qt_message_handler(mode, context, message): |
|
|
|
print(f"Qt Message: {mode} {context} {message}") |
|
|
|
|