Questionaire-Definition mit allen Seiten aufsammeln
This commit is contained in:
parent
2e5685ea0d
commit
05811c6579
2 changed files with 51 additions and 19 deletions
|
|
@ -276,15 +276,21 @@
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684425234772" ID="ID_829734331" MODIFIED="1684521730288" TEXT="SoSci-Questionaire verarbeiten">
|
||||
<icon BUILTIN="full-2"/>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1684425355743" ID="ID_336090024" MODIFIED="1684425365214" TEXT="das nested XML extrahieren und parsen"/>
|
||||
<node CREATED="1684425365798" ID="ID_1030356083" MODIFIED="1684425376845" TEXT="die Seitenstruktur navigieren"/>
|
||||
<node CREATED="1684425378039" ID="ID_960847395" MODIFIED="1684425420299" TEXT="jedes konkret referenzierte Block-Element aus der Map holen">
|
||||
<linktarget COLOR="#a9b4c1" DESTINATION="ID_960847395" ENDARROW="Default" ENDINCLINATION="187;0;" ID="Arrow_ID_184243819" SOURCE="ID_1210419956" STARTARROW="None" STARTINCLINATION="187;0;"/>
|
||||
<node COLOR="#338800" CREATED="1684425234772" ID="ID_829734331" MODIFIED="1684531690122" TEXT="SoSci-Questionaire verarbeiten">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1684425355743" ID="ID_336090024" MODIFIED="1684531685063" TEXT="das nested XML extrahieren und parsen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684425365798" ID="ID_1030356083" MODIFIED="1684531686634" TEXT="die Seitenstruktur navigieren">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684425378039" ID="ID_960847395" MODIFIED="1684531688361" TEXT="jedes konkret referenzierte Block-Element aus der Map holen">
|
||||
<linktarget COLOR="#a9b4c1" DESTINATION="ID_960847395" ENDARROW="Default" ENDINCLINATION="187;0;" ID="Arrow_ID_184243819" SOURCE="ID_1210419956" STARTARROW="None" STARTINCLINATION="187;0;"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1684425424682" ID="ID_951583805" MODIFIED="1684531689077" TEXT="in eine mehrstufige Liste ablegen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node CREATED="1684425424682" ID="ID_951583805" MODIFIED="1684425432315" TEXT="in eine mehrstufige Liste ablegen"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1684425268727" ID="ID_1433452218" MODIFIED="1684521730288" TEXT="Word-Content generieren">
|
||||
<icon BUILTIN="full-3"/>
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ WORD_OUTPUT='Thesis-Fragebogen-import.docx'
|
|||
|
||||
def convertSosci2Word():
|
||||
# Schritt-1 : alle Frage-Definitionen aufsammeln
|
||||
collectQuestionDefinitions()
|
||||
questions = collectQuestionDefinitions()
|
||||
# Schritt-2 : die Fragen in der Reihenfolge vom Questionaire
|
||||
questionaire = buildQuestionaire(questions)
|
||||
## TODO
|
||||
# Schritt-3 : Questionaire in das Word-Dokument ausgeben
|
||||
## TODO
|
||||
|
|
@ -105,15 +106,12 @@ def collectQuestionDefinitions():
|
|||
#
|
||||
questions = {}
|
||||
#
|
||||
print("Extracting Question Definitions...")
|
||||
root = ElementTree.parse(SOSCI_XML).getroot()
|
||||
for section in root.findall('section'):
|
||||
title = section.find('title')
|
||||
id_prefix = getSpecificID(section)
|
||||
print("Section: Title »%s« Prefix=%s" % (title.text,id_prefix))
|
||||
|
||||
for question in section.findall('question'):
|
||||
title = question.find('title').text
|
||||
desc = question.find('description').text
|
||||
questionType = question.find('class').text
|
||||
id_suffix = getSpecificID(question)
|
||||
id_suffix = int(id_suffix)
|
||||
|
|
@ -131,12 +129,9 @@ def collectQuestionDefinitions():
|
|||
|
||||
questions[questionID] = element
|
||||
|
||||
print(questions.keys())
|
||||
for key in questions.keys():
|
||||
quest = questions[key]
|
||||
print("Question: ID=%s type=%s desc=%s" % (quest.qid, type(quest), quest.desc))
|
||||
print(quest.dump())
|
||||
|
||||
# Rückgabe: ein Dictionary mit allen bekannten Question-Elementen (keyed by ID)
|
||||
return questions
|
||||
|
||||
|
||||
|
||||
# Hilfsmittel für SoSci-XML: extrahiert ein ID-Element, das eingeschachtelt in <attributes.specific> liegt
|
||||
|
|
@ -146,6 +141,37 @@ def getSpecificID(element):
|
|||
|
||||
|
||||
|
||||
def buildQuestionaire(questions):
|
||||
#
|
||||
print("Building Questionaire Pages...")
|
||||
#
|
||||
root = ElementTree.parse(SOSCI_XML).getroot()
|
||||
quest = root.find('questionnaire').find('attributes.specific')
|
||||
quest = next(a for a in quest.findall('attr') if a.get('id') == 'content')
|
||||
quest = quest.text
|
||||
|
||||
questionaire = []
|
||||
|
||||
questRoot = ElementTree.fromstring(quest)
|
||||
for page in questRoot.findall('page'):
|
||||
if page.get('ident') == 'I':
|
||||
continue # die erste Seite enthält den Einführungstext. Den fügen wir später manuell ein
|
||||
#
|
||||
info = page.find('info').text
|
||||
print('Seite: %s' % info)
|
||||
questionsOnThisPage = []
|
||||
for quest in page.findall('question'):
|
||||
questionID = quest.get('id')
|
||||
print(questionID)
|
||||
element = questions[questionID]
|
||||
print(element.dump())
|
||||
questionsOnThisPage.append(element)
|
||||
|
||||
questionaire.append((info, questionsOnThisPage))
|
||||
#
|
||||
print(questionaire)
|
||||
return questionaire
|
||||
|
||||
|
||||
# ---- Hilfsfunktionen
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue