-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicoast.py
38 lines (27 loc) · 881 Bytes
/
icoast.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
import csv
from dateutil.parser import parse
from collections import defaultdict
with open("icoast_in.csv","rb") as inf:
cr = csv.reader(inf)
header = cr.next()
daycounts = defaultdict(int)
usercounts = defaultdict(lambda: defaultdict(int))
for l in cr:
d = dict(zip(header,l))
dt = parse(d["Completion Time"])
daycounts["{0}-{1}-{2}".format(dt.year,dt.month,dt.day)] += 1
usercounts["{0}-{1}-{2}".format(dt.year,dt.month,dt.day)][d["User ID"]] += 1
users = set(["716","736","882","730","712"])
# for k in usercounts:
# users.update(usercounts[k].keys())
with open("icoast.csv","wb") as outf:
cw = csv.writer(outf)
cw.writerow(["date","count"] + list(users))
for k in daycounts:
outrow = [k,daycounts[k]]
for u in users:
if u in usercounts[k]:
outrow.append(usercounts[k][u])
else:
outrow.append(0)
cw.writerow(outrow)