diff --git a/overview.py b/overview.py new file mode 100644 index 0000000..ab1687c --- /dev/null +++ b/overview.py @@ -0,0 +1,52 @@ +import os +import json +from django.conf import settings +from minecraft_manager.models import Application, Player, Ticket, Warning, IP + + +def overview_data(): + data = {} + + # Setup + with open(os.path.join(settings.MINECRAFT_BASE_DIR, 'banned-players.json'), encoding='utf-8') as f: + bans = json.load(f) + + + # Totals + data['total'] = { + 'application': { + 'accepted': Application.objects.filter(accepted=True).count(), + 'denied': Application.objects.filter(accepted=False).count(), + 'all': Application.objects.count() + }, + 'player': { + 'banned': len(bans), + 'unbanned': Player.objects.count() - len(bans), + 'all': Player.objects.count() + }, + 'ticket': { + 'claimed': Ticket.objects.filter(staff__isnull=False).count(), + 'unclaimed': Ticket.objects.filter(staff__isnull=True).count(), + 'resolved': Ticket.objects.filter(resolved=True).count(), + 'unresolved': Ticket.objects.filter(resolved=False).count(), + 'all': Ticket.objects.count() + }, + 'warning': Warning.objects.count(), + 'ip': IP.objects.count() + } + + # Averages + data['average'] = { + 'age': sum([application.age for application in Application.objects.all()]) / + data['total']['application']['all'] if data['total']['application']['all'] != 0 else 1 + } + + # Ratios + data['ratio'] = { + 'accepted': data['total']['application']['accepted'] / + data['total']['application']['denied'] if data['total']['application']['denied'] != 0 else 1, + 'banned': data['total']['player']['banned'] / + data['total']['player']['unbanned'] if data['total']['player']['unbanned'] != 0 else 1 + } + + return data diff --git a/templates/minecraft_manager/overview.html b/templates/minecraft_manager/overview.html index 5cd2646..63f261b 100644 --- a/templates/minecraft_manager/overview.html +++ b/templates/minecraft_manager/overview.html @@ -6,141 +6,45 @@ {% endblock %} {% block section %}
-
-
-

Applications{% if form.apps.unanswered > 0 %} -

- +
+
+

Applications: {{ data.total.application.all }}

+

Accepted: {{ data.total.application.accepted }}

+

Denied: {{ data.total.application.denied }}

+
+

Tickets: {{ data.total.ticket.all }}

+

Claimed: {{ data.total.ticket.claimed }}

+

Unclaimed: {{ data.total.ticket.unclaimed }}

+

Resolved: {{ data.total.ticket.resolved }}

+

Unresolved: {{ data.total.ticket.unresolved }}

-
-
-

Totals

- -
+
+

Players: {{ data.total.player.all }}

+

Not Banned: {{ data.total.player.unbanned }}

+

Banned: {{ data.total.player.banned }}

+
+

Warnings: {{ data.total.warning }}

+
+

IPs: {{ data.total.ip }}

- +
+
+
+
+
+

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

+
+
+

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

+
+
+
{% endblock section %} \ No newline at end of file diff --git a/views.py b/views.py index d2769e9..46be592 100644 --- a/views.py +++ b/views.py @@ -14,6 +14,7 @@ from django.views.generic import View from django.contrib.auth.models import User from minecraft_manager.models import Application as AppModel, Player as PlayerModel, Ticket as TicketModel, Warning as WarningModel, IP as IPModel, Alert as AlertModel, Note as NoteModel, UserSettings as UserSettingsModel from minecraft_manager.forms import WarningForm, NoteForm +from minecraft_manager.overview import overview_data import minecraft_manager.api.api as API import subprocess @@ -33,19 +34,9 @@ class Overview(View): request.user.usersettings = UserSettingsModel(auth_user=request.user) request.user.usersettings.last_ip = user_ip request.user.usersettings.save() - unanswered_apps = AppModel.objects.filter(accepted=None).count() - accepted_apps = AppModel.objects.filter(accepted=True).count() - denied_apps = AppModel.objects.filter(accepted=False).count() - unclaimed_tickets = TicketModel.objects.filter(staff=None, resolved=False).count() - claimed_tickets = TicketModel.objects.filter(staff__isnull=False, resolved=False).count() - resolved_tickets = TicketModel.objects.filter(resolved=True).count() - counts = {'applications': AppModel.objects.count(), 'players': PlayerModel.objects.count(), - "ips": IPModel.objects.count(), "tickets": TicketModel.objects.count(), - "warnings": WarningModel.objects.count()} - form = {'apps': {'unanswered': unanswered_apps, 'accepted': accepted_apps, 'denied': denied_apps}, - 'tickets': {'unclaimed': unclaimed_tickets, 'claimed': claimed_tickets, 'resolved': resolved_tickets}, - 'counts': counts} - return render(request, 'minecraft_manager/overview.html', {'current_app': 'overview', 'form': form}) + + + return render(request, 'minecraft_manager/overview.html', {'current_app': 'overview', 'data': overview_data()}) class CoreProtect(View):