Oslomp/stats bugfixes

This commit is contained in:
Olaf Slomp
2019-02-28 10:45:01 +01:00
committed by Gerdriaan Mulder
parent 409c5b2930
commit 3f263ae429
4 changed files with 27 additions and 22 deletions

View File

@ -56,7 +56,6 @@ $(function () {
return false
}
$.post('/api/report', {id: songId, msg: message, csrfmiddlewaretoken: csrf_token}, function (result) {
console.log(result);
if (result.success) {
createAlert('success', 'Thanks for your song report!');
}
@ -209,6 +208,7 @@ function renderQueue(playNextAt, now)
} else {
var requestNext = !((queue[id+1].requested_by === 'Marietje') && (requestedBy !== 'Marietje'))
}
//checks if id is the first item and returns false if the previous song is not Marietje, while the current song is.
if(id === 0){
var requestPrev = false

View File

@ -26,7 +26,7 @@
<tr>
<th>#</th>
<th>User</th>
<th># Songs</th>
<th style="text-align: right;"># Songs</th>
</tr>
</thead>
<tbody>
@ -34,7 +34,8 @@
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.user__name }}</td>
<td>{{ stat.total }} ({% widthratio stat.total stats.total_uploads 100 %}%)</td>
<td style="text-align: right;">{{ stat.total }}</td>
<td>({% widthratio stat.total stats.total_uploads 100 %}%)</td>
</tr>
{% endfor %}
</tbody>
@ -51,7 +52,7 @@
<tr>
<th>#</th>
<th>User</th>
<th># Requests</th>
<th style="text-align: right;"># Requests</th>
</tr>
</thead>
<tbody>
@ -59,7 +60,8 @@
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.user__name }}</td>
<td>{{ stat.total }} ({% widthratio stat.total stats.total_requests 100 %}%)</td>
<td style="text-align: right;">{{ stat.total }}</td>
<td>({% widthratio stat.total stats.total_requests 100 %}%)</td>
</tr>
{% endfor %}
</tbody>
@ -105,7 +107,7 @@
<tr>
<th>#</th>
<th>User</th>
<th># Unique</th>
<th style="text-align: right;"># Unique</th>
</tr>
</thead>
<tbody>
@ -113,7 +115,8 @@
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.user__name }}</td>
<td>{{ stat.unique_requests }} ({% widthratio stat.unique_requests stat.total_requests 100 %}%)</td>
<td style="text-align: right;">{{ stat.unique_requests }}</td>
<td>({% widthratio stat.unique_requests stat.total_requests 100 %}%)</td>
</tr>
{% endfor %}
</tbody>
@ -156,7 +159,7 @@
<tr>
<th>#</th>
<th>User</th>
<th># Others</th>
<th style="text-align: right;"># Others</th>
<th># Own</th>
</tr>
</thead>
@ -165,7 +168,7 @@
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.name }}</td>
<td>{{ stat.total }}</td>
<td style="text-align: right;">{{ stat.total }}</td>
<td>{{ stat.own_total}}</td>
</tr>
{% endfor %}

View File

@ -41,7 +41,7 @@
<th>{{ forloop.counter }}</th>
<td>{{ stat.song__artist }}</td>
<td>{{ stat.song__title }}</td>
<td>{{ stat.total }}</td>
<td style="text-align: middle;">{{ stat.total }}</td>
</tr>
{% endfor %}
</tbody>
@ -64,7 +64,7 @@
<th>#</th>
<th>Artist</th>
<th>Title</th>
<th>Others</th>
<th style="text-align: right;">Others</th>
<th>You</th>
</tr>
</thead>
@ -74,7 +74,7 @@
<th>{{ forloop.counter }}</th>
<td>{{ stat.song__artist }}</td>
<td>{{ stat.song__title }}</td>
<td>{{ stat.total }}</td>
<td style="text-align: right;">{{ stat.total }}</td>
<td>{{ stat.user_total }}</td>
</tr>
{% endfor %}
@ -91,7 +91,7 @@
<tr>
<th>#</th>
<th>Uploader</th>
<th># Requests</th>
<th style="text-align: right;"># Requests</th>
</tr>
</thead>
<tbody>
@ -99,7 +99,8 @@
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ stat.song__user__name }}</td>
<td>{{ stat.total }} ({% widthratio stat.total stats.total_requests 100 %}%)</td>
<td style="text-align: right;">{{ stat.total }}</td>
<td>({% widthratio stat.total stats.total_requests 100 %}%)</td>
</tr>
{% endfor %}
</tbody>

View File

@ -127,7 +127,7 @@ def compute_stats():
total_time_overall = sum(x['avg_dur'] for x in list(stats['time_requested']))
total_average = total_time_overall / len(stats['time_requested'])
avg_dur_min, avg_dur_sec = divmod(total_average, 60)
total_average = '{} minutes and {} seconds'.format(
total_average = '{:.0f} minutes and {:.0f} seconds'.format(
avg_dur_min, avg_dur_sec)
requests_uploader = PlaylistSong.objects.filter(state=2).exclude(
@ -138,7 +138,7 @@ def compute_stats():
most_requested_uploaders = []
best_uploaders_list(list(requests_uploader), most_requested_uploaders)
most_requested_uploaders = sorted(most_requested_uploaders, key=lambda x: x['total'], reverse=True)[:settings.STATS_TOP_COUNT]
for time in list(stats['time_requested']):
# converts total time and average time in respectively days and minutes, seconds
time['duration'] = str(round(time['total'] / 86400, 2)) + ' days'
@ -150,13 +150,13 @@ def compute_stats():
# Convert requested time to days
time_requested = list(stats['time_requested'])
for tr in time_requested:
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
tr['duration'] = "{:5.2f} days".format(tr['total'] / 86400)
return {
'last_updated': last_updated,
'total_uploads': stats['total_uploads'],
'total_uploads': "{0:,.0f}".format(stats['total_uploads']),
'upload_stats': list(stats['upload_stats']),
'total_requests': stats['total_requests'],
'total_requests': "{0:,.0f}".format(stats['total_requests']),
'request_stats': list(stats['request_stats']),
'unique_request_stats': list(stats['unique_request_stats']),
'total_unique_requests': stats['total_unique_requests'],
@ -207,7 +207,7 @@ def user_stats(request):
total=Count('id', filter=~Q(user__id=request)),
user_total=Count('id', filter=Q(user__id=request))).order_by(
'-total', 'song__artist',
'song__title')[:settings.STATS_TOP_COUNT]
'song__title')
most_played = list(most_played_uploads)
total_played_uploads = 0
@ -215,7 +215,8 @@ def user_stats(request):
for x in most_played:
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]
return {
'last_updated': last_updated,
'total_uploads': total_uploads,
@ -223,7 +224,7 @@ def user_stats(request):
'unique_requests': unique_requests,
'most_played_songs': list(most_played_songs),
'most_played_uploaders': list(most_played_uploaders),
'most_played_uploads': list(most_played_uploads),
'most_played_uploads': most_played_uploads_list,
'stats_top_count': settings.STATS_TOP_COUNT,
'total_played_uploads': total_played_uploads,
'total_played_user_uploads': total_played_user_uploads,