mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 13:22:20 +01:00
added descriptions to stats and userstats
This commit is contained in:
@ -18,8 +18,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Uploads</h2>
|
<h2>Uploads</h2>
|
||||||
<h4>Total: {{ stats.total_uploads }}</h4>
|
<p>In total <strong> {{ stats.total_uploads }} </strong> songs have been uploaded.
|
||||||
<h4>Top {{ stats.stats_top_count }}:</h4>
|
These are the {{ stats.stats_top_count }} people who have uploaded the most.</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
@ -43,8 +43,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Requests</h2>
|
<h2>Requests</h2>
|
||||||
<h4>Total: {{ stats.total_requests }}</h4>
|
<p>In total <strong> {{ stats.total_requests }} </strong> songs have been requested.
|
||||||
<h4>Top {{ stats.stats_top_count }}:</h4>
|
These are the {{ stats.stats_top_count }} people who have requested the most songs.</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
@ -68,8 +68,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Time requested</h2>
|
<h2>Time requested</h2>
|
||||||
<h4>Total: {{stats.total_time_requested}}</h4>
|
<p>In total <strong> {{ stats.total_time_requested }} </strong> of music have been requested, with an
|
||||||
<h4>Top {{ stats.stats_top_count }}:</h4>
|
average song length of <strong>{{ stats.total_average }}</strong>.
|
||||||
|
These are the {{ stats.stats_top_count }} people with the longest total time queued</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
@ -95,8 +96,9 @@
|
|||||||
</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.total}}</h4>
|
<p>In total <strong> {{stats.total_unique_requests.total}}</strong> different songs
|
||||||
<h4>Top {{ stats.stats_top_count }}:</h4>
|
have been requested. The {{ stats.stats_top_count }} people that have requested the largest number of
|
||||||
|
different songs are shown below.
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
@ -120,7 +122,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Most played songs</h2>
|
<h2>Most played songs</h2>
|
||||||
<h4>Top {{ stats.stats_top_count }}:</h4>
|
<p>These are the {{ stats.stats_top_count }} most played songs ever.</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
@ -146,22 +148,25 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Most played uploaders</h2>
|
<h2>Most played uploaders</h2>
|
||||||
<h4>Top {{ stats.stats_top_count }}:</h4>
|
<p>The left column shows the {{ stats.stats_top_count }} people whose songs are requested most often by other people
|
||||||
|
people. The right column shows how many times that person has queued his own songs.</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>User</th>
|
<th>User</th>
|
||||||
<th># Songs</th>
|
<th># Others</th>
|
||||||
|
<th># Own</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for stat in stats.most_requested_uploaders %}
|
{% for stat in stats.most_requested_uploaders %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ forloop.counter }}</th>
|
<th>{{ forloop.counter }}</th>
|
||||||
<td>{{ stat.song__user__name }}</td>
|
<td>{{ stat.name }}</td>
|
||||||
<td>{{ stat.total }} ({% widthratio stat.total stats.total_requests 100 %}%)</td>
|
<td>{{ stat.total }}</td>
|
||||||
|
<td>{{ stat.own_total}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -170,7 +175,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Most played songs last 14 days</h2>
|
<h2>Most played songs last 14 days</h2>
|
||||||
<h4>Top {{ stats.stats_top_count }}:</h4>
|
<p>These songs are played the {{ stats.stats_top_count }} most in the last two weeks.</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@ -19,11 +19,11 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>Total uploads: {{ stats.total_uploads }}</h4>
|
|
||||||
<h4>Unique requests: {{ stats.unique_requests }} ({% widthratio stats.unique_requests stats.total_requests 100 %}%)</h4>
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Most played songs</h2>
|
<h2>Most played songs</h2>
|
||||||
<h4>Total: {{ stats.total_requests }}</h4>
|
<p>You have requested <strong> {{ stats.unique_requests }} </strong> different
|
||||||
|
songs a total of <strong> {{ stats.total_requests }} </strong> times. This
|
||||||
|
means <strong> {% widthratio stats.unique_requests stats.total_requests 100 %}% </strong> of your requests have been unique. </p>
|
||||||
<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">
|
||||||
@ -51,8 +51,11 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Uploads requested</h2>
|
<h2>Uploads requested</h2>
|
||||||
<h4>Total played by you: {{stats.total_played_user_uploads}}</h4>
|
<p> You have uploaded a total of <strong> {{stats.total_uploads }} </strong> songs. The left column
|
||||||
<h4>Total played by others: {{stats.total_played_uploads}}</h4>
|
shows how many times these have been requested by other people. The right column shows
|
||||||
|
how many times you requested your own songs. In total your songs
|
||||||
|
have been queued <strong> {{stats.total_played_uploads }} </strong> times by others and
|
||||||
|
<strong> {{stats.total_played_user_uploads }} </strong> by yourself.
|
||||||
<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">
|
||||||
@ -81,7 +84,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h2>Most played uploaders</h2>
|
<h2>Most played uploaders</h2>
|
||||||
<h4>Top {{ stats.stats_top_count }}:</h4>
|
<p> The people whose songs you have queued the most are:</p>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@ -17,8 +17,10 @@ def recache_stats():
|
|||||||
caches['default'].set('stats', new_stats, 2 * 3600)
|
caches['default'].set('stats', new_stats, 2 * 3600)
|
||||||
return new_stats
|
return new_stats
|
||||||
|
|
||||||
|
|
||||||
def recache_user_stats():
|
def recache_user_stats():
|
||||||
users = User.objects.exclude(Q(id=None)
|
users = User.objects.exclude(
|
||||||
|
Q(id=None)
|
||||||
| Q(id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values('id')
|
| Q(id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values('id')
|
||||||
for user in users:
|
for user in users:
|
||||||
new_stats = user_stats(user['id'])
|
new_stats = user_stats(user['id'])
|
||||||
@ -27,13 +29,51 @@ 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 time_convert(time):
|
def time_convert(time):
|
||||||
for tr in time:
|
try:
|
||||||
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
|
for tr in time:
|
||||||
avg_dur_sec = tr['avg_dur']%60
|
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
|
||||||
avg_dur_min = int((tr['avg_dur']-avg_dur_sec)/60)
|
avg_dur_sec = tr['avg_dur'] % 60
|
||||||
tr['avg_dur'] = '{}:{}'.format(avg_dur_min, avg_dur_sec)
|
avg_dur_min = int((tr['avg_dur'] - avg_dur_sec) / 60)
|
||||||
return time
|
tr['avg_dur'] = '{}:{}'.format(avg_dur_min, avg_dur_sec)
|
||||||
|
return time
|
||||||
|
except:
|
||||||
|
avg_dur_sec = round(time % 60)
|
||||||
|
avg_dur_min = int(round((time - avg_dur_sec) / 60))
|
||||||
|
return ('{} minutes and {} seconds'.format(avg_dur_min, avg_dur_sec))
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_uploaders(requests_uploader, most_requested_uploaders):
|
||||||
|
for x in requests_uploader:
|
||||||
|
a = len(most_requested_uploaders)
|
||||||
|
b = 0
|
||||||
|
while b <= a:
|
||||||
|
if b == a:
|
||||||
|
adding_list_item(most_requested_uploaders, x)
|
||||||
|
elif x['song__user__id'] == most_requested_uploaders[b]['id']:
|
||||||
|
if x['song__user__name'] == x['user__name']:
|
||||||
|
most_requested_uploaders[b]['own_total'] = x['total']
|
||||||
|
else:
|
||||||
|
most_requested_uploaders[b]['total'] += x['total']
|
||||||
|
break
|
||||||
|
b += 1
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def adding_list_item(list, x):
|
||||||
|
list.append({
|
||||||
|
'id': x['song__user__id'],
|
||||||
|
'name': x['song__user__name'],
|
||||||
|
'total': 0,
|
||||||
|
'own_total': 0
|
||||||
|
})
|
||||||
|
if x['song__user__id'] == x['user__id']:
|
||||||
|
list[-1]['own_total']: x['total']
|
||||||
|
else:
|
||||||
|
list[-1]['_total']: x['total']
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
@ -78,28 +118,41 @@ def compute_stats():
|
|||||||
'-total', 'song__artist')[:settings.STATS_TOP_COUNT]
|
'-total', 'song__artist')[:settings.STATS_TOP_COUNT]
|
||||||
|
|
||||||
most_played_songs_14_days = PlaylistSong.objects.filter(
|
most_played_songs_14_days = PlaylistSong.objects.filter(
|
||||||
state=2, played_at__gte=timezone.now() -
|
state=2, played_at__gte=timezone.now() - timedelta(days=14)).exclude(
|
||||||
timedelta(days=14)).exclude(user_id=None).values(
|
user_id=None).values(
|
||||||
'song__artist',
|
'song__artist',
|
||||||
'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(
|
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'), avg_dur=Sum('song__duration')/Count('id')).order_by(
|
'user__id', 'user__name').annotate(
|
||||||
'-total')[:settings.STATS_TOP_COUNT]
|
total=Sum('song__duration'),
|
||||||
|
avg_dur=Sum('song__duration') /
|
||||||
|
Count('id')).order_by('-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(
|
||||||
Q(user_id=None)
|
Q(user_id=None)
|
||||||
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).aggregate(
|
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).aggregate(
|
||||||
total=Sum('song__duration'))
|
total=Sum('song__duration'))
|
||||||
|
|
||||||
most_requested_uploaders = PlaylistSong.objects.filter(state=2).exclude(
|
total_time_overall = 0
|
||||||
|
count = 0
|
||||||
|
for x in list(time_requested):
|
||||||
|
total_time_overall += x['avg_dur']
|
||||||
|
count += 1
|
||||||
|
total_average = total_time_overall / count
|
||||||
|
total_average = time_convert(total_average)
|
||||||
|
|
||||||
|
requests_uploader = 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(
|
||||||
'song__user__id', 'song__user__name').annotate(total=Count(
|
'song__user__id', 'song__user__name', 'user__name',
|
||||||
'song__user__id')).order_by('-total')[:settings.STATS_TOP_COUNT]
|
'user__id').annotate(total=Count('song__user__name'))
|
||||||
|
|
||||||
|
most_requested_uploaders = []
|
||||||
|
calculate_uploaders(list(requests_uploader), most_requested_uploaders)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'last_updated': last_updated,
|
'last_updated': last_updated,
|
||||||
@ -117,6 +170,7 @@ def compute_stats():
|
|||||||
'most_requested_uploaders': list(most_requested_uploaders),
|
'most_requested_uploaders': list(most_requested_uploaders),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def user_stats(request):
|
def user_stats(request):
|
||||||
last_updated = datetime.now()
|
last_updated = datetime.now()
|
||||||
|
|
||||||
@ -148,11 +202,12 @@ 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(user__id=None).values(
|
state=2, song_id__in=Song.objects.filter(user__id=request)).exclude(
|
||||||
'song__artist',
|
user__id=None).values('song__artist', 'song__title').annotate(
|
||||||
'song__title').annotate(total=Count('id', filter=~Q(user__id=request)), user_total=Count('id', filter=Q(user__id=request))).order_by(
|
total=Count('id', filter=~Q(user__id=request)),
|
||||||
'-total', 'song__artist',
|
user_total=Count('id', filter=Q(user__id=request))).order_by(
|
||||||
'song__title')[:settings.STATS_TOP_COUNT]
|
'-total', 'song__artist',
|
||||||
|
'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
|
||||||
@ -173,4 +228,3 @@ def user_stats(request):
|
|||||||
'total_played_uploads': total_played_uploads,
|
'total_played_uploads': total_played_uploads,
|
||||||
'total_played_user_uploads': total_played_user_uploads,
|
'total_played_user_uploads': total_played_user_uploads,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user