-
Notifications
You must be signed in to change notification settings - Fork 0
/
responses.py
70 lines (44 loc) · 1.65 KB
/
responses.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
import csv
from datetime import datetime
def get_responses_as_list():
with open('responses.csv') as csv_file:
reader = csv.reader(csv_file)
return list(reader)
responses = get_responses_as_list()
def before_cutoff_date(date):
cutoff_date = datetime(2017, 3, 10, 17)
response_date = datetime.strptime(date, '%m/%d/%Y %H:%M:%S')
return response_date < cutoff_date
def num_skipped(answers):
return len(list(filter(lambda x: x == '', answers)))
def is_valid_response(row):
return num_skipped(row[1:]) < 10 and before_cutoff_date(row[0])
print (len(responses))
questions = responses[0][1:]
responses = list(filter(is_valid_response, responses[1:]))
print (len(responses))
num_questions = []
for i, q in enumerate(questions):
totals = {
'Strongly Agree': 0,
'Agree': 0,
'Neutral': 0,
'Disagree': 0,
'Strongly Disagree': 0
}
for response in responses:
answer = response[i+1]
if answer:
totals[answer] += 1
num_questions.append(totals)
def get_total(totals, response):
return [total[response] for total in totals]
with open('totals.csv', 'wb') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(['Response'] + questions)
writer.writerow(['Strongly Agree'] + get_total(num_questions, 'Strongly Agree'))
writer.writerow(['Agree'] + get_total(num_questions, 'Agree'))
writer.writerow(['Neutral'] + get_total(num_questions, 'Neutral'))
writer.writerow(['Disagree'] + get_total(num_questions, 'Disagree'))
writer.writerow(['Strongly Disagree'] + get_total(num_questions, 'Strongly Disagree'))
print(num_questions)