parent
c9d5546386
commit
611c4e1934
|
@ -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
|
|
@ -6,141 +6,45 @@
|
|||
{% endblock %}
|
||||
{% block section %}
|
||||
<div id="content">
|
||||
<div class="row">
|
||||
<div class="col-xs-9 col-md-6">
|
||||
<h3 class="center">Applications{% if form.apps.unanswered > 0 %} <a href="{% url "application" %}?accepted=">({{ form.apps.unanswered }} Unanswered)</a>{% endif %}</h3>
|
||||
<canvas id="appChart" style="width:30em;height:15em" ></canvas>
|
||||
</div>
|
||||
<div class="col-xs-9 col-md-6">
|
||||
<h3 class="center">Tickets{% if form.tickets.unclaimed > 0 %} <a href="{% url "ticket" %}?claimed=false">({{ form.tickets.unclaimed }} Unclaimed)</a>{% endif %}</h3>
|
||||
<h4></h4>
|
||||
<canvas id="ticketChart" style="width:30em;height:15em" ></canvas>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9 col-md-6">
|
||||
<h3>Applications: {{ data.total.application.all }}</h3>
|
||||
<p>Accepted: {{ data.total.application.accepted }}</p>
|
||||
<p>Denied: {{ data.total.application.denied }}</p>
|
||||
<br/>
|
||||
<h3>Tickets: {{ data.total.ticket.all }}</h3>
|
||||
<p>Claimed: {{ data.total.ticket.claimed }}</p>
|
||||
<p>Unclaimed: {{ data.total.ticket.unclaimed }}</p>
|
||||
<p>Resolved: {{ data.total.ticket.resolved }}</p>
|
||||
<p>Unresolved: {{ data.total.ticket.unresolved }}</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-18 col-md-12">
|
||||
<h3 class="center">Totals</h3>
|
||||
<canvas id="totalChart" style="width:30em;height:15em" ></canvas>
|
||||
</div>
|
||||
<div class="col-xs-9 col-md-6">
|
||||
<h3>Players: {{ data.total.player.all }}</h3>
|
||||
<p>Not Banned: {{ data.total.player.unbanned }}</p>
|
||||
<p>Banned: {{ data.total.player.banned }}</p>
|
||||
<br/>
|
||||
<h3>Warnings: {{ data.total.warning }}</h3>
|
||||
<br/>
|
||||
<h3>IPs: {{ data.total.ip }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var app_data = {
|
||||
labels: [
|
||||
"Unanswered",
|
||||
"Denied",
|
||||
"Accepted"
|
||||
],
|
||||
datasets: [
|
||||
{
|
||||
data: [{{ form.apps.unanswered }}, {{ form.apps.denied }}, {{ form.apps.accepted }}],
|
||||
backgroundColor: [
|
||||
"#8080ff",
|
||||
"#ff3333",
|
||||
"#33cc33"
|
||||
],
|
||||
hoverBackgroundColor: [
|
||||
"#8080ff",
|
||||
"#ff3333",
|
||||
"#33cc33"
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
var app_options = {
|
||||
animation: {
|
||||
animateRotate: true
|
||||
}
|
||||
}
|
||||
var app_ctx = $("#appChart");
|
||||
var app_chart = new Chart(app_ctx,
|
||||
{
|
||||
type: 'pie',
|
||||
data: app_data,
|
||||
options: app_options
|
||||
}
|
||||
);
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-xs-9 col-md-6">
|
||||
<h3>Average Age: {{ data.average.age }}</h3>
|
||||
</div>
|
||||
<div class="col-xs-9 col-md-6">
|
||||
|
||||
var ticket_data = {
|
||||
labels: [
|
||||
"Unclaimed",
|
||||
"Claimed",
|
||||
"Resolved"
|
||||
],
|
||||
datasets: [
|
||||
{
|
||||
data: [{{ form.tickets.unclaimed }}, {{ form.tickets.claimed }}, {{ form.tickets.resolved }}],
|
||||
backgroundColor: [
|
||||
"#8080ff",
|
||||
"#ff3333",
|
||||
"#33cc33"
|
||||
],
|
||||
hoverBackgroundColor: [
|
||||
"#8080ff",
|
||||
"#ff3333",
|
||||
"#33cc33"
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
var ticket_options = {
|
||||
animation: {
|
||||
animateRotate: true
|
||||
}
|
||||
}
|
||||
var ticket_ctx = $("#ticketChart");
|
||||
var ticket_chart = new Chart(ticket_ctx,
|
||||
{
|
||||
type: 'pie',
|
||||
data: ticket_data,
|
||||
options: ticket_options
|
||||
}
|
||||
);
|
||||
|
||||
var total_data = {
|
||||
labels: [
|
||||
"Applications",
|
||||
"Players",
|
||||
"IPs",
|
||||
"Tickets",
|
||||
"Warnings"
|
||||
],
|
||||
datasets: [
|
||||
{
|
||||
label: "Totals",
|
||||
data: [
|
||||
{{ form.counts.applications }},
|
||||
{{ form.counts.players }},
|
||||
{{ form.counts.ips }},
|
||||
{{ form.counts.tickets }},
|
||||
{{ form.counts.warnings }}
|
||||
],
|
||||
backgroundColor: [
|
||||
'rgba(255, 99, 132, 0.2)',
|
||||
'rgba(54, 162, 235, 0.2)',
|
||||
'rgba(255, 206, 86, 0.2)',
|
||||
'rgba(75, 192, 192, 0.2)',
|
||||
'rgba(153, 102, 255, 0.2)'
|
||||
],
|
||||
borderColor: [
|
||||
'rgba(255,99,132,1)',
|
||||
'rgba(54, 162, 235, 1)',
|
||||
'rgba(255, 206, 86, 1)',
|
||||
'rgba(75, 192, 192, 1)',
|
||||
'rgba(153, 102, 255, 1)'
|
||||
],
|
||||
borderWidth: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
var total_ctx = $("#totalChart");
|
||||
var total_chart = new Chart(total_ctx,
|
||||
{
|
||||
type: 'bar',
|
||||
data: total_data
|
||||
}
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-xs-9 col-md-6">
|
||||
<h3>Acceptance Rate: {{ data.ratio.accepted }}</h3>
|
||||
</div>
|
||||
<div class="col-xs-9 col-md-6">
|
||||
<h3>Ban Rate: {{ data.ratio.banned }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock section %}
|
17
views.py
17
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):
|
||||
|
|
Loading…
Reference in New Issue