diff --git a/marietje/stats/templates/stats/stats.html b/marietje/stats/templates/stats/stats.html index bdaa8e6..38a26e7 100644 --- a/marietje/stats/templates/stats/stats.html +++ b/marietje/stats/templates/stats/stats.html @@ -72,7 +72,7 @@

Time requested

In total {{ stats.total_time_requested }} of music have been requested, with an average song length of {{ stats.total_average }}. - These are the {{ stats.stats_top_count }} people with the longest total time queued

+ These are the {{ stats.stats_top_count }} people with the longest total time queued.

@@ -148,11 +148,34 @@
+ +
+

Most played Artists

+

These are the {{ stats.stats_top_count }} most played artists ever.

+
+ + + + + + + + + + {% for stat in stats.most_played_artists %} + + + + + + {% endfor %} + +
#Artist# Requests
{{ forloop.counter }}{{ stat.song__artist }}{{ stat.total }}
+

Most played uploaders

-

The left column shows the {{ stats.stats_top_count }} people whose songs are requested most often by other people - people. The right column shows how many times that person has queued his own songs.

+

These are the {{ stats.stats_top_count }} people whose songs are requested most often by other people, as shown in the left column. The right column shows how many times that person has queued his own songs.

diff --git a/marietje/stats/templates/stats/user.html b/marietje/stats/templates/stats/user.html index 5c99762..4353d1e 100644 --- a/marietje/stats/templates/stats/user.html +++ b/marietje/stats/templates/stats/user.html @@ -48,7 +48,30 @@
-
+
+

Most played Artists

+

Top {{ stats.stats_top_count }}:

+
+ + + + + + + + + + {% for stat in stats.most_played_artists %} + + + + + + {% endfor %} + +
#Artist# Requests
{{ forloop.counter }}{{ stat.song__artist }}{{ stat.total }}
+
+

Uploads requested

You have uploaded a total of {{stats.total_uploads }} songs. The left column @@ -82,6 +105,34 @@

+
+

Upload artists requested

+

The left column shows how many times songs from artists uploaded by you have been requested by + other people. The right column shows how many times you requested those songs. +

Top {{ stats.stats_top_count }}:

+
+ + + + + + + + + + + {% for stat in stats.most_played_uploaded_artists %} + + + + + + + {% endfor %} + +
#ArtistOthersYou
{{ forloop.counter }}{{ stat.song__artist }}{{ stat.total }}{{ stat.user_total }}
+
+

Most played uploaders

The people whose songs you have queued the most are:

@@ -107,7 +158,6 @@
-

Biggest fans

The people that queued your songs the most are:

diff --git a/marietje/stats/utils.py b/marietje/stats/utils.py index 2be61fc..6a64354 100644 --- a/marietje/stats/utils.py +++ b/marietje/stats/utils.py @@ -106,6 +106,12 @@ def compute_stats(): 'song__title').annotate(total=Count('id')).order_by( '-total', 'song__artist')[:settings.STATS_TOP_COUNT] + stats['most_played_artists'] = PlaylistSong.objects.filter(state=2).exclude( + Q(user_id=None) + | Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values( + 'song__artist__id', 'song__artist__name').annotate(total=Count('song__artist__id')).order_by( + '-total', 'song__artist__name')[:settings.STATS_TOP_COUNT] + stats['most_played_songs_14_days'] = PlaylistSong.objects.filter( state=2, played_at__gte=timezone.now() - timedelta(days=14)).exclude(user_id=None).values( @@ -197,6 +203,12 @@ def user_stats(request): '-total', 'song__artist', 'song__title')[:settings.STATS_TOP_COUNT] + most_played_artists = PlaylistSong.objects.filter( + user__id=request, state=2, + song_id__isnull=False).values('song__artist').annotate( + total=Count('song__artist')).order_by( + '-total', 'song__artist')[:settings.STATS_TOP_COUNT] + most_played_uploaders = PlaylistSong.objects.filter( user__id=request, state=2).exclude( Q(user_id=None) @@ -218,27 +230,37 @@ def user_stats(request): user__id=None).values('song__artist', 'song__title').annotate( total=Count('id', filter=~Q(user__id=request)), user_total=Count('id', filter=Q(user__id=request))).order_by( - '-total', 'song__artist', - 'song__title') + '-total', 'song__artist', 'song__title') + + most_played_uploaded_artists = PlaylistSong.objects.filter( + state=2, song_id__in=Song.objects.filter(user__id=request)).exclude( + user__id=None).values('song__artist').annotate(total=Count( + 'song__artist', filter=~Q(user__id=request)), user_total=Count( + 'id', filter=Q(user__id=request))).order_by( + '-total', 'song__artist') most_played = list(most_played_uploads) - total_played_uploads = 0 - total_played_user_uploads = 0 + total_played = {} + total_played['uploads'] = 0 + total_played['user_uploads'] = 0 for x in most_played: - total_played_uploads += x['total'] - total_played_user_uploads += x['user_total'] + total_played['uploads'] += x['total'] + total_played['user_uploads'] += x['user_total'] most_played_uploads_list = sorted(most_played_uploads, key=lambda x: (x['song__artist'], x['song__title'])) most_played_uploads_list = sorted(most_played_uploads_list, key=lambda x: x["total"], reverse=True)[:settings.STATS_TOP_COUNT] + most_played_uploaded_artists = sorted(list(most_played_uploaded_artists), key=lambda x: x["total"], reverse=True)[:settings.STATS_TOP_COUNT] return { 'last_updated': last_updated, 'total_uploads': total_uploads, 'total_requests': total_requests, 'unique_requests': unique_requests, 'most_played_songs': list(most_played_songs), + 'most_played_artists': list(most_played_artists), 'most_played_uploaders': list(most_played_uploaders), 'most_played_uploads': most_played_uploads_list, + 'most_played_uploaded_artists': most_played_uploaded_artists, 'stats_top_count': settings.STATS_TOP_COUNT, - 'total_played_uploads': total_played_uploads, - 'total_played_user_uploads': total_played_user_uploads, + 'total_played_uploads': total_played['uploads'], + 'total_played_user_uploads': total_played['user_uploads'], 'biggest_fans': list(biggest_fans), }