From a3b88d9fe4dcac110ba5e100ce7384fcd5fc52f2 Mon Sep 17 00:00:00 2001 From: Miguel Astor Date: Mon, 9 Feb 2026 16:57:14 -0400 Subject: [PATCH] Add total library count to report stats Show "Games in Library" stat alongside "Games Played" and "Total Playtime". Games with zero or null playtime are excluded from tables and charts but now counted in the library total. Co-Authored-By: Claude Opus 4.5 --- generate_report.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/generate_report.py b/generate_report.py index 4cf4495..ac46439 100644 --- a/generate_report.py +++ b/generate_report.py @@ -254,6 +254,10 @@ HTML_TEMPLATE = """
+
+
__TOTAL_LIBRARY__
+
Games in Library
+
0
Games Played
@@ -564,12 +568,16 @@ HTML_TEMPLATE = """ """ -def get_all_games(db_path: str) -> list[dict]: - """Query the database and return all games with playtime and categories.""" +def get_all_games(db_path: str) -> tuple[list[dict], int]: + """Query the database and return all games with playtime and categories, plus total library count.""" conn = sqlite3.connect(db_path) cursor = conn.cursor() - # Get games with playtime + # Get total games in library + cursor.execute("SELECT COUNT(*) FROM games") + total_library = cursor.fetchone()[0] + + # Get games with playtime > 0 cursor.execute(""" SELECT id, name, playtime, COALESCE(service, 'local') as service FROM games @@ -594,7 +602,7 @@ def get_all_games(db_path: str) -> list[dict]: game_categories[game_id] = [] game_categories[game_id].append(category) - return [ + games = [ { "name": row[1], "playtime": row[2], @@ -603,11 +611,12 @@ def get_all_games(db_path: str) -> list[dict]: } for row in games_rows ] + return games, total_library def generate_report(db_path: str, output_path: str, top_n: int, bg_image_path: str = None) -> None: """Generate the HTML report.""" - all_games = get_all_games(db_path) + all_games, total_library = get_all_games(db_path) if not all_games: print("No games with playtime found in the database.") @@ -625,10 +634,12 @@ def generate_report(db_path: str, output_path: str, top_n: int, bg_image_path: s html = HTML_TEMPLATE.replace("__ALL_GAMES__", json.dumps(all_games)) html = html.replace("__TOP_N__", str(top_n)) + html = html.replace("__TOTAL_LIBRARY__", str(total_library)) html = html.replace("__BACKGROUND_IMAGE__", bg_data_url) Path(output_path).write_text(html, encoding="utf-8") print(f"Report generated: {output_path}") + print(f"Total games in library: {total_library}") print(f"Total games with playtime: {total_games}") print(f"Total playtime: {total_playtime:.1f} hours")