dodany agregator wyników z jsona do csv

master
Michał 'rysiek' Woźniak 2015-01-11 22:56:34 +01:00
parent a9cbd32ee2
commit 439d829400
1 changed files with 63 additions and 0 deletions

63
socnetsurvey_aggregate.py Executable file
View File

@ -0,0 +1,63 @@
#!/usr/bin/python3
import os
import csv
import simplejson as json
questions = [
["s1_q1", "perceiveProblems"],
["s1_q2_1", "howSerious:negotiatingPosition"],
["s1_q2_2", "howSerious:publicAdministration"],
["s1_q2_3", "howSerious:personalSocialFamily"],
["s1_q2_4", "howSerious:influenceOverPerception"],
["s1_q2_5", "howSerious:thirdPartiesBusinessPartners"],
["s1_q2_6", "howSerious:losingControl"],
["s1_q2_7", "howSerious:changeOfTOS"],
["s1_q2_8", "howSerious:connectedServices"],
["s1_q2_9", "howSerious:other"],
["s1_q2_9_text", "howSerious:other:text"],
["s1_q3", "nonCommercial"],
["s1_q4_4", "oversight"],
["s1_q5", "bestSolution"],
["s2_q1", "identifyAs"],
["s2_q1_7_text", "identifyAs:text"],
["s2_q2", "age"],
["s2_q3", "occupation"],
["s2_q4", "education"],
["s2_q5", "comment"],
["request_hash", "requestHash"],
["datetime", "dateTime"]
]
# otwieramy plik csv
with open('../socnetsurvey_data.csv', 'w') as csvfile:
csvdata = csv.writer(csvfile)
# nagłówek do csv!
c = []
for q in questions:
c += [':'.join(q)]
csvdata.writerow(c)
# iterujemy po plikach
for f in os.listdir('.'):
# plik?
if os.path.isfile(f):
# info
print(u'ładuję ', ''.join((f, '...')))
# łądujemy
j = json.load(open(f))
# sprawdzamy co mamy
c = []
for q in questions:
if q[0] in j:
c += [
#':'.join((q[0], str(j[q[0]])))
str(j[q[0]])
]
else:
c+= [
#''.join((q[0], ':'))
''
]
# do csv!
csvdata.writerow(c)