From 84303689115072ca2280dae56203825146cf364c Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 3 Oct 2024 15:11:38 +0100 Subject: [PATCH] - Working prototype --- .gitignore | 1 + Utilities/DatabaseBuilder.py | 22 +- Utilities/DetermineOriginGame.py | 72 +- Utilities/requirements.txt | Bin 268 -> 304 bytes pokemon_earliest_games.csv | 1306 ++++++++++++++++++++++++++++++ 5 files changed, 1369 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index fa1449e..d4f2c03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ pokemon_cache.db pokemon_database.db Utilities/venv/ +venv/ \ No newline at end of file diff --git a/Utilities/DatabaseBuilder.py b/Utilities/DatabaseBuilder.py index fc48549..e95a4ac 100644 --- a/Utilities/DatabaseBuilder.py +++ b/Utilities/DatabaseBuilder.py @@ -123,6 +123,11 @@ def tidy_location_name(name): name = name[:-len(direction)].strip() name += f' ({direction.capitalize()})' break + + if name.isdigit(): + name = "Route " + name + + name = name.replace("Routes", "Route") return name @@ -167,11 +172,17 @@ def load_game_data(conn): ("Let's Go Eevee", 7, ["Let's Go, Eevee!", "Lets Go Eevee"]), ("Sword", 8, ["Sword Version"]), ("Shield", 8, ["Shield Version"]), + ("Expansion Pass", 8, ["Expansion Pass (Sword)", "Expansion Pass (Shield)"]), ("Brilliant Diamond", 8, ["Brilliant Diamond Version", "Brilliant-Diamond"]), ("Shining Pearl", 8, ["Shining Pearl Version", "Shining-Pearl"]), ("Legends Arceus", 8, ["Legends: Arceus", "Legends-Arceus"]), ("Scarlet", 9, ["Scarlet Version"]), ("Violet", 9, ["Violet Version"]), + ("The Teal Mask", 9, ["The Teal Mask Version", "The Teal Mask (Scarlet)", "The Teal Mask (Violet)"]), + ("The Hidden Treasure of Area Zero", 9, ["The Hidden Treasure of Area Zero Version", "The Hidden Treasure of Area Zero (Scarlet)", "The Hidden Treasure of Area Zero (Violet)"]), + + ("Pokémon Home", 98, ["Pokémon HOME"]), + ("Pokémon Go", 99, ["Pokémon GO"]), ] for game in games: @@ -278,6 +289,8 @@ def load_encounter_data(conn): if match: base_name = match.group(1).strip() form_name = match.group(2).strip() if match.group(2) else "Default" + if form_name == "None": + form_name = "Default" else: base_name = full_name form_name = "Default" @@ -341,8 +354,9 @@ def load_encounter_data(conn): elif encounter_locations != "N/A" and encounter_locations: # Process each encounter location for location_info in encounter_locations.split('|'): - location, method = location_info.strip().rsplit(' ', 1) - method = method.strip('()') + location = location_info.strip() + + location = tidy_location_name(location) # Tidy up the location name and generate a description description = tidy_location_name(location) @@ -356,8 +370,8 @@ def load_encounter_data(conn): location_id = cursor.fetchone()[0] # Insert or get encounter_method_id - cursor.execute('INSERT OR IGNORE INTO encounter_methods (name) VALUES (?)', (method,)) - cursor.execute('SELECT id FROM encounter_methods WHERE name = ?', (method,)) + cursor.execute('INSERT OR IGNORE INTO encounter_methods (name) VALUES (?)', (obtain_method,)) + cursor.execute('SELECT id FROM encounter_methods WHERE name = ?', (obtain_method,)) method_id = cursor.fetchone()[0] # Insert form_encounter diff --git a/Utilities/DetermineOriginGame.py b/Utilities/DetermineOriginGame.py index 200cc29..d34c61f 100644 --- a/Utilities/DetermineOriginGame.py +++ b/Utilities/DetermineOriginGame.py @@ -40,7 +40,9 @@ all_games = [ "Brilliant Diamond", "Shining Pearl", "Legends: Arceus", "Scarlet", "Violet", "The Teal Mask", "The Hidden Treasure of Area Zero", "The Hidden Treasure of Area Zero (Scarlet)", "The Hidden Treasure of Area Zero (Violet)", "The Teal Mask (Scarlet)", "The Teal Mask (Violet)", - "Unknown" + "Unknown", + "Pokémon Home", + "Pokémon Go", ] big_pokemon_list = [] @@ -163,14 +165,18 @@ class Pokemon: self.stage = stage self.is_baby = self.stage is not None and 'Baby' in self.stage - def update_encounter_information(self, exclude_events=True): + def update_encounter_information(self, exclude_events=True, exclude_home=True, exclude_go=True): if not self.encounter_information: return - non_catchable_methods = ["trade", "global link", "poké transfer", "time capsule", "unobtainable", "pokémon home"] + non_catchable_methods = ["trade", "global link", "poké transfer", "time capsule", "unobtainable"] if exclude_events: non_catchable_methods.append("event") + if exclude_home: + non_catchable_methods.append("pokemon home") + if exclude_go: + non_catchable_methods.append("pokémon go") for encounter in self.encounter_information: encounter.method = None @@ -195,13 +201,7 @@ class Pokemon: else: encounter.method = "Catchable" - def determine_earliest_game(self): - if not self.encounter_information: - self.earliest_game = None - return - - self.update_encounter_information() - + def parse_encoutners_for_games(self): game_methods = {} for encounter in self.encounter_information: if encounter.method: @@ -211,18 +211,32 @@ class Pokemon: if game.lower() in game_methods: self.earliest_game = game_methods[game.lower()] return - - self.update_encounter_information(exclude_events=False) - game_methods = {} - for encounter in self.encounter_information: - if encounter.method: - game_methods[encounter.game.lower()] = encounter + def determine_earliest_game(self): + if not self.encounter_information: + self.earliest_game = None + return + + self.update_encounter_information() + self.parse_encoutners_for_games() + if self.earliest_game != None: + return + - for game in all_games: - if game.lower() in game_methods: - self.earliest_game = game_methods[game.lower()] - return + self.update_encounter_information(exclude_events=False) + self.parse_encoutners_for_games() + if self.earliest_game != None: + return + + self.update_encounter_information(exclude_home=False) + self.parse_encoutners_for_games() + if self.earliest_game != None: + return + + self.update_encounter_information(exclude_go=False) + self.parse_encoutners_for_games() + if self.earliest_game != None: + return self.earliest_game = None @@ -908,7 +922,9 @@ def determine_earliest_games(pokemon_list, cache): handle_unown(pokemon, encounter_data) handle_form_shift(pokemon, encounter_data) if pokemon.name == "Gimmighoul" and pokemon.form == "Roaming Form": - continue + encounter_information = EncounterInformation("Pokémon Go", ["Pokémon Go"]) + pokemon.encounter_information.append(encounter_information) + pokemon.determine_earliest_game() print(f"Processed {pokemon}: {pokemon.earliest_game.game} ({pokemon.earliest_game.method})") @@ -1034,14 +1050,14 @@ def save_to_csv(pokemon_list, filename='pokemon_earliest_games.csv'): for pokemon in big_pokemon_list: encounter_locations = [] for encounter in pokemon.encounter_information: - if encounter.game == pokemon.earliest_game and encounter.method == pokemon.obtain_method: - encounter_locations.append(encounter.locations) + if encounter.game == pokemon.earliest_game.game: + encounter_locations.extend(encounter.locations) writer.writerow({ 'number': pokemon.number, - 'name': pokemon.name, - 'earliest_game': pokemon.earliest_game, - 'obtain_method': pokemon.obtain_method, - 'encounter_locations': ' | '.join(str(item) for item in encounter_locations) + 'name': f"{pokemon.name} ({pokemon.form})", + 'earliest_game': pokemon.earliest_game.game, + 'obtain_method': pokemon.earliest_game.method, + 'encounter_locations': ' | '.join((str(item) for item in encounter_locations)) }) def parse_encounter_locations(encounter_data, game): @@ -1151,7 +1167,7 @@ def check_alternative_sources(pokemon, cache): def handle_unknown_encounters(pokemon_list, cache): for pokemon in big_pokemon_list: - if pokemon.earliest_game == None or pokemon.obtain_method == None: + if pokemon.earliest_game == None or pokemon.earliest_game.method == None: print(f"Checking alternative sources for {pokemon.name}") return diff --git a/Utilities/requirements.txt b/Utilities/requirements.txt index 9b9b53b50f1adc876f74eb9f3455d9a4d2b23eea..594a5072b610123b47815f4b1eb89caf029053b5 100644 GIT binary patch delta 44 pcmeBS+Q77dhfyVsp_HKt2rC)N;VfGQTLuFLJqAMt3m|F00086C2x0&L delta 7 OcmdnM)WfuahY