Split Uploads Requested in two columns, for others and for you personally

This commit is contained in:
oslomp
2018-12-15 15:19:47 +01:00
parent 1da2f4cc05
commit 2e9be85cc4
2 changed files with 13 additions and 6 deletions

View File

@ -50,8 +50,9 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<h2>Uploads requested by others</h2> <h2>Uploads requested</h2>
<h4>Total: {{stats.total_played_uploads}}</h4> <h4>Total played by you: {{stats.total_played_user_uploads}}</h4>
<h4>Total played by others: {{stats.total_played_uploads}}</h4>
<h4>Top {{ stats.stats_top_count }}:</h4> <h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
@ -60,7 +61,8 @@
<th>#</th> <th>#</th>
<th>Artist</th> <th>Artist</th>
<th>Title</th> <th>Title</th>
<th># Requests</th> <th>Others</th>
<th>You</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -70,6 +72,7 @@
<td>{{ stat.song__artist }}</td> <td>{{ stat.song__artist }}</td>
<td>{{ stat.song__title }}</td> <td>{{ stat.song__title }}</td>
<td>{{ stat.total }}</td> <td>{{ stat.total }}</td>
<td>{{ stat.user_total }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -2,7 +2,7 @@ from datetime import datetime, timedelta, time
from django.core.cache import caches from django.core.cache import caches
from django.conf import settings from django.conf import settings
from django.db.models import Count, Q, Sum from django.db.models import Count, Q, Sum, When, Case
from django.shortcuts import render from django.shortcuts import render
from django.utils import timezone from django.utils import timezone
@ -145,15 +145,18 @@ def user_stats(request):
'-total')[:settings.STATS_TOP_COUNT] '-total')[:settings.STATS_TOP_COUNT]
most_played_uploads = PlaylistSong.objects.filter( most_played_uploads = PlaylistSong.objects.filter(
state=2, song_id__in=Song.objects.filter(user__id=request)).exclude(Q(user__id=None)|Q(user__id=request)).values( state=2, song_id__in=Song.objects.filter(user__id=request)).exclude(user__id=None).values(
'song__artist', 'song__artist',
'song__title').annotate(total=Count('id')).order_by( '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', '-total', 'song__artist',
'song__title')[:settings.STATS_TOP_COUNT] 'song__title')[:settings.STATS_TOP_COUNT]
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
for x in most_played: for x in most_played:
total_played_uploads += x['total'] total_played_uploads += x['total']
total_played_user_uploads += x['user_total']
return { return {
'last_updated': last_updated, 'last_updated': last_updated,
@ -165,5 +168,6 @@ def user_stats(request):
'most_played_uploads': list(most_played_uploads), 'most_played_uploads': list(most_played_uploads),
'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,
} }