From 19cdda372c3b82d38444a5f14efb0874344b483d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 11 Sep 2021 07:09:05 -0700 Subject: [PATCH] Tidies up charts --- bookwyrm/templates/settings/dashboard.html | 59 +------------------ .../settings/dashboard_status_chart.html | 26 ++++++++ .../settings/dashboard_user_chart.html | 29 +++++++++ bookwyrm/views/admin/dashboard.py | 37 ++++++------ 4 files changed, 76 insertions(+), 75 deletions(-) create mode 100644 bookwyrm/templates/settings/dashboard_status_chart.html create mode 100644 bookwyrm/templates/settings/dashboard_user_chart.html diff --git a/bookwyrm/templates/settings/dashboard.html b/bookwyrm/templates/settings/dashboard.html index e8c77602..81ed28f8 100644 --- a/bookwyrm/templates/settings/dashboard.html +++ b/bookwyrm/templates/settings/dashboard.html @@ -77,63 +77,10 @@ - - - - {% endblock %} {% block scripts %} - + +{% include 'settings/dashboard_user_chart.html' %} +{% include 'settings/dashboard_status_chart.html' %} {% endblock %} diff --git a/bookwyrm/templates/settings/dashboard_status_chart.html b/bookwyrm/templates/settings/dashboard_status_chart.html new file mode 100644 index 00000000..bbacf3f4 --- /dev/null +++ b/bookwyrm/templates/settings/dashboard_status_chart.html @@ -0,0 +1,26 @@ +{% load i18n %} + + diff --git a/bookwyrm/templates/settings/dashboard_user_chart.html b/bookwyrm/templates/settings/dashboard_user_chart.html new file mode 100644 index 00000000..33be28f7 --- /dev/null +++ b/bookwyrm/templates/settings/dashboard_user_chart.html @@ -0,0 +1,29 @@ +{% load i18n %} + diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index 2ad7718a..2d7e8bdb 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -30,34 +30,33 @@ class Dashboard(View): user_stats = {"labels": [], "total": [], "active": []} interval_end = now - timedelta(days=buckets * bucket_size) while interval_end < timezone.now(): - user_stats["total"].append(user_queryset.filter( - created_date__lte=interval_end - ).count()) - user_stats["active"].append(user_queryset.filter( - local=True, - is_active=True, - last_active_date__gte=interval_end - timedelta(days=31), - created_date__lte=interval_end - ).count()) - user_stats["labels"].append(interval_end.strftime("%Y-%m-%d")) + user_stats["total"].append( + user_queryset.filter(created_date__day__lte=interval_end.day).count() + ) + user_stats["active"].append( + user_queryset.filter( + last_active_date__gt=interval_end - timedelta(days=31), + created_date__day__lte=interval_end.day, + ).count() + ) + user_stats["labels"].append(interval_end.strftime("%b %d")) interval_end += timedelta(days=bucket_size) - status_queryset = models.Status.objects.filter( - user__local=True, deleted=False - ) + status_queryset = models.Status.objects.filter(user__local=True, deleted=False) status_stats = {"labels": [], "total": []} interval_start = now - timedelta(days=buckets * bucket_size) interval_end = interval_start + timedelta(days=bucket_size) while interval_end < timezone.now(): - status_stats["total"].append(status_queryset.filter( - created_date__gte=interval_start, - created_date__lte=interval_end, - ).count()) - status_stats["labels"].append(interval_start.strftime("%Y-%m-%d")) + status_stats["total"].append( + status_queryset.filter( + created_date__day__gt=interval_start.day, + created_date__day__lte=interval_end.day, + ).count() + ) + status_stats["labels"].append(interval_end.strftime("%b %d")) interval_start = interval_end interval_end += timedelta(days=bucket_size) - data = { "users": user_queryset.count(), "active_users": user_queryset.filter(