2018-12-05 22:58:26 +00:00
|
|
|
import os
|
|
|
|
import json
|
2018-12-06 04:38:36 +00:00
|
|
|
from datetime import datetime, timedelta
|
2018-12-05 22:58:26 +00:00
|
|
|
from django.conf import settings
|
2018-12-13 21:18:29 +00:00
|
|
|
from minecraft_manager.models import Application, Player, Ticket, Note, IP
|
2018-12-06 05:30:07 +00:00
|
|
|
from django.contrib.auth.models import User
|
2018-12-05 22:58:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
},
|
2018-12-13 21:18:29 +00:00
|
|
|
'note': Note.objects.count(),
|
2018-12-05 22:58:26 +00:00
|
|
|
'ip': IP.objects.count()
|
|
|
|
}
|
|
|
|
|
|
|
|
# Averages
|
|
|
|
data['average'] = {
|
2018-12-06 17:00:57 +00:00
|
|
|
'age': round(sum([application.age for application in Application.objects.filter(accepted=True)]) /
|
|
|
|
data['total']['application']['accepted'] if data['total']['application']['accepted'] != 0 else 1, 2)
|
2018-12-05 22:58:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:38:36 +00:00
|
|
|
# Percentage
|
|
|
|
data['percentage'] = {
|
2018-12-05 23:05:32 +00:00
|
|
|
'accepted': round((data['total']['application']['accepted'] /
|
2019-07-26 17:37:20 +00:00
|
|
|
data['total']['application']['all'] if data['total']['application']['all'] != 0 else 1) * 100, 2),
|
2018-12-05 23:05:32 +00:00
|
|
|
'banned': round((data['total']['player']['banned'] /
|
2019-07-26 17:37:20 +00:00
|
|
|
data['total']['player']['all'] if data['total']['player']['all'] != 0 else 1) * 100, 2),
|
|
|
|
'applied': round((data['total']['application']['all'] /
|
|
|
|
data['total']['player']['all'] if data['total']['player']['all'] != 0 else 1) * 100, 2)
|
2018-12-06 04:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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()
|
2018-12-05 22:58:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 05:30:07 +00:00
|
|
|
# Admin
|
|
|
|
data['resolved'] = []
|
|
|
|
for user in User.objects.all().order_by('username'):
|
|
|
|
data['resolved'].append({
|
|
|
|
'active': user.is_active,
|
|
|
|
'username': user.username,
|
|
|
|
'tickets': Ticket.objects.filter(staff=user).count()
|
|
|
|
})
|
|
|
|
|
2018-12-05 22:58:26 +00:00
|
|
|
return data
|