##// END OF EJS Templates
Fixed statistics module to exclude empty (not null) URLs
Fixed statistics module to exclude empty (not null) URLs

File last commit:

r1749:39e5bf4f default
r1749:39e5bf4f default
Show More
statistics.py
35 lines | 1.2 KiB | text/x-python | PythonLexer
neko259
Added statistics management command
r1727 from django.core.management import BaseCommand
neko259
Added statistics on file format usage
r1742 from django.db.models import Count
neko259
Added statistics management command
r1727
from boards.models import Attachment
from boards.utils import get_domain
class Command(BaseCommand):
help = 'Gather board statistics'
def handle(self, *args, **options):
neko259
Added statistics on file format usage
r1742 print('* Domains and their usage')
neko259
Added statistics management command
r1727 domains = {}
neko259
Fixed statistics module to exclude empty (not null) URLs
r1749 for attachment in Attachment.objects.exclude(url=None).exclude(url=''):
neko259
Added statistics management command
r1727 full_domain = attachment.url.split('/')[2]
domain = get_domain(full_domain)
if domain in domains:
domains[domain] += 1
else:
domains[domain] = 1
for domain in domains:
print('{}: {}'.format(domain, domains[domain]))
print('* Overall numbers')
print('{} attachments in the system, {} of them as URLs'.format(
Attachment.objects.count(),
Attachment.objects.exclude(url=None).count()))
neko259
Added statistics on file format usage
r1742 print('* File types')
mimetypes = Attachment.objects.filter(url=None)\
.values('mimetype').annotate(count=Count('id'))\
.order_by('-count')
for mimetype in mimetypes:
print('{}: {}'.format(mimetype['mimetype'], mimetype['count']))