diff --git a/overview.py b/overview.py index 60ddcdb..609ae1a 100644 --- a/overview.py +++ b/overview.py @@ -1,5 +1,6 @@ import os import json +from datetime import datetime, timedelta from django.conf import settings from minecraft_manager.models import Application, Player, Ticket, Warning, IP @@ -41,12 +42,24 @@ def overview_data(): data['total']['application']['all'] if data['total']['application']['all'] != 0 else 1, 2) } - # Ratios - data['ratio'] = { + # Percentage + data['percentage'] = { 'accepted': round((data['total']['application']['accepted'] / - data['total']['application']['denied'] if data['total']['application']['denied'] != 0 else 1) * 100, 2), + data['total']['application']['all'] if data['total']['application']['all'] != 0 else 1) * 100, 2), 'banned': round((data['total']['player']['banned'] / - data['total']['player']['unbanned'] if data['total']['player']['unbanned'] != 0 else 1) * 100, 2) + data['total']['player']['all'] if data['total']['player']['all'] != 0 else 1) * 100, 2), + 'applied': round((data['total']['application']['all'] / data['total']['player']['all']) * 100, 2) + } + + # Unique logins + now = datetime.now() + day = now - timedelta(days=1) + week = now - timedelta(weeks=1) + month = now - timedelta(weeks=4) + data['unique'] = { + 'day': Player.objects.filter(last_seen__range=[day, now]).count(), + 'week': Player.objects.filter(last_seen__range=[week, now]).count(), + 'month': Player.objects.filter(last_seen__range=[month, now]).count() } return data diff --git a/templates/minecraft_manager/overview.html b/templates/minecraft_manager/overview.html index 665ac76..24ff385 100644 --- a/templates/minecraft_manager/overview.html +++ b/templates/minecraft_manager/overview.html @@ -40,10 +40,21 @@