-
Notifications
You must be signed in to change notification settings - Fork 1
/
combine.py
53 lines (44 loc) · 1.3 KB
/
combine.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
"""
Combine dumped poll results
"""
import arrow
import json
# Mongo database
from pymongo import MongoClient
import CONFIG
from choices import CHOICES
counts = { }
for day in CHOICES:
dayname = day["day"]
counts[dayname] = { }
for period in day["periods"]:
counts[dayname][period] = 0
try:
dbclient = MongoClient(CONFIG.MONGO_URL)
db = dbclient.cis322
collection = db.poll
except:
print("Failure opening database. Is Mongo running? Correct password?")
sys.exit(1)
record_count = 0
for record in collection.find( { "kind": "office hours poll" } ):
name = record["name"]
print("*** {}".format(name))
if 'TEST' in name or 'test' in name:
print(" Skipping {}".format(record["name"]))
continue
record_count += 1
# del record['_id']
# print(json.dumps(record, sort_keys=True, indent=4 ))
times = record["times"]
for dayname, periods in times.items():
print("{} {}".format(dayname, periods))
for period in periods:
counts[dayname][period] += 1
print("\n== {} responses ==".format(record_count))
# Dump in order from CHOICES
print("\n==SUMMARY==")
for day in CHOICES:
dayname = day["day"]
for period in day["periods"]:
print("{} {}: {}".format(dayname,period, counts[dayname][period]))