From 2a012ebf505a1601bb097ed6547782a4649c767c Mon Sep 17 00:00:00 2001 From: Jan Maximilian Michal <j.michal@stud.uni-goettingen.de> Date: Wed, 2 Nov 2016 12:14:32 +0000 Subject: [PATCH] Cleaning argparse. Added more info to README --- README.md | 33 +++- gen.py | 17 +- hallgrim/IliasXMLCreator/multi.py | 4 - .../gap/1478024104__9310__qpl_82996.xml | 25 +++ .../gap/1478024104__9310__qti_82996.xml | 158 ++++++++++++++++++ notes.md | 8 - 6 files changed, 227 insertions(+), 18 deletions(-) mode change 100644 => 100755 gen.py create mode 100755 hallgrim/ilias_templates/gap/1478024104__9310__qpl_82996.xml create mode 100644 hallgrim/ilias_templates/gap/1478024104__9310__qti_82996.xml delete mode 100644 notes.md diff --git a/README.md b/README.md index bcefd2b..c865f07 100644 --- a/README.md +++ b/README.md @@ -1 +1,32 @@ -*Add a good description / documenation \ No newline at end of file +# Hallgrim - an ILIAS task generator in Python + +## Usage + +Invoke the script with `python3 gen.py -h` in order to see usage. Very limited +until now. + +Example scripts can be found in `scripts/`. + +A first version of the tool that relied on autoilias is still in the repository +(see `generator.py`). It will be removed as soon as the necessary features are +implemented. + +## TODO + +* Add a good description / documentation. +* Add instruction to produce multiple (parametrized) instances of a single +question. +* Add more functionality (gap, alignment, etc.) +* Make parsers more robust. +* reverse ILIAS authentication mechanism for automated upload. + +### Notes + +The final data is produced in three steps: + +1. A python script file with predefined structure that has to export certain +variables in a specified format. +2. An intermediate representation (probably an array that contains relevant +data and assumes unknown properties) +3. The XML structure for one or multiple questions, readable by Ilias. +4. An Ilias object packed as .zip file, ready for upload. diff --git a/gen.py b/gen.py old mode 100644 new mode 100755 index e203714..f7adf2a --- a/gen.py +++ b/gen.py @@ -1,3 +1,5 @@ +#!/usr/local/bin/python3 + try: import mistune except ImportError as err: @@ -14,32 +16,36 @@ from hallgrim.IliasXMLCreator import multi, single import hallgrim.parser from hallgrim.messages import * + def filename_to_module(name): return name.rstrip('.py').replace('/', '.') + def type_selector(type): if 'multiple' in type: return multi if 'single' in type: return single + def parseme(): parser = argparse.ArgumentParser() parser.add_argument( '-o', '--out', - help='Output file', + help='''Specifiy different output file. If no argument is given the Name + of the script is used.''', type=argparse.FileType('w'), metavar='FILE') parser.add_argument( - '-i', - '--input', + 'input', help='Script to execute', metavar='FILE') args = parser.parse_args() return args.out, args.input + def main(): output, script_name = parseme() script = importlib.import_module(filename_to_module(script_name)) @@ -53,9 +59,10 @@ def main(): 'questions': hallgrim.parser.choice_parser(script.choices), } - output = os.path.join('output', script.meta['title']) + '.xml' if not output else output + output = os.path.join( + 'output', script.meta['title']) + '.xml' if not output else output type_selector(script.meta['type']).convert_and_print(data, output) info('Processed "{}" and wrote xml to "{}".'.format(script_name, output)) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/hallgrim/IliasXMLCreator/multi.py b/hallgrim/IliasXMLCreator/multi.py index 28e8c6e..f4a4a21 100644 --- a/hallgrim/IliasXMLCreator/multi.py +++ b/hallgrim/IliasXMLCreator/multi.py @@ -30,8 +30,6 @@ def itemmetadata(type, author, feedback_setting=1): return root ########################################################################## - - def material(content): material = et.Element('material') material.append(simple_elemet( @@ -65,8 +63,6 @@ def presentation(title, question_text, questions, shuffle=True): return root ########################################################################## - - def respcondition(points, count, correct=True): root = et.Element('respcondition', attrib={'continue': 'Yes'}) conditionvar = et.Element('conditionvar') diff --git a/hallgrim/ilias_templates/gap/1478024104__9310__qpl_82996.xml b/hallgrim/ilias_templates/gap/1478024104__9310__qpl_82996.xml new file mode 100755 index 0000000..630f69d --- /dev/null +++ b/hallgrim/ilias_templates/gap/1478024104__9310__qpl_82996.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE Test + SYSTEM 'http://www.ilias.uni-koeln.de/download/dtd/ilias_co.dtd'> +<!--Export of ILIAS Test Questionpool 82996 of installation .--> +<ContentObject Type="Questionpool_Test"> + <MetaData> + <General Structure="Hierarchical"> + <Identifier Catalog="ILIAS" Entry="il_9310_qpl_82996"/> + <Title Language="de">Aufgabentypen aus ILIAS</Title> + <Language Language="de"/> + <Description Language="de">Eine Sammlung von Prototypen, um Aufgabe automatisch generieren zu können.</Description> + <Keyword Language="de"/> + </General> + </MetaData> + <Settings> + <ShowTaxonomies>0</ShowTaxonomies> + <NavTaxonomy>0</NavTaxonomy> + <SkillService>0</SkillService> + </Settings> + <PageObject> + <PageContent> + <Question QRef="il_9310_qst_1662666"/> + </PageContent> + </PageObject> +</ContentObject> \ No newline at end of file diff --git a/hallgrim/ilias_templates/gap/1478024104__9310__qti_82996.xml b/hallgrim/ilias_templates/gap/1478024104__9310__qti_82996.xml new file mode 100644 index 0000000..447d6b3 --- /dev/null +++ b/hallgrim/ilias_templates/gap/1478024104__9310__qti_82996.xml @@ -0,0 +1,158 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE questestinterop + SYSTEM 'ims_qtiasiv1p2p1.dtd'> +<!--Generated by ILIAS XmlWriter--> +<questestinterop> + <item ident="il_9310_qst_1662666" maxattempts="0" title="template Gap "> + <qticomment>Description</qticomment> + <duration>P0Y0M0DT0H30M0S</duration> + <itemmetadata> + <qtimetadata> + <qtimetadatafield> + <fieldlabel>ILIAS_VERSION</fieldlabel> + <fieldentry>5.1.8 2016-08-03</fieldentry> + </qtimetadatafield> + <qtimetadatafield> + <fieldlabel>QUESTIONTYPE</fieldlabel> + <fieldentry>CLOZE QUESTION</fieldentry> + </qtimetadatafield> + <qtimetadatafield> + <fieldlabel>AUTHOR</fieldlabel> + <fieldentry>Jan Maximilian Michal</fieldentry> + </qtimetadatafield> + <qtimetadatafield> + <fieldlabel>additional_cont_edit_mode</fieldlabel> + <fieldentry>default</fieldentry> + </qtimetadatafield> + <qtimetadatafield> + <fieldlabel>externalId</fieldlabel> + <fieldentry>5818dab7ebe8e4.96644801</fieldentry> + </qtimetadatafield> + <qtimetadatafield> + <fieldlabel>textgaprating</fieldlabel> + <fieldentry>ci</fieldentry> + </qtimetadatafield> + <qtimetadatafield> + <fieldlabel>fixedTextLength</fieldlabel> + <fieldentry>20</fieldentry> + </qtimetadatafield> + <qtimetadatafield> + <fieldlabel>identicalScoring</fieldlabel> + <fieldentry>1</fieldentry> + </qtimetadatafield> + <qtimetadatafield> + <fieldlabel>combinations</fieldlabel> + <fieldentry>W10=</fieldentry> + </qtimetadatafield> + </qtimetadata> + </itemmetadata> + <presentation label="template Gap "> + <flow> + <material> + <mattext texttype="text/xhtml"><p>Question text</p></mattext> + </material> + <material> + <mattext texttype="text/xhtml"><p>Ich habe eine lila Lücke </mattext> + </material> + <response_str ident="gap_0" rcardinality="Single"> + <render_fib columns="10" fibtype="String" prompt="Box"/> + </response_str> + <material> + <mattext texttype="text/xhtml">.</p> +<p>Auswahl Lücke </mattext> + </material> + <response_str ident="gap_1" rcardinality="Single"> + <render_choice shuffle="Yes"> + <response_label ident="0"> + <material> + <mattext>Answer 2.1</mattext> + </material> + </response_label> + <response_label ident="1"> + <material> + <mattext>Answer 2.2</mattext> + </material> + </response_label> + <response_label ident="2"> + <material> + <mattext>Answer 2.3</mattext> + </material> + </response_label> + </render_choice> + </response_str> + <material> + <mattext texttype="text/xhtml"></p> +<p>Numerische Lücke</mattext> + </material> + <response_num ident="gap_2" numtype="Decimal" rcardinality="Single"> + <render_fib columns="30" fibtype="Decimal" maxnumber="1" minnumber="-1" prompt="Box"/> + </response_num> + <material> + <mattext texttype="text/xhtml">&lt;/p&gt;</p> +<p></p></mattext> + </material> + </flow> + </presentation> + <resprocessing> + <outcomes> + <decvar/> + </outcomes> + <respcondition continue="Yes"> + <conditionvar> + <varequal respident="gap_0">Answer 1</varequal> + </conditionvar> + <setvar action="Add">3</setvar> + <displayfeedback feedbacktype="Response" linkrefid="0_Response_0"/> + </respcondition> + <respcondition continue="Yes"> + <conditionvar> + <varequal respident="gap_1">Answer 2.1</varequal> + </conditionvar> + <setvar action="Add">20</setvar> + <displayfeedback feedbacktype="Response" linkrefid="1_Response_0"/> + </respcondition> + <respcondition continue="Yes"> + <conditionvar> + <varequal respident="gap_1">Answer 2.3</varequal> + </conditionvar> + <setvar action="Add">0</setvar> + <displayfeedback feedbacktype="Response" linkrefid="1_Response_2"/> + </respcondition> + <respcondition continue="Yes"> + <conditionvar> + <varequal respident="gap_1">Answer 2.2</varequal> + </conditionvar> + <setvar action="Add">0</setvar> + <displayfeedback feedbacktype="Response" linkrefid="1_Response_1"/> + </respcondition> + <respcondition continue="Yes"> + <conditionvar> + <varequal respident="gap_2">0</varequal> + </conditionvar> + <setvar action="Add">33</setvar> + <displayfeedback feedbacktype="Response" linkrefid="2_Response_0"/> + </respcondition> + </resprocessing> + <itemfeedback ident="0" view="All"> + <flow_mat> + <material> + <mattext texttype="text/plain"/> + </material> + </flow_mat> + </itemfeedback> + <itemfeedback ident="1" view="All"> + <flow_mat> + <material> + <mattext texttype="text/plain"/> + </material> + </flow_mat> + </itemfeedback> + <itemfeedback ident="2" view="All"> + <flow_mat> + <material> + <mattext texttype="text/plain"/> + </material> + </flow_mat> + </itemfeedback> + </item> +</questestinterop> \ No newline at end of file diff --git a/notes.md b/notes.md deleted file mode 100644 index c3e1d77..0000000 --- a/notes.md +++ /dev/null @@ -1,8 +0,0 @@ -### Notes - -Every task has to follow a certain structur: - -* generate_form -* generate_solution -* generate_task -* other outputs -- GitLab