Skip to content

Commit

Permalink
chore:Refactor .gitignore and database module, and update ui.py in sr…
Browse files Browse the repository at this point in the history
…c/gui
  • Loading branch information
valentin-marquez committed Oct 16, 2024
1 parent 02de65f commit 09bdaaa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
44 changes: 14 additions & 30 deletions src/data/database.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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"),
Expand All @@ -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

Expand Down
13 changes: 5 additions & 8 deletions src/gui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def stop(self):


class NikkeOCRUI(QMainWindow):

def __init__(self) -> None:
super().__init__()
self.config: Config = Config()
Expand All @@ -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"]

Expand Down Expand Up @@ -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()
Expand All @@ -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."))
Expand Down Expand Up @@ -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}")

Expand Down

0 comments on commit 09bdaaa

Please sign in to comment.