From a864e8f535122f5538c7c535ca4ba9ee3df82c26 Mon Sep 17 00:00:00 2001 From: Olaf Slomp Date: Wed, 23 Oct 2019 20:13:12 +0200 Subject: [PATCH] Extra statistic: biggest fans --- marietje/stats/templates/stats/user.html | 27 +++++++++++++++++++++++- marietje/stats/utils.py | 9 ++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/marietje/stats/templates/stats/user.html b/marietje/stats/templates/stats/user.html index d1bdcb3..5c99762 100644 --- a/marietje/stats/templates/stats/user.html +++ b/marietje/stats/templates/stats/user.html @@ -107,7 +107,32 @@ +
+
+

Biggest fans

+

The people that queued your songs the most are:

+
+ + + + + + + + + + {% for stat in stats.biggest_fans %} + + + + + + {% endfor %} + +
#User# Requests
{{ forloop.counter }}{{ stat.user__name }}{{ stat.total }}
+
+
{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/marietje/stats/utils.py b/marietje/stats/utils.py index 61f26b1..fcfeb4a 100644 --- a/marietje/stats/utils.py +++ b/marietje/stats/utils.py @@ -203,6 +203,14 @@ def user_stats(request): total=Count('song__user__id')).order_by( '-total')[:settings.STATS_TOP_COUNT] + biggest_fans = PlaylistSong.objects.filter( + state=2, song_id__in=Song.objects.filter(user__id=request)).exclude( + Q(user_id=None) + | Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values( + 'user__id', 'user__name').annotate( + total=Count('user__id')).order_by( + '-total')[:settings.STATS_TOP_COUNT] + most_played_uploads = PlaylistSong.objects.filter( state=2, song_id__in=Song.objects.filter(user__id=request)).exclude( user__id=None).values('song__artist', 'song__title').annotate( @@ -230,4 +238,5 @@ def user_stats(request): 'stats_top_count': settings.STATS_TOP_COUNT, 'total_played_uploads': total_played_uploads, 'total_played_user_uploads': total_played_user_uploads, + 'biggest_fans': list(biggest_fans), }