From 439d829400ca302de5f372ed8f4ecb7675f41c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=27rysiek=27=20Wo=C5=BAniak?= Date: Sun, 11 Jan 2015 22:56:34 +0100 Subject: [PATCH] =?UTF-8?q?dodany=20agregator=20wynik=C3=B3w=20z=20jsona?= =?UTF-8?q?=20do=20csv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- socnetsurvey_aggregate.py | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 socnetsurvey_aggregate.py diff --git a/socnetsurvey_aggregate.py b/socnetsurvey_aggregate.py new file mode 100755 index 0000000..613f1e1 --- /dev/null +++ b/socnetsurvey_aggregate.py @@ -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) \ No newline at end of file