diff --git a/marietje/stats/templates/stats/user.html b/marietje/stats/templates/stats/user.html
index 9f23409..f0bff7d 100644
--- a/marietje/stats/templates/stats/user.html
+++ b/marietje/stats/templates/stats/user.html
@@ -8,17 +8,22 @@
User Statistics
+ {% if not stats %}
+
+ Stats unavailable :(
+
+ {% else %}
{% if current_age_text %}
{{ current_age_text }}
{% endif %}
+
Total uploads: {{ stats.total_uploads }}
- Total requests: {{ stats.total_requests }}
Unique requests: {{ stats.unique_requests }} ({% widthratio stats.unique_requests stats.total_requests 100 %}%)
- Total requested uploads: {{stats.total_played_uploads}}
Most played songs
+
Total: {{ stats.total_requests }}
Top {{ stats.stats_top_count }}:
@@ -45,7 +50,8 @@
-
Most played uploads
+
Uploads requested by others
+
Total: {{stats.total_played_uploads}}
Top {{ stats.stats_top_count }}:
@@ -87,7 +93,7 @@
| {{ forloop.counter }} |
{{ stat.song__user__name }} |
- {{ stat.total }} ({% widthratio stat.total total_requests 100 %}%) |
+ {{ stat.total }} ({% widthratio stat.total stats.total_requests 100 %}%) |
{% endfor %}
@@ -95,5 +101,6 @@
+ {% endif %}
{% endblock %}
\ No newline at end of file
diff --git a/marietje/stats/utils.py b/marietje/stats/utils.py
index 9cd17e7..79a7542 100644
--- a/marietje/stats/utils.py
+++ b/marietje/stats/utils.py
@@ -60,7 +60,7 @@ def compute_stats():
'user__id', 'user__name').annotate(
total_requests=Count('id', distinct=True),
unique_requests=Count('song__id', distinct=True)).order_by(
- '-total_requests')[:settings.STATS_TOP_COUNT]
+ '-unique_requests')[:settings.STATS_TOP_COUNT]
total_unique_requests = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
@@ -145,16 +145,15 @@ def user_stats(request):
'-total')[:settings.STATS_TOP_COUNT]
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__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values(
- 'pk').values(
+ state=2, song_id__in=Song.objects.filter(user__id=request)).exclude(Q(user__id=None)|Q(user__id=request)).values(
'song__artist',
'song__title').annotate(total=Count('id')).order_by(
'-total', 'song__artist',
'song__title')[:settings.STATS_TOP_COUNT]
-
- total_played_uploads = most_played_uploads.aggregate(newtotal=Sum('total'))
+ most_played = list(most_played_uploads)
+ total_played_uploads = 0
+ for x in most_played:
+ total_played_uploads += x['total']
return {
'last_updated': last_updated,
@@ -165,6 +164,6 @@ def user_stats(request):
'most_played_uploaders': list(most_played_uploaders),
'most_played_uploads': list(most_played_uploads),
'stats_top_count': settings.STATS_TOP_COUNT,
- 'total_played_uploads': total_played_uploads['newtotal'],
+ 'total_played_uploads': total_played_uploads,
}