Revert "added Time Requested to stats"

This reverts commit 38feb0d39e.
This commit is contained in:
Daan Sprenkels
2018-11-28 12:28:19 +01:00
parent 38feb0d39e
commit d827ec39d2
2 changed files with 2 additions and 53 deletions

View File

@ -66,34 +66,8 @@
</table> </table>
</div> </div>
</div> </div>
<div class="col-md-6">
<h2>Time Requested</h2>
<h4>Total: {{stats.total_time_requested}}</h4>
<h4>Top {{ stats.stats_top_count }}:</h4>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>User</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
{% for stat in stats.time_requested %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.user__name }}</td>
<td>{{ stat.duration }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="col-md-6"> <div class="col-md-6">
<h2>Unique requests</h2> <h2>Unique requests</h2>
<h4>Total: {{stats.total_unique_requests}}</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">

View File

@ -2,7 +2,7 @@ from datetime import datetime, timedelta
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
from django.shortcuts import render from django.shortcuts import render
from django.utils import timezone from django.utils import timezone
@ -16,11 +16,6 @@ def recache_stats():
caches['default'].set('stats', new_stats, 7200) caches['default'].set('stats', new_stats, 7200)
return new_stats return new_stats
def to_days(time):
for tr in time:
tr['duration'] = str(round(tr['total']/86400, 2)) + ' days'
return time
def compute_stats(): def compute_stats():
# We want to grab the time now, because otherwise we would be reporting a minute too late # We want to grab the time now, because otherwise we would be reporting a minute too late
@ -52,10 +47,6 @@ def compute_stats():
ratio=Count('song_id', distinct=True) / Count('id') * ratio=Count('song_id', distinct=True) / Count('id') *
100).order_by('-total')[:settings.STATS_TOP_COUNT] 100).order_by('-total')[:settings.STATS_TOP_COUNT]
total_unique_requests = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).distinct().count()
most_played_songs = PlaylistSong.objects.filter(state=2).exclude( most_played_songs = 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(
@ -70,18 +61,6 @@ 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]
time_requested = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values(
'user__id', 'user__name').annotate(total=Sum('song__duration')).order_by(
'-total')[:settings.STATS_TOP_COUNT]
total_time_requested = PlaylistSong.objects.all().filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).aggregate(
total=Sum('song__duration'))
return { return {
'last_updated': last_updated, 'last_updated': last_updated,
'total_uploads': total_uploads, 'total_uploads': total_uploads,
@ -89,11 +68,7 @@ def compute_stats():
'total_requests': total_requests, 'total_requests': total_requests,
'request_stats': list(request_stats), 'request_stats': list(request_stats),
'unique_request_stats': list(unique_request_stats), 'unique_request_stats': list(unique_request_stats),
'total_unique_requests': total_unique_requests,
'most_played_songs': list(most_played_songs), 'most_played_songs': list(most_played_songs),
'most_played_songs_14_days': list(most_played_songs_14_days), 'most_played_songs_14_days': list(most_played_songs_14_days),
'time_requested': to_days(list(time_requested)),
'total_time_requested': str(round(float(total_time_requested['total'])/86400, 2)) + ' days',
'stats_top_count': settings.STATS_TOP_COUNT, 'stats_top_count': settings.STATS_TOP_COUNT,
} }