From b94fd0856aa4b026b1310cc14351b376ced244fb Mon Sep 17 00:00:00 2001 From: ulna <220980518+ulnanlu@users.noreply.github.com> Date: Sun, 27 Sep 2026 13:01:08 +0200 Subject: [PATCH] fix: populate metrics charts on PostgreSQL --- database_metrics.py | 8 +++++--- templates/metrics.jinja | 2 +- tests/test_metrics.py | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/database_metrics.py b/database_metrics.py index 96251b1..d694ea8 100644 --- a/database_metrics.py +++ b/database_metrics.py @@ -44,7 +44,9 @@ def get_metrics(): """, ((today - timedelta(days=days - 1)).strftime("%Y-%m-%d"),), ) - user_counts = dict(user_rows) + # PostgreSQL returns DATE values as datetime.date objects, while SQLite + # returns strings. Normalize both so they match the string chart labels. + user_counts = {str(day): count for day, count in user_rows} metrics["users_per_day"] = [user_counts.get(date, 0) for date in date_labels] # Comparisons created per day @@ -56,7 +58,7 @@ def get_metrics(): """, ((today - timedelta(days=days - 1)).strftime("%Y-%m-%d"),), ) - comp_counts = dict(comp_rows) + comp_counts = {str(day): count for day, count in comp_rows} metrics["comparisons_per_day"] = [comp_counts.get(date, 0) for date in date_labels] # Images uploaded per day (by image_positions join comparisons for date) @@ -70,7 +72,7 @@ def get_metrics(): """, ((today - timedelta(days=days - 1)).strftime("%Y-%m-%d"),), ) - img_counts = dict(img_rows) + img_counts = {str(day): count for day, count in img_rows} metrics["images_per_day"] = [img_counts.get(date, 0) for date in date_labels] metrics["date_labels"] = date_labels diff --git a/templates/metrics.jinja b/templates/metrics.jinja index b86cb9f..8effbf6 100644 --- a/templates/metrics.jinja +++ b/templates/metrics.jinja @@ -112,7 +112,7 @@ - +