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 <noreply@anthropic.com>
This commit is contained in:
Miguel Astor
2026-02-09 16:57:14 -04:00
parent a21e3f3d07
commit a3b88d9fe4

View File

@@ -254,6 +254,10 @@ HTML_TEMPLATE = """<!DOCTYPE html>
<div class="card">
<div class="stats">
<div class="stat">
<div class="stat-value" id="total-library">__TOTAL_LIBRARY__</div>
<div class="stat-label">Games in Library</div>
</div>
<div class="stat">
<div class="stat-value" id="total-games">0</div>
<div class="stat-label">Games Played</div>
@@ -564,12 +568,16 @@ HTML_TEMPLATE = """<!DOCTYPE html>
"""
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")