mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 08:52:22 +01:00
Revert "Merge branch '14-day-stat' into 'marietje-zuid'"
This reverts merge request !24
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django.core.cache import caches
|
from django.core.cache import caches
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Count, Q, Sum
|
from django.db.models import Count, Q, Sum
|
||||||
@ -61,7 +63,7 @@ def adding_list_item(most_requested_list, requests):
|
|||||||
|
|
||||||
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
|
||||||
last_updated = timezone.now()
|
last_updated = datetime.now()
|
||||||
stats = {}
|
stats = {}
|
||||||
|
|
||||||
stats['total_uploads'] = Song.objects.filter(deleted=False).exclude(
|
stats['total_uploads'] = Song.objects.filter(deleted=False).exclude(
|
||||||
@ -104,7 +106,7 @@ def compute_stats():
|
|||||||
|
|
||||||
stats['most_played_songs_14_days'] = PlaylistSong.objects.filter(
|
stats['most_played_songs_14_days'] = PlaylistSong.objects.filter(
|
||||||
state=2, played_at__gte=timezone.now() -
|
state=2, played_at__gte=timezone.now() -
|
||||||
timezone.timedelta(days=14)).exclude(user_id=None).values(
|
timedelta(days=14)).exclude(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]
|
||||||
@ -172,7 +174,7 @@ def compute_stats():
|
|||||||
|
|
||||||
|
|
||||||
def user_stats(request):
|
def user_stats(request):
|
||||||
last_updated = timezone.now()
|
last_updated = datetime.now()
|
||||||
|
|
||||||
total_uploads = Song.objects.filter(
|
total_uploads = Song.objects.filter(
|
||||||
user__id=request, deleted=False).count()
|
user__id=request, deleted=False).count()
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django.core.cache import caches
|
from django.core.cache import caches
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
def stats(request):
|
def stats(request):
|
||||||
stats_data = caches['default'].get('stats')
|
stats_data = caches['default'].get('stats')
|
||||||
@ -30,12 +32,12 @@ def user_stats(request):
|
|||||||
return render(request, 'stats/user.html', data, status=status)
|
return render(request, 'stats/user.html', data, status=status)
|
||||||
|
|
||||||
def age_text(last_updated):
|
def age_text(last_updated):
|
||||||
current_age = timezone.now() - last_updated
|
current_age = datetime.now() - last_updated
|
||||||
minutes = (current_age.seconds % 3600) / 60
|
minutes = (current_age.seconds % 3600) / 60
|
||||||
hours = current_age.seconds / 3600
|
hours = current_age.seconds / 3600
|
||||||
minutestr = "minute" if minutes == 1 else "minutes"
|
minutestr = "minute" if minutes == 1 else "minutes"
|
||||||
hourstr = "hour" if hours == 1 else "hours"
|
hourstr = "hour" if hours == 1 else "hours"
|
||||||
if current_age < timezone.timedelta(hours=1):
|
if current_age < timedelta(hours=1):
|
||||||
return 'Stats were updated {:.0f} {} ago.'.format(minutes, minutestr)
|
return 'Stats were updated {:.0f} {} ago.'.format(minutes, minutestr)
|
||||||
|
|
||||||
return 'Stats were updated {:.0f} {} and {:.0f} {} ago.'.format(
|
return 'Stats were updated {:.0f} {} and {:.0f} {} ago.'.format(
|
||||||
|
|||||||
Reference in New Issue
Block a user