From 56e69b1cc5cfb8cf499617128f7d12b27a534716 Mon Sep 17 00:00:00 2001 From: Daan Sprenkels Date: Sat, 18 Aug 2018 22:32:46 +0200 Subject: [PATCH] Fix duplicate name bug on stats page --- marietje/stats/utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/marietje/stats/utils.py b/marietje/stats/utils.py index cf91340..b9b8582 100644 --- a/marietje/stats/utils.py +++ b/marietje/stats/utils.py @@ -16,6 +16,7 @@ def recache_stats(): caches['default'].set('stats', new_stats, 7200) return new_stats + def compute_stats(): # We want to grab the time now, because otherwise we would be reporting a minute too late last_updated = datetime.now() @@ -23,9 +24,9 @@ def compute_stats(): total_uploads = Song.objects.filter(deleted=False).exclude( user_id=None).count() - upload_stats = Song.objects.filter( - deleted=False).exclude(user_id=None).values('user__name').annotate( - total=Count('id')).order_by( + upload_stats = Song.objects.filter(deleted=False).exclude( + user_id=None).values( + 'user__id', 'user__name').annotate(total=Count('id')).order_by( '-total', 'user__name')[:settings.STATS_TOP_COUNT] total_requests = PlaylistSong.objects.filter(state=2).exclude( @@ -35,13 +36,13 @@ def compute_stats(): request_stats = PlaylistSong.objects.filter(state=2).exclude( Q(user_id=None) | Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values( - 'user__name').annotate(total=Count('id')).order_by( + 'user__id', 'user__name').annotate(total=Count('id')).order_by( '-total', 'user__name')[:settings.STATS_TOP_COUNT] unique_request_stats = PlaylistSong.objects.filter(state=2).exclude( Q(user_id=None) | Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values( - 'user__name', 'user__name').annotate( + 'user__id', 'user__name').annotate( total=Count('song_id', distinct=True), ratio=Count('song_id', distinct=True) / Count('id') * 100).order_by('-total')[:settings.STATS_TOP_COUNT]