#!/usr/bin/python3
import os
import csv
import json
result = {}
for file in os.listdir("./"):
if file.endswith(".csv"):
yesVotes = {'CDU/CSU': 0, 'SPD': 0, 'DIE LINKE.': 0, 'BÜ90/GR': 0}
noVotes = {'CDU/CSU': 0, 'SPD': 0, 'DIE LINKE.': 0, 'BÜ90/GR': 0}
abstVotes = {'CDU/CSU': 0, 'SPD': 0, 'DIE LINKE.': 0, 'BÜ90/GR': 0}
invalidVotes = {'CDU/CSU': 0, 'SPD': 0, 'DIE LINKE.': 0, 'BÜ90/GR': 0}
notVotes = {'CDU/CSU': 0, 'SPD': 0, 'DIE LINKE.': 0, 'BÜ90/GR': 0}
votes = {'CDU/CSU': 0, 'SPD': 0, 'DIE LINKE.': 0, 'BÜ90/GR': 0}
#"Wahlperiode","Sitzungnr","Abstimmnr","Fraktion/Gruppe","Name","Vorname","Titel","ja","nein","Enthaltung","ungültig","nichtabgegeben","Bezeichnung"
with open(file, 'r', encoding='utf-8') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',')
firstrow = True
for row in csvreader:
#skip header
if firstrow:
firstrow = False
continue
party = row[3]
if row[7] == "1.0":
yesVotes[party] += 1
votes[party] += 1
elif row[8] == "1.0":
noVotes[party] += 1
votes[party] += 1
elif row[9] == "1.0":
abstVotes[party] += 1
votes[party] += 1
elif row[10] == "1.0":
invalidVotes[party] += 1
votes[party] += 1
else:
notVotes[party] += 1
# print ergs
yesVotes.update({k: v/votes[k] for k,v in yesVotes.items()})
noVotes.update({k: v/votes[k] for k,v in noVotes.items()})
abstVotes.update({k: v/votes[k] for k,v in abstVotes.items()})
invalidVotes.update({k: v/votes[k] for k,v in invalidVotes.items()})
result[file[:-4]] = {
'yes': yesVotes,
'no': noVotes,
'abst': abstVotes,
'inv': invalidVotes,
'not': notVotes
}
print(json.dumps(result))