From 6dc36f2092aa1cf1033879567e91219f46e93306 Mon Sep 17 00:00:00 2001 From: oslomp Date: Mon, 4 Feb 2019 19:53:20 +0100 Subject: [PATCH] pylint fixes --- marietje/marietje/settings.py | 2 +- marietje/stats/utils.py | 52 +++++++++++++++++------------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/marietje/marietje/settings.py b/marietje/marietje/settings.py index 3109ead..4745f32 100644 --- a/marietje/marietje/settings.py +++ b/marietje/marietje/settings.py @@ -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}, }, } diff --git a/marietje/stats/utils.py b/marietje/stats/utils.py index 0541b89..5555ea1 100644 --- a/marietje/stats/utils.py +++ b/marietje/stats/utils.py @@ -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,