# Path: apps/core/models.py
# class Service(models.Model):
#     """
#     denotes single sso client
#     - name:               unique name
#     - is_shown:           decides to show in SSO main page
#     - alias:              user friendly name
#     - scope:              scope; TEST / SPARCS / PUBLIC
#     - main_url:           main page url
#     - login_callback_url: login callback url
#     - unregister_url:     unregister page url
#     - secret_key:         secret key
#     - admin_user:         admin of this client
#     - cooltime:           cooltime (days) to re-register; < 60
#     - icon:               icon of this service
#     """
# 
#     name = models.CharField(max_length=40, primary_key=True)
#     is_shown = models.BooleanField(default=True)
#     alias = models.CharField(max_length=30)
#     scope = models.CharField(max_length=6, choices=SERVICE_SCOPE,
#                              default=SERVICE_TEST)
#     main_url = models.CharField(max_length=200)
#     login_callback_url = models.CharField(max_length=200)
#     unregister_url = models.CharField(max_length=200, null=True, blank=True)
#     secret_key = models.CharField(max_length=100)
#     admin_user = models.ForeignKey(User, on_delete=models.CASCADE,
#                                    related_name='managed_services')
#     cooltime = models.IntegerField()
#     icon = models.ImageField(null=True, blank=True)
# 
#     @property
#     def icon_url(self):
#         return self.icon.url if self.icon else '/static/img/test-service.png'
# 
#     def __str__(self):
#         return self.alias
# 
# class Statistic(models.Model):
#     """
#     denotes single statistic; raw json
#     - time: timestamp of statistic
#     - data: raw json statistic data
#     """
#     time = models.DateTimeField()
#     data = models.TextField()
# 
#     def pretty(self):
#         time_str = localtime(self.time).isoformat()
#         return f'{time_str} {self.data}'
# 
#     def __str__(self):
#         return f'{self.time}'


import json
from datetime import timedelta
from django.conf import settings
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from django.utils import timezone
from apps.core.models import Service, Statistic
                'kaist': {
                    'start_year': {},
                    'birth_year': {},
                    'gender': {
                        'male': 0,
                        'female': 0,
                    },
                    'department': {},
                    'employee': 0,
                    'professor': 0,
                },
            }

    def add_basic_stat(self, service, user):
        stat = self.stats[service]
        stat['account']['all'] += 1
        if user.profile.email_authed:
            stat['account']['email'] += 1
        if user.profile.facebook_id:
            stat['account']['fb'] += 1
        if user.profile.twitter_id:
            stat['account']['tw'] += 1
        if user.profile.kaist_id:
            stat['account']['kaist'] += 1
        if user.profile.test_enabled:
            stat['account']['test'] += 1

        if user.profile.gender == '*M':
            stat['gender']['male'] += 1
        elif user.profile.gender == '*F':

# Path: apps/core/models.py
# class Service(models.Model):
#     """
#     denotes single sso client
#     - name:               unique name
#     - is_shown:           decides to show in SSO main page
#     - alias:              user friendly name
#     - scope:              scope; TEST / SPARCS / PUBLIC
#     - main_url:           main page url
#     - login_callback_url: login callback url
#     - unregister_url:     unregister page url
#     - secret_key:         secret key
#     - admin_user:         admin of this client
#     - cooltime:           cooltime (days) to re-register; < 60
#     - icon:               icon of this service
#     """
# 
#     name = models.CharField(max_length=40, primary_key=True)
#     is_shown = models.BooleanField(default=True)
#     alias = models.CharField(max_length=30)
#     scope = models.CharField(max_length=6, choices=SERVICE_SCOPE,
#                              default=SERVICE_TEST)
#     main_url = models.CharField(max_length=200)
#     login_callback_url = models.CharField(max_length=200)
#     unregister_url = models.CharField(max_length=200, null=True, blank=True)
#     secret_key = models.CharField(max_length=100)
#     admin_user = models.ForeignKey(User, on_delete=models.CASCADE,
#                                    related_name='managed_services')
#     cooltime = models.IntegerField()
#     icon = models.ImageField(null=True, blank=True)
# 
#     @property
#     def icon_url(self):
#         return self.icon.url if self.icon else '/static/img/test-service.png'
# 
#     def __str__(self):
#         return self.alias
# 
# class Statistic(models.Model):
#     """
#     denotes single statistic; raw json
#     - time: timestamp of statistic
#     - data: raw json statistic data
#     """
#     time = models.DateTimeField()
#     data = models.TextField()
# 
#     def pretty(self):
#         time_str = localtime(self.time).isoformat()
#         return f'{time_str} {self.data}'
# 
#     def __str__(self):
#         return f'{self.time}'


# Path: apps/core/management/commands/collect-stats.py
import json
from datetime import timedelta
from django.conf import settings
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from django.utils import timezone
from apps.core.models import Service, Statistic

                'kaist': {
                    'start_year': {},
                    'birth_year': {},
                    'gender': {
                        'male': 0,
                        'female': 0,
                    },
                    'department': {},
                    'employee': 0,
                    'professor': 0,
                },
            }

    def add_basic_stat(self, service, user):
        stat = self.stats[service]
        stat['account']['all'] += 1
        if user.profile.email_authed:
            stat['account']['email'] += 1
        if user.profile.facebook_id:
            stat['account']['fb'] += 1
        if user.profile.twitter_id:
            stat['account']['tw'] += 1
        if user.profile.kaist_id:
            stat['account']['kaist'] += 1
        if user.profile.test_enabled:
            stat['account']['test'] += 1

        if user.profile.gender == '*M':
            stat['gender']['male'] += 1
        elif user.profile.gender == '*F':

            stat['gender']['female'] += 1