diff --git a/.gitignore b/.gitignore index 3e77af2..ef25de4 100644 --- a/.gitignore +++ b/.gitignore @@ -161,3 +161,7 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + + +generated/ +output/ diff --git a/src/data/database.py b/src/data/database.py index be07fdd..e38e779 100644 --- a/src/data/database.py +++ b/src/data/database.py @@ -1,19 +1,17 @@ import datetime import json import os -from typing import Any, Dict, Optional, List, Tuple +from typing import Any, Dict, List, Optional from src.config import Config class NikkeDatabase: - def __init__(self) -> None: self.config: Config = Config() self.data_folder: str = str(self.config.USER_DATA_DIR) self.current_file: str = self._generate_new_filename() self.data: List[Dict[str, Any]] = [] - self.added_nikkes: int = 0 def _generate_new_filename(self) -> str: timestamp = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") @@ -30,15 +28,7 @@ def save_data(self) -> None: with open(self.current_file, "w") as f: json.dump(self.data, f, indent=4) - def add_or_update_character( - self, name: str, nikke_info: Dict[str, Any] - ) -> Tuple[bool, bool]: - # Validate combat_power - try: - combat_power = int(nikke_info.get("combat_power", "0")) - except ValueError: - combat_power = 0 - + def add_or_update_character(self, name: str, nikke_info: Dict[str, Any]) -> bool: simplified_info = { "name": name, "manufacturer": nikke_info.get("manufacturer"), @@ -48,33 +38,27 @@ def add_or_update_character( "rarity": nikke_info.get("rarity"), "weapon": nikke_info.get("weapon"), "element": nikke_info.get("element"), - "combat_power": str(combat_power), + "combat_power": nikke_info.get("combat_power"), "last_updated": str(datetime.datetime.now()), } - # Check if character already exists - for i, character in enumerate(self.data): - if character["name"] == name: - # Update existing character - self.data[i] = simplified_info - self.save_data() - return True, False # Updated, but not added + # Check if character already exists and update, otherwise append + for char in self.data: + if char["name"] == name: + char.update(simplified_info) + break + else: + self.data.append(simplified_info) - # If character doesn't exist, add new one - self.data.append(simplified_info) - self.added_nikkes += 1 self.save_data() - return True, True # Added new character + return True def get_character(self, name: str) -> Optional[Dict[str, Any]]: - for character in self.data: - if character["name"] == name: - return character + for char in self.data: + if char["name"] == name: + return char return None - def get_added_nikkes_count(self) -> int: - return self.added_nikkes - def get_all_characters(self) -> List[Dict[str, Any]]: return self.data diff --git a/src/gui/ui.py b/src/gui/ui.py index 049b6f8..e222556 100644 --- a/src/gui/ui.py +++ b/src/gui/ui.py @@ -56,7 +56,6 @@ def stop(self): class NikkeOCRUI(QMainWindow): - def __init__(self) -> None: super().__init__() self.config: Config = Config() @@ -67,6 +66,7 @@ def __init__(self) -> None: self.automation_active: bool = False self.first_nikke_name: Optional[str] = None + self.processed_nikkes: int = 0 self.current_step: int = 0 self.selected_rarities: List[str] = ["SSR", "SR", "R"] @@ -219,6 +219,7 @@ def _start_automation(self) -> None: self.automation_active = True self.current_step = 0 self.first_nikke_name = None + self.processed_nikkes = 0 self.status_label.setText(_("Status: Running (Press F1 to stop)")) self.log(_("Automation started. Performing click sequence...")) self._perform_automation() @@ -229,7 +230,7 @@ def _stop_automation(self) -> None: self.current_step = 0 self.status_label.setText(_("Status: Idle (Press F1 to start)")) self.log(_("Automation stopped and reset")) - self.log(f"Total new Nikkes added: {self.database.get_added_nikkes_count()}") + self.log(f"Total Nikkes processed: {self.processed_nikkes}") def _move_to_next_character(self) -> None: self.log(_("Clicking to move to next character.")) @@ -461,12 +462,8 @@ def _handle_character(self, nikke_info: Dict[str, Any]) -> None: name: str = nikke_info["name"] self.log(f"Identified Nikke: {name}") - success, added = self.database.add_or_update_character(name, nikke_info) - if success: - if added: - self.log(f"Added new Nikke to database: {name}") - else: - self.log(f"Updated existing Nikke in database: {name}") + if self.database.add_or_update_character(name, nikke_info): + self.log(f"Updated database for {name}") else: self.log(f"Failed to update database for {name}")