From b44f49239b065d29a36b7122c4fb0492c025eeac Mon Sep 17 00:00:00 2001 From: Etzelia Date: Wed, 5 Dec 2018 22:38:36 -0600 Subject: [PATCH] Overview improvements --- overview.py | 21 +++++++++++++++++---- templates/minecraft_manager/overview.html | 15 +++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) 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 @@
-

Acceptance Rate: {{ data.ratio.accepted }}%

+

Acceptance Rate: {{ data.percentage.accepted }}%

+

Application/Player Rate: {{ data.percentage.applied }}%

-

Ban Rate: {{ data.ratio.banned }}%

+

Ban Rate: {{ data.percentage.banned }}%

+
+
+
+
+
+

Logins Today: {{ data.unique.day }}

+

Logins Last Month: {{ data.unique.month }}

+
+
+

Logins Last Week: {{ data.unique.week }}