@@ -0,0 +1,2051 @@
+# -*- coding: utf-8 -*-%0A%0Aimport arrow%0A%0Afrom django.contrib.auth import get_user_model%0Afrom django.core.management.base import BaseCommand%0Afrom django.db.models import Count%0A%0Afrom termcolor import colored%0A%0Afrom data_import.models import DataFile%0Afrom open_humans.models import Member%0Afrom private_sharing.models import DataRequestProject, DataRequestProjectMember%0AUserModel = get_user_model()%0A%0A%0Aclass Command(BaseCommand):%0A    help = 'Statistics on the site'%0A    args = ''%0A%0A    def add_arguments(self, parser):%0A        parser.add_argument('--date', type=str,%0A                            help='stats as of this date')%0A%0A    def handle(self, *args, **options):%0A        cutoff = arrow.get(options%5B'date'%5D).datetime%0A%0A        members = Member.objects.filter(user__date_joined__lte=cutoff)%0A        members_with_data = members.annotate(%0A            datafiles_count=Count('user__datafiles')).filter(%0A            datafiles_count__gte=1)%0A        files = DataFile.objects.exclude(archived__lte=cutoff).filter(%0A            created__lte=cutoff)%0A        projects_made = DataRequestProject.objects.filter(created__lte=cutoff)%0A        projects_approved = projects_made.filter(approved=True)%0A%0A        data_connections = set(%5B(%0A            df%5B'source'%5D, df%5B'user__username'%5D) for%0A            df in DataFile.objects.exclude(%0A            archived__lte=cutoff).filter(%0A            created__lte=cutoff).values('user__username', 'source')%5D)%0A%0A        proj_connections = DataRequestProjectMember.objects.exclude(%0A            project__approved=False).exclude(joined=False).exclude(%0A            authorized=False).filter(created__lte=cutoff)%0A%0A        print(%22Members: %7B%7D%22.format(members.count()))%0A        print(%22Members with any data connections: %7B%7D%22.format(%0A            members_with_data.count()))%0A        print(%22Data connections: %7B%7D%22.format(len(data_connections)))%0A        print(%22Project connections: %7B%7D%22.format(proj_connections.count()))%0A        print(%22Projects drafted: %7B%7D%22.format(projects_made.count()))%0A        print(%22Projects approved: %7B%7D%22.format(projects_approved.count()))%0A

Add new stats management command