-
Notifications
You must be signed in to change notification settings - Fork 1
/
general_export_for_stats.py
53 lines (41 loc) · 1.61 KB
/
general_export_for_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import django
import argparse
import sys
import json
if __name__=="__main__":
parser = argparse.ArgumentParser(description='exports registraions in json')
parser.add_argument('--mode', nargs='?', const=1, type=str, default='debug', help='debug/production')
parser.add_argument('--cohort', nargs='?', const=1, type=int, default=-1, help='cohort to export')
parser.add_argument('--no-projects', action='store_true')
MODE, COHORT, NOPROJECTS = parser.parse_args().mode, parser.parse_args().cohort, parser.parse_args().no_projects
if MODE not in ["debug", "production"]:
sys.exit(1)
if MODE == 'debug':
os.environ['DJANGO_SETTINGS_MODULE'] = 'MasterMarketplace.settings_development'
elif MODE == 'production':
os.environ['DJANGO_SETTINGS_MODULE'] = 'MasterMarketplace.settings'
django.setup()
from registration.models import Registration
from projects.models import Project
data = {
'registrations' : {},
'projects' : {}
}
if COHORT != -1:
regs = Registration.objects.filter(Cohort=COHORT)
else:
regs = Registration.objects.all()
for reg in regs:
data['registrations'][reg.Student.email] = reg.Program.Name.split('-')[0]
if NOPROJECTS:
print(json.dumps(data))
sys.exit(0)
groupcount = {}
for p in Project.objects.filter(Status=3):
try:
groupcount[p.Group.ShortName] += 1
except KeyError:
groupcount[p.Group.ShortName] = 1
data['projects'] = groupcount
print(json.dumps(data))