pylint fixes

This commit is contained in:
oslomp
2019-02-04 19:53:20 +01:00
parent 1b4108c5d0
commit 6dc36f2092
2 changed files with 27 additions and 27 deletions

View File

@ -105,7 +105,7 @@ CACHES = {
'userstats': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/MarietjeDjango_cache/default',
'OPTIONS': { 'MAX_ENTRIES': 1500 },
'OPTIONS': {'MAX_ENTRIES': 1500},
},
}

View File

@ -64,26 +64,27 @@ def adding_list_item(most_requested_list, requests):
def compute_stats():
# We want to grab the time now, because otherwise we would be reporting a minute too late
last_updated = datetime.now()
stats = {}
total_uploads = Song.objects.filter(deleted=False).exclude(
stats['total_uploads'] = Song.objects.filter(deleted=False).exclude(
user_id=None).count()
upload_stats = Song.objects.filter(deleted=False).exclude(
stats['upload_stats'] = Song.objects.filter(deleted=False).exclude(
user_id=None).values(
'user__id', 'user__name').annotate(total=Count('id')).order_by(
'-total', 'user__name')[:settings.STATS_TOP_COUNT]
total_requests = PlaylistSong.objects.filter(state=2).exclude(
stats['total_requests'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).count()
request_stats = PlaylistSong.objects.filter(state=2).exclude(
stats['request_stats'] = 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=Count('id')).order_by(
'-total', 'user__name')[:settings.STATS_TOP_COUNT]
unique_request_stats = PlaylistSong.objects.filter(state=2).exclude(
stats['unique_request_stats'] = 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(
@ -91,27 +92,26 @@ def compute_stats():
unique_requests=Count('song__id', distinct=True)).order_by(
'-unique_requests')[:settings.STATS_TOP_COUNT]
total_unique_requests = PlaylistSong.objects.filter(state=2).exclude(
stats['total_unique_requests'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).aggregate(
total=Count('song__id', distinct=True))
most_played_songs = PlaylistSong.objects.filter(state=2).exclude(
stats['most_played_songs'] = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
| Q(user_id__in=settings.STATS_REQUEST_IGNORE_USER_IDS)).values(
'song__artist',
'song__title').annotate(total=Count('id')).order_by(
'-total', 'song__artist')[:settings.STATS_TOP_COUNT]
most_played_songs_14_days = PlaylistSong.objects.filter(
stats['most_played_songs_14_days'] = PlaylistSong.objects.filter(
state=2, played_at__gte=timezone.now() -
timedelta(days=14)).exclude(user_id=None).values(
'song__artist',
'song__title').annotate(total=Count('id')).order_by(
'-total', 'song__artist')[:settings.STATS_TOP_COUNT]
time_requested = PlaylistSong.objects.filter(state=2).exclude(
stats['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(
@ -119,16 +119,16 @@ def compute_stats():
avg_dur=Sum('song__duration') /
Count('id')).order_by('-total')[:settings.STATS_TOP_COUNT]
total_time_requested = PlaylistSong.objects.all().filter(state=2).exclude(
stats['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'))
total_time_overall = sum(x['avg_dur'] for x in list(time_requested))
total_average = total_time_overall / len(time_requested)
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(
avg_dur_min, avg_dur_sec)
avg_dur_min, avg_dur_sec)
requests_uploader = PlaylistSong.objects.filter(state=2).exclude(
Q(user_id=None)
@ -139,7 +139,7 @@ def compute_stats():
most_requested_uploaders = []
best_uploaders_list(list(requests_uploader), most_requested_uploaders)
for time in list(time_requested):
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'
avg_dur_min, avg_dur_sec = divmod(time['avg_dur'], 60)
@ -148,23 +148,23 @@ def compute_stats():
time['avg_dur'] = '{}:{}'.format(avg_dur_min, avg_dur_sec)
# Convert requested time to days
time_requested = list(time_requested)
time_requested = list(stats['time_requested'])
for tr in time_requested:
tr['duration'] = str(round(tr['total'] / 86400, 2)) + ' days'
return {
'last_updated': last_updated,
'total_uploads': total_uploads,
'upload_stats': list(upload_stats),
'total_requests': total_requests,
'request_stats': list(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_14_days': list(most_played_songs_14_days),
'time_requested': time_requested,
'total_uploads': stats['total_uploads'],
'upload_stats': list(stats['upload_stats']),
'total_requests': stats['total_requests'],
'request_stats': list(stats['request_stats']),
'unique_request_stats': list(stats['unique_request_stats']),
'total_unique_requests': stats['total_unique_requests'],
'most_played_songs': list(stats['most_played_songs']),
'most_played_songs_14_days': list(stats['most_played_songs_14_days']),
'time_requested': stats['time_requested'],
'total_time_requested': str(round(float(
total_time_requested['total']) / 86400, 2)) + ' days',
stats['total_time_requested']['total']) / 86400, 2)) + ' days',
'stats_top_count': settings.STATS_TOP_COUNT,
'most_requested_uploaders': list(most_requested_uploaders),
'total_average': total_average,