-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeContrb.py
More file actions
48 lines (40 loc) · 1.11 KB
/
timeContrb.py
File metadata and controls
48 lines (40 loc) · 1.11 KB
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
import pymongo, json, datetime
users = {}
spans = {}
client = pymongo.MongoClient(host='da0.eecs.utk.edu')
db = client['bitbucket']
commits = db['commits']
iterator = commits.find({})
for result in iterator:
try:
for commit in result['values']:
username = ''
repo = ''
date = ''
try:
username = commit['author']['user']['username']
repo = commit['repository']['full_name']
date = commit['date']
except KeyError:
pass
if username != '' and date != '':
year, month, day = map(int, date.split('T')[0].split('-'))
u_date = datetime.date(year, month, day)
try:
users[username]
except KeyError:
users[username] = {
'first' : datetime.date(datetime.MAXYEAR, 1, 1),
'last' : datetime.date(datetime.MINYEAR, 1, 1)
}
if u_date < users[username]['first']:
users[username]['first'] = u_date
if u_date > users[username]['last']:
users[username]['last'] = u_date
except KeyError:
pass
for username in users:
diff = users[username]['last'] - users[username]['first']
diff = int(diff.days)
spans[username] = diff
print json.dumps(spans)