Commit 7a6bed16 authored by Hubert Denkmair's avatar Hubert Denkmair

make highscore relevant time range configurable

parent f65e34c7
......@@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
import datetime
import pytz
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......@@ -104,4 +106,8 @@ LOGIN_URL = '/login/'
STATIC_URL = '/static/'
HIGHSCORE_DT_FROM = datetime.datetime(1, 1, 1, 0, 0, tzinfo=pytz.UTC)
HIGHSCORE_DT_TILL = datetime.datetime(9999, 12, 31, 23, 59, tzinfo=pytz.UTC)
HIGHSCORE_BLACKLIST = []
exec(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "local_settings.py")).read()) in globals()
......@@ -2,18 +2,16 @@ from django.shortcuts import render
from django.db.models import F, Max, ExpressionWrapper, FloatField
from core.models import SnakeGame
from django.db import models
import datetime
import pytz
STATS_DT_FROM = datetime.datetime(2018, 5, 12, 16, 0, tzinfo=pytz.UTC)
STATS_DT_TILL = datetime.datetime(2018, 5, 13, 12, 0, tzinfo=pytz.UTC)
STATS_BLACKLIST = [
"M0wLaue"
]
from django.conf import settings
def get_relevant_games():
return SnakeGame.objects.filter(end_date__gte=STATS_DT_FROM, end_date__lte=STATS_DT_TILL).exclude(user__username__in=STATS_BLACKLIST)
return SnakeGame.objects.filter(
end_date__gte=settings.HIGHSCORE_DT_FROM,
end_date__lte=settings.HIGHSCORE_DT_TILL
).exclude(
user__username__in=settings.HIGHSCORE_BLACKLIST
)
def sattr(obj, attr, val):
......@@ -61,7 +59,11 @@ def score(request):
def maxage(request):
data = get_relevant_games().values('user__username').annotate(score=Max(F('end_frame')-F('start_frame'))).exclude(user__username__in=STATS_BLACKLIST).order_by('-score')
data = get_relevant_games().\
values('user__username').\
annotate(score=Max(F('end_frame')-F('start_frame'))).\
exclude(user__username__in=settings.HIGHSCORE_BLACKLIST).\
order_by('-score')
if request.user.is_authenticated:
usr = get_relevant_games().filter(user=request.user).aggregate(score=Max(F('end_frame')-F('start_frame')))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment