Added artist-specific stats

This commit is contained in:
Olaf Slomp
2020-03-28 12:53:26 +01:00
parent af6031c3a5
commit 8b437310ab
3 changed files with 101 additions and 2 deletions

View File

@ -148,6 +148,30 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
<div class="col-md-6">
<h2>Most played Artists</h2>
<p>These are the {{ stats.stats_top_count }} most played artists ever.</p>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Artist</th>
<th style="text-align: right;"># Requests</th>
</tr>
</thead>
<tbody>
{% for stat in stats.most_played_artists %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.song__artist }}</td>
<td style="text-align: right;">{{ stat.total }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<h2>Most played uploaders</h2> <h2>Most played uploaders</h2>

View File

@ -48,7 +48,30 @@
</table> </table>
</div> </div>
</div> </div>
<div class="row"> <div class="col-md-6">
<h2>Most played Artists</h2>
<h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Artist</th>
<th style="text-align: right;"># Requests</th>
</tr>
</thead>
<tbody>
{% for stat in stats.most_played_artists %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.song__artist }}</td>
<td style="text-align: right;">{{ stat.total }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="col-md-6"> <div class="col-md-6">
<h2>Uploads requested</h2> <h2>Uploads requested</h2>
<p> You have uploaded a total of <strong> {{stats.total_uploads }} </strong> songs. The left column <p> You have uploaded a total of <strong> {{stats.total_uploads }} </strong> songs. The left column
@ -82,6 +105,34 @@
</table> </table>
</div> </div>
</div> </div>
<div class="col-md-6">
<h2>Upload artists requested</h2>
<p> 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.
<h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Artist</th>
<th style="text-align: right;">Others</th>
<th>You</th>
</tr>
</thead>
<tbody>
{% for stat in stats.most_played_uploaded_artists %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.song__artist }}</td>
<td style="text-align: right;">{{ stat.total }}</td>
<td>{{ stat.user_total }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="col-md-6"> <div class="col-md-6">
<h2>Most played uploaders</h2> <h2>Most played uploaders</h2>
<p> The people whose songs you have queued the most are:</p> <p> The people whose songs you have queued the most are:</p>
@ -107,7 +158,6 @@
</table> </table>
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-6"> <div class="col-md-6">
<h2>Biggest fans</h2> <h2>Biggest fans</h2>
<p> The people that queued your songs the most are:</p> <p> The people that queued your songs the most are:</p>

View File

@ -80,6 +80,7 @@ def compute_stats():
Q(user_id=None) Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).count() | Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).count()
stats['request_stats'] = PlaylistSong.objects.filter(state=2).exclude( stats['request_stats'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None) Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values( | Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values(
@ -106,6 +107,12 @@ def compute_stats():
'song__title').annotate(total=Count('id')).order_by( 'song__title').annotate(total=Count('id')).order_by(
'-total', 'song__artist')[:settings.STATS_TOP_COUNT] '-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( stats['most_played_songs_14_days'] = PlaylistSong.objects.filter(
state=2, played_at__gte=timezone.now() - state=2, played_at__gte=timezone.now() -
timedelta(days=14)).exclude(user_id=None).values( timedelta(days=14)).exclude(user_id=None).values(
@ -164,6 +171,7 @@ def compute_stats():
'request_stats': list(stats['request_stats']), 'request_stats': list(stats['request_stats']),
'unique_request_stats': list(stats['unique_request_stats']), 'unique_request_stats': list(stats['unique_request_stats']),
'total_unique_requests': "{0:,.0f}".format(stats['total_unique_requests']['total']), 'total_unique_requests': "{0:,.0f}".format(stats['total_unique_requests']['total']),
'total_unique_artists': "{0:,.0f}".format(stats['total_unique_artists']['total']),
'most_played_songs': list(stats['most_played_songs']), 'most_played_songs': list(stats['most_played_songs']),
'most_played_songs_14_days': list(stats['most_played_songs_14_days']), 'most_played_songs_14_days': list(stats['most_played_songs_14_days']),
'time_requested': stats['time_requested'], 'time_requested': stats['time_requested'],
@ -197,6 +205,12 @@ def user_stats(request):
'-total', 'song__artist', '-total', 'song__artist',
'song__title')[:settings.STATS_TOP_COUNT] '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( most_played_uploaders = PlaylistSong.objects.filter(
user__id=request, state=2).exclude( user__id=request, state=2).exclude(
Q(user_id=None) Q(user_id=None)
@ -221,6 +235,13 @@ def user_stats(request):
'-total', 'song__artist', '-total', 'song__artist',
'song__title') '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) most_played = list(most_played_uploads)
total_played_uploads = 0 total_played_uploads = 0
total_played_user_uploads = 0 total_played_user_uploads = 0
@ -229,14 +250,18 @@ def user_stats(request):
total_played_user_uploads += x['user_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, 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_uploads_list = sorted(most_played_uploads_list, key=lambda x: x["total"], reverse=True)[:settings.STATS_TOP_COUNT]
most_played_uploaded_artists = list(most_played_uploaded_artists)
most_played_uploaded_artists_list = sorted(most_played_uploaded_artists, key=lambda x: x["total"], reverse=True)[:settings.STATS_TOP_COUNT]
return { return {
'last_updated': last_updated, 'last_updated': last_updated,
'total_uploads': total_uploads, 'total_uploads': total_uploads,
'total_requests': total_requests, 'total_requests': total_requests,
'unique_requests': unique_requests, 'unique_requests': unique_requests,
'most_played_songs': list(most_played_songs), 'most_played_songs': list(most_played_songs),
'most_played_artists': list(most_played_artists),
'most_played_uploaders': list(most_played_uploaders), 'most_played_uploaders': list(most_played_uploaders),
'most_played_uploads': most_played_uploads_list, 'most_played_uploads': most_played_uploads_list,
'most_played_uploaded_artists': most_played_uploaded_artists_list,
'stats_top_count': settings.STATS_TOP_COUNT, 'stats_top_count': settings.STATS_TOP_COUNT,
'total_played_uploads': total_played_uploads, 'total_played_uploads': total_played_uploads,
'total_played_user_uploads': total_played_user_uploads, 'total_played_user_uploads': total_played_user_uploads,