-
Notifications
You must be signed in to change notification settings - Fork 0
/
tally.py
109 lines (89 loc) · 3.71 KB
/
tally.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from __future__ import print_function
from datetime import datetime
import event_log_parser as elp
import utils_parser as up
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
RANGE = 'Form Responses 1!A2:F'
class Attendee :
def __init__(self):
self.date = None
self.name = None
self.email = None
self.affiliation = None
self.department = None
def getPastEvents (events, thresholdDate) :
newEventsDict = dict()
for eventKey in events.keys():
event = events[eventKey]
if event.date < thresholdDate:
newEventsDict[eventKey] = event
return newEventsDict
def getFutureEvents (events, thresholdDate) :
newEventsDict = dict()
for eventKey in events.keys():
event = events[eventKey]
if event.date > thresholdDate:
newEventsDict[eventKey] = event
return newEventsDict
numColumnsInRSVPForm = 6
numColumnsInSignupForm = 5
timestampIndex = 0
emailIndex_RSVP = 1
nameIndex_RSVP = 2
affiliation_RSVP = numColumnsInRSVPForm - 1
department_RSVP = affiliation_RSVP - 1
emailIndex_SignIn = 2
nameIndex_SignIn = 1
affiliation_SignIn = numColumnsInSignupForm - 1
department_SignIn = affiliation_SignIn - 1
def getAttendees (events) :
service = up.getService()
rsvpAttendees = dict()
signupAttendees = dict()
for eventKey in events.keys():
event = events[eventKey]
eventName = event.name
rsvpSpreadsheetID = up.getSpreadsheetID(event.rsvpSpreadsheet)
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=rsvpSpreadsheetID,
range=RANGE).execute()
values = result.get('values', [])
for value in values:
# Parse RSVP Form
if len(value) > numColumnsInRSVPForm - 1:
attendee = Attendee()
attendee.date = datetime.strptime(value[timestampIndex], '%m/%d/%Y %H:%M:%S')
attendee.name = value[nameIndex_RSVP]
attendee.email = value[emailIndex_RSVP]
attendee.affiliation = value[affiliation_RSVP]
attendee.department = value[department_RSVP]
rsvpAttendees[eventName + "_" + attendee.name] = attendee
# Parse SignIn Form
if len(value) > numColumnsInSignupForm - 1:
attendee = Attendee()
attendee.date = datetime.strptime(value[timestampIndex], '%m/%d/%Y %H:%M:%S')
attendee.name = value[nameIndex_SignIn]
attendee.email = value[emailIndex_SignIn]
attendee.affiliation = value[affiliation_SignIn]
attendee.department = value[department_SignIn]
signupAttendees[eventName + "_" + attendee.name] = attendee
return rsvpAttendees, signupAttendees
def tallyOfficers(attendees) :
officersCount = dict()
officersNames = dict()
for attendeeKey in attendees.keys() :
attendee = attendees[attendeeKey]
if 'Officer' in attendee.affiliation :
if attendee.email not in officersCount.keys() :
officersCount[attendee.email] = 1
officersNames[attendee.email] = attendee.name
else :
officersCount[attendee.email] += 1
return officersCount, officersNames
# This tallies up the future RSVP count of officers
events = elp.getEvents()
rsvpAttendees, signupAttendees = getAttendees(getFutureEvents(events, datetime.now()))
officerCount, officersNames = tallyOfficers(rsvpAttendees)
for officer in officerCount.keys() :
print(officersNames[officer] + " " + str(officerCount[officer]))