mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 19:52:20 +01:00
added average song length to stats
This commit is contained in:
@ -76,7 +76,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>User</th>
|
<th>User</th>
|
||||||
<th>Duration</th>
|
<th style="text-align: right;">Duration</th>
|
||||||
|
<th>Average</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -84,7 +85,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>{{ forloop.counter }}</th>
|
<th>{{ forloop.counter }}</th>
|
||||||
<td>{{ stat.user__name }}</td>
|
<td>{{ stat.user__name }}</td>
|
||||||
<td>{{ stat.duration }}</td>
|
<td style="text-align: right;">{{ stat.duration }}</td>
|
||||||
|
<td>{{stat.avg_dur}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@ -27,9 +27,12 @@ def recache_user_stats():
|
|||||||
caches['userstats'].set(cacheloc, new_stats, 48 * 3600)
|
caches['userstats'].set(cacheloc, new_stats, 48 * 3600)
|
||||||
return new_stats
|
return new_stats
|
||||||
|
|
||||||
def to_days(time):
|
def time_convert(time):
|
||||||
for tr in time:
|
for tr in time:
|
||||||
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
|
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
|
||||||
|
avg_dur_sec = tr['avg_dur']%60
|
||||||
|
avg_dur_min = int((tr['avg_dur']-avg_dur_sec)/60)
|
||||||
|
tr['avg_dur'] = '{}:{}'.format(avg_dur_min, avg_dur_sec)
|
||||||
return time
|
return time
|
||||||
|
|
||||||
def compute_stats():
|
def compute_stats():
|
||||||
@ -84,7 +87,7 @@ def compute_stats():
|
|||||||
time_requested = PlaylistSong.objects.filter(state=2).exclude(
|
time_requested = 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(
|
||||||
'user__id', 'user__name').annotate(total=Sum('song__duration')).order_by(
|
'user__id', 'user__name').annotate(total=Sum('song__duration'), avg_dur=Sum('song__duration')/Count('id')).order_by(
|
||||||
'-total')[:settings.STATS_TOP_COUNT]
|
'-total')[:settings.STATS_TOP_COUNT]
|
||||||
|
|
||||||
total_time_requested = PlaylistSong.objects.all().filter(state=2).exclude(
|
total_time_requested = PlaylistSong.objects.all().filter(state=2).exclude(
|
||||||
@ -108,7 +111,7 @@ def compute_stats():
|
|||||||
'total_unique_requests': total_unique_requests,
|
'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)),
|
'time_requested': time_convert(list(time_requested)),
|
||||||
'total_time_requested': str(round(float(total_time_requested['total']) / 86400, 2)) + ' days',
|
'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,
|
||||||
'most_requested_uploaders': list(most_requested_uploaders),
|
'most_requested_uploaders': list(most_requested_uploaders),
|
||||||
|
|||||||
Reference in New Issue
Block a user