-
Notifications
You must be signed in to change notification settings - Fork 0
/
changesets-aggregate.py
41 lines (36 loc) · 1.26 KB
/
changesets-aggregate.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
# -*- coding: utf-8 -*-
import django
import datetime
import json
from django.conf import settings
from django.contrib.auth.models import User
from apps.oi import states
from apps.oi.models import Changeset, ChangesetComment, CTYPES
def main():
step = 7
top = 30
years = range(2010, 2017)
months = range(1, 13)
data = [[[[[0 for i in range(top + 1)]
for auto in range(2)]
for approved in range(2)]
for month in months]
for year in years]
django.setup()
anon = User.objects.get(username=settings.ANON_USER_NAME)
changes = Changeset.objects.exclude(indexer=anon).filter(
change_type=CTYPES['issue'],
created__gt=datetime.date(2010, 1, 1),
state__in=[states.APPROVED,states.DISCARDED])
for item in changes:
auto = 0
if ChangesetComment.objects.filter(changeset=item, text__startswith='This is an automatic').exists():
auto = 1
approved = 1 if item.state == states.APPROVED else 0;
i = (item.modified - item.created).days / step
if i > top:
i = top
data[item.modified.year - 2010][item.modified.month - 1][approved][auto][i] += 1
print 'var data =', json.dumps(data), ';'
if __name__ == '__main__':
main()