##// END OF EJS Templates
Localized a minor sticker message. Refactored sticker factory
Localized a minor sticker message. Refactored sticker factory

File last commit:

r1782:71d3a47e default
r1942:412bb996 default
Show More
statistics.py
36 lines | 1.3 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
Allow deleting aliases
r1750 for attachment in Attachment.objects.exclude(url=''):
neko259
Show domain next to URL if available
r1765 domain = get_domain(attachment.url)
neko259
Added statistics management command
r1727 if domain in domains:
domains[domain] += 1
else:
domains[domain] = 1
neko259
Sort domains by their usage in statistics
r1782 domain_list = [(item, domains[item]) for item in domains.keys()]
domain_list = sorted(domain_list, key=lambda domain: -domain[1])
for domain in domain_list:
print('{}: {}'.format(domain[0], domain[1]))
neko259
Added statistics management command
r1727
print('* Overall numbers')
print('{} attachments in the system, {} of them as URLs'.format(
Attachment.objects.count(),
neko259
Allow deleting aliases
r1750 Attachment.objects.exclude(url='').count()))
neko259
Added statistics management command
r1727
neko259
Added statistics on file format usage
r1742 print('* File types')
neko259
Allow deleting aliases
r1750 mimetypes = Attachment.objects.filter(url='')\
neko259
Show domain next to URL if available
r1765 .values('mimetype').annotate(count=Count('id'))\
.order_by('-count')
neko259
Added statistics on file format usage
r1742 for mimetype in mimetypes:
print('{}: {}'.format(mimetype['mimetype'], mimetype['count']))