-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalysis
More file actions
138 lines (125 loc) · 5.05 KB
/
analysis
File metadata and controls
138 lines (125 loc) · 5.05 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import csv
def checkState(state):
with open('votes.csv') as csv_file:
csv_reader = csv.reader(csv_file)
info = [[] for i in range(8)]
for row in csv_reader:
if row[2] == state:
for i in range(8):
info[i].append(row[i])
with open('' + state + '_votes.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(['Name', 'Party', 'State', 'Question', 'Measure', 'URL', 'Date', 'Vote', 'Category'])
for i in range(len(info[0])):
r = []
for j in info:
r.append(j[i])
writer.writerow(r)
def checkRep(senator, state):
with open('votes.csv') as csv_file:
csv_reader = csv.reader(csv_file)
info = [[] for i in range(9)]
for row in csv_reader:
if row[0] == senator and row[2] == state:
for i in range(9):
info[i].append(row[i])
with open('' + senator + '_votes.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(['Name', 'Party', 'State', 'Question', 'Measure', 'URL', 'Date', 'Vote', 'Category'])
for i in range(len(info[0])):
r = []
for j in info:
r.append(j[i])
writer.writerow(r)
def voteWithParty(senator, state, rLeader, dLeader):
votes_with = 0
votes_total = 0
with open('votes.csv') as csv_file:
csv_reader = csv.reader(csv_file)
info = [[] for i in range(9)]
for row in csv_reader:
if row[0] == senator and row[2] == state:
party = row[1]
if party == 'D':
leader = dLeader
elif party == 'R':
leader = rLeader
else:
return -1
with open('' + leader + '_votes.csv') as csv_leadfile:
csv_leadfile = csv.reader(csv_leadfile)
for leadrow in csv_leadfile:
if row[6] == leadrow[6]:
votes_total += 1
if row[7] == leadrow[7]:
votes_with += 1
return round(votes_with/votes_total,1)
def listofCategoriesandSenators():
categories = []
senators = []
with open('votes.csv') as csv_file:
csv_reader = csv.reader(csv_file)
for row in csv.reader(csv_file):
if not row[8] in categories:
categories.append(row[8])
if not [row[0], row[1], row[2]] in senators:
senators.append([row[0], row[1], row[2]])
return categories, senators
def categoryLoyalties(senator, state, rLeader, dLeader, categories):
catLoyalties = []
for category in categories:
votes_with = 0
votes_total = 0
with open('votes.csv') as csv_file:
csv_reader = csv.reader(csv_file)
info = [[] for i in range(9)]
for row in csv_reader:
if row[0] == senator and row[2] == state:
party = row[1]
if party == 'D':
leader = dLeader
elif party == 'R':
leader = rLeader
else:
votes_with = -1
votes_total = 1
break
with open('' + leader + '_votes.csv') as csv_leadfile:
csv_leadfile = csv.reader(csv_leadfile)
for leadrow in csv_leadfile:
if row[6] == leadrow[6] and row[8] == leadrow[8]:
votes_total += 1
if row[7] == leadrow[7]:
votes_with += 1
#print(votes_with, votes_total)
catLoyalties.append(round(votes_with/votes_total*100,1))
return catLoyalties
def participation(senator, state):
committed_votes = 0
voting_sessions = 0
with(open('votes.csv')) as csv_file:
csv_reader = csv.reader(csv_file)
info = [[] for i in range(9)]
for row in csv_reader:
if row[0] == senator and row[2] == state:
if row[7] == 'Yea' or row[7] == 'Nay':
committed_votes += 1
voting_sessions += 1
return round(committed_votes/voting_sessions,1)
categories, senators = listofCategoriesandSenators()
senators = senators[1:]
with open('votes_analysis.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
arr = ['Name', 'Party', 'State', 'Participation', 'Party Loyalty']
writer.writerow(arr)
for i in categories:
if i is not "Assorted Motion":
arr.append('Loyalty to ' + i)
for i in senators:
r = [i[0], i[1], i[2], participation(i[0], i[2]) * 100, voteWithParty(i[0], i[2], 'McConnell', 'Schumer') * 100]
s = categoryLoyalties(i[0], i[2], 'McConnell', 'Schumer', categories)
r += s
writer.writerow(r)
if __name__== "__main__":
checkRep('Schumer', 'NY')
checkRep('McConnell', 'KY')