added window with the database statistics
This commit is contained in:
parent
1dd69955d4
commit
540b5a3194
27
backend.py
27
backend.py
@ -219,3 +219,30 @@ class AnimeBackend:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error deleting year {year}: {e}")
|
logging.error(f"Error deleting year {year}: {e}")
|
||||||
self.db.rollback()
|
self.db.rollback()
|
||||||
|
|
||||||
|
def get_total_entries(self):
|
||||||
|
try:
|
||||||
|
cursor = self.db.cursor()
|
||||||
|
cursor.execute("SELECT COUNT(*) FROM anime")
|
||||||
|
return cursor.fetchone()[0]
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Error getting total entries: {e}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_completed_entries(self):
|
||||||
|
try:
|
||||||
|
cursor = self.db.cursor()
|
||||||
|
cursor.execute("SELECT COUNT(*) FROM anime WHERE status = 'completed'")
|
||||||
|
return cursor.fetchone()[0]
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Error getting completed entries: {e}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_entries_by_type(self):
|
||||||
|
try:
|
||||||
|
cursor = self.db.cursor()
|
||||||
|
cursor.execute("SELECT type, COUNT(*) FROM anime GROUP BY type ORDER BY 2 DESC")
|
||||||
|
return cursor.fetchall() # Returns list of tuples: (type, count)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Error getting entries by type: {e}")
|
||||||
|
return []
|
38
frontend.py
38
frontend.py
@ -221,6 +221,9 @@ class AnimeTracker(QMainWindow):
|
|||||||
random_act = QAction('Random Pick', self)
|
random_act = QAction('Random Pick', self)
|
||||||
random_act.triggered.connect(self.random_pick)
|
random_act.triggered.connect(self.random_pick)
|
||||||
tools_menu.addAction(random_act)
|
tools_menu.addAction(random_act)
|
||||||
|
statistics_act = QAction('Statistics', self)
|
||||||
|
statistics_act.triggered.connect(self.show_statistics)
|
||||||
|
tools_menu.addAction(statistics_act)
|
||||||
help_menu = menubar.addMenu('Help')
|
help_menu = menubar.addMenu('Help')
|
||||||
shortcuts_act = QAction('Shortcuts', self)
|
shortcuts_act = QAction('Shortcuts', self)
|
||||||
shortcuts_act.triggered.connect(self.show_shortcuts)
|
shortcuts_act.triggered.connect(self.show_shortcuts)
|
||||||
@ -713,6 +716,41 @@ class AnimeTracker(QMainWindow):
|
|||||||
else:
|
else:
|
||||||
QMessageBox.information(self, "Random Pick", "No unwatched anime in this tab.")
|
QMessageBox.information(self, "Random Pick", "No unwatched anime in this tab.")
|
||||||
|
|
||||||
|
def show_statistics(self):
|
||||||
|
dialog = QDialog(self)
|
||||||
|
dialog.setWindowTitle("Anime Statistics")
|
||||||
|
layout = QVBoxLayout(dialog)
|
||||||
|
|
||||||
|
total = self.backend.get_total_entries()
|
||||||
|
completed = self.backend.get_completed_entries()
|
||||||
|
percentage = (completed / total * 100) if total > 0 else 0
|
||||||
|
|
||||||
|
layout.addWidget(QLabel(f"Total anime entries: <b>{total}</b>"))
|
||||||
|
layout.addWidget(QLabel(f"Total completed entries: <b>{completed}</b>"))
|
||||||
|
layout.addWidget(QLabel(f"Percentage of completed entries: <b>{percentage:.2f}%</b>"))
|
||||||
|
|
||||||
|
layout.addWidget(QLabel("Number of anime entries by type:"))
|
||||||
|
types_data = self.backend.get_entries_by_type()
|
||||||
|
if types_data:
|
||||||
|
for typ, count in types_data:
|
||||||
|
display_type = typ if typ else "None" # Handle empty type as 'None'
|
||||||
|
layout.addWidget(QLabel(f" {display_type}: <b>{count}</b>"))
|
||||||
|
else:
|
||||||
|
layout.addWidget(QLabel(" No data available"))
|
||||||
|
|
||||||
|
db_path = 'anime_backlog.db'
|
||||||
|
if os.path.exists(db_path):
|
||||||
|
db_size_kb = os.path.getsize(db_path) / 1024
|
||||||
|
layout.addWidget(QLabel(f"Size of the database: <b>{db_size_kb:.2f} Kb</b>"))
|
||||||
|
else:
|
||||||
|
layout.addWidget(QLabel("Size of the database: N/A (database file not found)"))
|
||||||
|
|
||||||
|
buttons = QDialogButtonBox(QDialogButtonBox.Ok)
|
||||||
|
buttons.accepted.connect(dialog.accept)
|
||||||
|
layout.addWidget(buttons)
|
||||||
|
|
||||||
|
dialog.exec_()
|
||||||
|
|
||||||
def import_csv(self):
|
def import_csv(self):
|
||||||
file_name, _ = QFileDialog.getOpenFileName(self, "Import CSV", "", "CSV Files (*.csv)")
|
file_name, _ = QFileDialog.getOpenFileName(self, "Import CSV", "", "CSV Files (*.csv)")
|
||||||
if file_name:
|
if file_name:
|
||||||
|
Loading…
Reference in New Issue
Block a user