-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateVoteData.py
More file actions
55 lines (50 loc) · 1.68 KB
/
generateVoteData.py
File metadata and controls
55 lines (50 loc) · 1.68 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
#coding:utf-8
# generateVoteData
import csv, sys
# read participan data
def readParticipants(filename):
partList = {}
with open(filename,'rb') as csvfile:
reader = csv.reader(csvfile,delimiter=',',quotechar='"',quoting=csv.QUOTE_MINIMAL)
for row in reader:
person = {}
person["partID"] = row[0]
person["type"] = row[1]
person["PosVoteID"] = row[2]
partList[row[2]] = person
csvfile.close()
return partList
# reader vote data generated by posvote
def readPosVoteData(filename):
voteList = {}
with open(filename,'rb') as csvfile:
reader = csv.reader(csvfile,delimiter=',',quotechar='"',quoting=csv.QUOTE_MINIMAL)
lineno = 0
for row in reader:
lineno+=1
vote = {}
if len(row)<2:
sys.stderr.write("ERROR: line "+ str(lineno) + " has no vote information"+"\n".decode('utf-8'))
continue
else:
vote["posVoteID"]=row[0]
vote["data"]=row[1:len(row)]
voteList[row[0]]=vote
csvfile.close()
return voteList
# generate vote data
def generateVoteData(partList, voteList):
voteData = {}
for vote in voteList:
if vote in partList:
participant = partList[vote]
for d in voteList[vote]["data"]:
print participant["partID"]+","+participant["type"]+","+d
else:
sys.stderr.write("ERROR: "+vote+" does not exist")
continue
# main procedure
if __name__ == '__main__':
partList = readParticipants(sys.argv[1])
voteList = readPosVoteData(sys.argv[2])
generateVoteData(partList, voteList)