Fix duplicate name bug on stats page

This commit is contained in:
Daan Sprenkels
2018-08-18 22:32:46 +02:00
parent 8488023710
commit 56e69b1cc5

View File

@ -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]