Exemplo n.º 1
0
    def toxml(self):
        part = Part.toxml(self)
        part.append(makeTree(['answer',
                                ['correctanswer',['math']],
                                ['checking',
                                        ['range']
                                ]
                            ]))

        answer = part.find('answer')
        answer.attrib = {
                'checkvariablenames': strcons_fix(self.checkVariableNames),
                'showPreview': strcons_fix(self.showPreview),
        }
        correctAnswer = answer.find('correctanswer')
        correctAnswer.attrib = {'simplification': strcons(self.answerSimplification)}
        correctAnswer.find('math').text = strcons(self.answer)
        
        checking = answer.find('checking')
        checking.attrib = {
                'type': strcons(self.checkingType),
                'accuracy': strcons_fix(self.checkingAccuracy),
                'failurerate': strcons_fix(self.failureRate)
        }
        checking.find('range').attrib = {'start': strcons_fix(self.vsetRangeStart), 'end': strcons_fix(self.vsetRangeEnd),  'points': strcons_fix(self.vsetRangePoints)}
        answer.append(self.maxLength.toxml())
        answer.append(self.minLength.toxml())
        answer.append(self.mustHave.toxml())
        answer.append(self.notAllowed.toxml())
        answer.append(self.expectedVariableNames.toxml())
        
        return part
Exemplo n.º 2
0
	def toxml(self):
		question = makeTree(['question',
								['statement'],
								['parts'],
								['advice'],
								['notes'],
								['variables'],
								['functions'],
								['preambles'],
								['rulesets']
							])

		question.attrib = {'name': strcons_fix(self.name)}
		question.find('statement').append(makeContentNode(self.statement))
		question.find('advice').append(makeContentNode(self.advice))

		parts = question.find('parts')
		for part in self.parts:
			parts.append(part.toxml())

		variables = question.find('variables')
		for variable in self.variables:
			variables.append(variable.toxml())
		variables.attrib = {
			'condition': strcons_fix(self.variablesTest['condition']),
			'maxRuns': strcons_fix(self.variablesTest['maxRuns']),
		}

		functions = question.find('functions')
		for function in self.functions:
			functions.append(function.toxml())

		rules = question.find('rulesets')
		for name in self.rulesets.keys():
			st = etree.Element('set',{'name':name})
			for rule in self.rulesets[name]:
				if isinstance(rule,str):
					st.append(etree.Element('include',{'name':rule}))
				else:
					st.append(rule.toxml())
			rules.append(st)

		preambles = question.find('preambles')
		css_preamble = etree.Element('preamble')
		css_preamble.attrib = {
			'language': 'css'
		}
		css_preamble.text = strcons_fix(self.preamble['css'])
		preambles.append(css_preamble)
		js_preamble = etree.Element('preamble')
		js_preamble.attrib = {
			'language': 'js'
		}
		js_preamble.text = strcons_fix(self.preamble['js'])
		preambles.append(js_preamble)
		preambles.attrib = {
			'nosubvars': 'true'
		}

		return question
Exemplo n.º 3
0
	def toxml(self):
		replacement = etree.Element('replace')
		replacement.attrib = {
			'variable': strcons_fix(self.variable),
			'part': strcons_fix(self.part),
			'must_go_first': strcons_fix(self.must_go_first),
		}
		return replacement
Exemplo n.º 4
0
	def toxml(self):
		part = Part.toxml(self)
		appendMany(part,['displayanswer','correctanswer','case'])
		
		part.find('displayanswer').append(makeContentNode(self.displayAnswer))

		part.find('correctanswer').text = strcons_fix(self.answer)

		part.find('case').attrib = {'sensitive': strcons_fix(self.caseSensitive), 'partialcredit': strcons_fix(self.partialCredit)+'%'}

		return part
Exemplo n.º 5
0
	def toxml(self):
		rule = makeTree(['ruledef',
							['conditions']
						])
		rule.attrib = {	'pattern': strcons_fix(self.pattern),
						'result': strcons_fix(self.result)
						}
		conditions = rule.find('conditions')
		for condition in self.conditions:
			conditions.append(etree.fromstring('<condition>'+condition+'</condition>'))

		return rule
Exemplo n.º 6
0
 def toxml(self):
     part = super(CustomPart,self).toxml()
     part.attrib['custom'] = 'true'
     part.append(makeTree(['settings']))
     settings = part.find('settings')
     for name,value in self.settings.items():
         setting = etree.Element('setting')
         setting.attrib = {
             'name': strcons_fix(name),
             'value': strcons_fix(json.dumps(value))
         }
         settings.append(setting)
     return part
Exemplo n.º 7
0
    def toxml(self):
        part = makeTree(['part',
                            ['prompt'],
                            ['steps'],
                            ['scripts'],
                            ['adaptivemarking',
                                ['variablereplacements'],
                            ],
                            ['markingalgorithm'],
                        ])

        part.attrib = {
            'usecustomname': strcons_fix(self.useCustomName),
            'customName': strcons_fix(self.customName),
            'type': strcons(self.kind), 
            'marks': strcons_fix(self.marks), 
            'stepspenalty': strcons_fix(self.stepsPenalty), 
            'enableminimummarks': strcons_fix(self.enableMinimumMarks), 
            'minimummarks': strcons_fix(self.minimumMarks), 
            'showcorrectanswer': strcons_fix(self.showCorrectAnswer),
            'showfeedbackicon': strcons_fix(self.showFeedbackIcon)
        }

        part.find('prompt').append(makeContentNode(self.prompt))

        steps = part.find('steps')
        for step in self.steps:
            steps.append(step.toxml())

        scripts = part.find('scripts')
        for name,script_dict in self.scripts.items():
            script_element = etree.Element('script')
            script_element.attrib = {
                'name': name,
                'order': script_dict.get('order','instead')
            }
            script_element.text = strcons(script_dict.get('script',''))
            scripts.append(script_element)

        marking_algorithm = part.find('markingalgorithm')
        marking_algorithm.text = strcons(self.customMarkingAlgorithm)
        marking_algorithm.attrib = {
            'extend': strcons_fix(self.extendBaseMarkingAlgorithm),
        }

        variable_replacements = part.find('adaptivemarking/variablereplacements')
        variable_replacements.attrib = {
            'strategy': self.variableReplacementStrategy
        }
        for vr in self.variable_replacements:
            replacement = vr.toxml()
            variable_replacements.append(replacement)

        return part
Exemplo n.º 8
0
	def toxml(self):
		restriction = makeTree([self.name,'message'])

		restriction.attrib = {'partialcredit': strcons_fix(self.partialCredit)+'%', 'showstrings': strcons_fix(self.showStrings)}
		if int(self.length)>=0:
			restriction.attrib['length'] = strcons_fix(self.length)

		for s in self.strings:
			string = etree.Element('string')
			string.text = strcons_fix(s)
			restriction.append(string)

		restriction.find('message').append(makeContentNode(self.message))

		return restriction
Exemplo n.º 9
0
    def toxml(self):
        self.marks = 0

        prompt = self.prompt

        def replace_gapfill(m):
            d=int(m.group(1))
            if len(self.gaps)<=d:
                raise ExamError("Reference to an undefined gap in a gapfill part (%i,%i)" %(d,len(self.gaps)))
            return '<gapfill reference="%s" />' % d

        self.prompt = re.sub(r"\[\[(\d+?)\]\]",replace_gapfill,self.prompt)

        part = super(GapFillPart,self).toxml()
        self.prompt = prompt

        gaps = etree.Element('gaps')
        part.append(gaps)

        for gap in self.gaps:
            gaps.append(gap.toxml())

        marking = etree.Element('marking')
        marking.attrib = {
            'sortanswers': strcons_fix(self.sortAnswers),
        }
        part.append(marking)

        return part
Exemplo n.º 10
0
	def tostring(self):
		try:
			xml = self.toxml()
			indent(xml)
			return(etree.tostring(xml,encoding="UTF-8").decode('utf-8'))
		except etree.ParseError as err:
			raise ExamError('XML Error: %s' % strcons_fix(err))
Exemplo n.º 11
0
	def toxml(self):
		function = makeTree(['function',
								['parameters']
							])
		function.attrib = { 'name': strcons_fix(self.name),
							'outtype': strcons_fix(self.type),
							'definition': strcons_fix(self.definition),
							'language': strcons_fix(self.language)
							}
		
		parameters = function.find('parameters')

		for pname,ptype in self.parameters:
			parameter = etree.Element('parameter',{'name': pname, 'type': ptype})
			parameters.append(parameter)

		return function
Exemplo n.º 12
0
    def toxml(self):
        restriction = makeTree([self.name,'message'])

        restriction.attrib = {'partialcredit': strcons_fix(self.partialCredit)+'%'}

        restriction.find('message').append(makeContentNode(self.message))

        return restriction
Exemplo n.º 13
0
    def toxml(self):
        part = makeTree(['part',
                            ['prompt'],
                            ['steps'],
                            ['scripts'],
                            ['adaptivemarking',
                                ['variablereplacements'],
                            ]
                        ])

        part.attrib = {
            'type': strcons(self.kind), 
            'marks': strcons_fix(self.marks), 
            'stepspenalty': strcons_fix(self.stepsPenalty), 
            'enableminimummarks': strcons_fix(self.enableMinimumMarks), 
            'minimummarks': strcons_fix(self.minimumMarks), 
            'showcorrectanswer': strcons_fix(self.showCorrectAnswer)
        }

        part.find('prompt').append(makeContentNode(self.prompt))

        steps = part.find('steps')
        for step in self.steps:
            steps.append(step.toxml())

        scripts = part.find('scripts')
        for name,script_dict in self.scripts.items():
            script_element = etree.Element('script')
            script_element.attrib = {
                'name': name,
                'order': script_dict.get('order','instead')
            }
            script_element.text = strcons(script_dict.get('script',''))
            scripts.append(script_element)

        variable_replacements = part.find('adaptivemarking/variablereplacements')
        variable_replacements.attrib = {
            'strategy': self.variableReplacementStrategy
        }
        for vr in self.variable_replacements:
            replacement = vr.toxml()
            variable_replacements.append(replacement)

        return part
Exemplo n.º 14
0
    def toxml(self):
        restriction = super().toxml()

        restriction.attrib['showstrings'] = strcons_fix(self.showStrings)

        for s in self.strings:
            string = etree.Element('string')
            string.text = strcons(s)
            restriction.append(string)

        return restriction
Exemplo n.º 15
0
def makeTree(struct):
    if struct == list(struct):
        name = struct[0]
        elem = etree.Element(name)
        for x in struct[1:]:
            elem.append(makeTree(x))
        return elem
    elif struct == strcons_fix(struct):
        return etree.Element(struct)
    elif etree.iselement(struct):
        return struct
Exemplo n.º 16
0
    def toxml(self):
        part = super(JMEPart,self).toxml()
        part.append(makeTree(['answer',
                                ['correctanswer',['math']],
                                ['checking',
                                        ['range'],
                                        ['valuegenerators'],
                                ]
                            ]))

        answer = part.find('answer')
        answer.attrib = {
                'checkvariablenames': strcons_fix(self.checkVariableNames),
                'showPreview': strcons_fix(self.showPreview),
        }
        correctAnswer = answer.find('correctanswer')
        correctAnswer.attrib = {'simplification': strcons(self.answerSimplification)}
        correctAnswer.find('math').text = strcons(self.answer)
        
        checking = answer.find('checking')
        checking.attrib = {
                'type': strcons(self.checkingType),
                'accuracy': strcons_fix(self.checkingAccuracy),
                'failurerate': strcons_fix(self.failureRate)
        }
        checking.find('range').attrib = {'start': strcons_fix(self.vsetRangeStart), 'end': strcons_fix(self.vsetRangeEnd),  'points': strcons_fix(self.vsetRangePoints)}

        valueGenerators = checking.find('valuegenerators')
        for g in self.valueGenerators:
            generator = etree.Element('generator')
            generator.attrib = {'name': g['name'], 'value': g['value']}
            valueGenerators.append(generator)

        answer.append(self.maxLength.toxml())
        answer.append(self.minLength.toxml())
        answer.append(self.mustHave.toxml())
        answer.append(self.notAllowed.toxml())
        answer.append(self.mustMatchPattern.toxml())

        return part
Exemplo n.º 17
0
	def toxml(self):
		root = makeTree(['exam',
							['settings',
								['navigation'],
								['timing'],
								['feedback',
									['advice']
								],
								['rulesets']
							],
							['functions'],
							['variables'],
							['questions']
						])
		root.attrib = {
				'name': strcons_fix(self.name),
				'percentPass': strcons_fix(self.percentPass)+'%',
			}
		
		settings = root.find('settings')

		nav = settings.find('navigation')
		nav.attrib = {
			'allowregen': strcons_fix(self.navigation['allowregen']),
			'reverse': strcons_fix(self.navigation['reverse']), 
			'browse': strcons_fix(self.navigation['browse']),
			'showfrontpage': strcons_fix(self.navigation['showfrontpage']),
			'showresultspage': strcons_fix(self.navigation['showresultspage']),
			'preventleave': strcons_fix(self.navigation['preventleave'])
		}

		nav.append(self.navigation['onleave'].toxml())

		timing = settings.find('timing')
		timing.attrib = {
				'duration': strcons_fix(self.duration),
				'allowPause': strcons_fix(self.timing['allowPause']),
		}
		timing.append(self.timing['timeout'].toxml())
		timing.append(self.timing['timedwarning'].toxml())

		feedback = settings.find('feedback')
		feedback.attrib = {
				'showactualmark': strcons_fix(self.showactualmark),
				'showtotalmark': strcons_fix(self.showtotalmark),
				'showanswerstate': strcons_fix(self.showanswerstate),
				'allowrevealanswer': strcons_fix(self.allowrevealanswer)
		}
		feedback.find('advice').attrib = {'type': strcons_fix(self.adviceType), 'threshold': strcons_fix(self.adviceGlobalThreshold)}

		rules = settings.find('rulesets')
		for name in self.rulesets.keys():
			st = etree.Element('set',{'name':name})
			for rule in self.rulesets[name]:
				if isinstance(rule,str):
					st.append(etree.Element('include',{'name':rule}))
				else:
					st.append(rule.toxml())
			rules.append(st)

		variables = root.find('variables')
		for variable in self.variables:
			variables.append(variable.toxml())

		functions = root.find('functions')
		for function in self.functions:
			functions.append(function.toxml())

		questions = root.find('questions')
		questions.attrib = {
				'shuffle': strcons_fix(self.shuffleQuestions),
				'all': strcons_fix(self.allQuestions),
				'pick': strcons_fix(self.pickQuestions),
		}

		for q in self.questions:
			questions.append(q.toxml())

		return root
Exemplo n.º 18
0
	def toxml(self):
		event = makeTree(['event'])
		event.attrib = {'type': strcons_fix(self.kind), 'action': strcons_fix(self.action)}
		event.append(makeContentNode(self.message))
		return event
Exemplo n.º 19
0
	def toxml(self):
		variable = makeTree(['variable',['value']])
		variable.attrib = {'name': strcons_fix(self.name)}
		variable.find('value').text = strcons_fix(self.definition)
		return variable
Exemplo n.º 20
0
    def toxml(self):
        root = makeTree(['exam',
                            ['settings',
                                ['navigation'],
                                ['timing'],
                                ['feedback',
                                    ['intro'],
                                    ['feedbackmessages'],
                                ],
                                ['rulesets']
                            ],
                            ['functions'],
                            ['variables'],
                            ['question_groups'],
                        ])
        root.attrib = {
                'name': strcons(self.name),
                'percentPass': strcons_fix(self.percentPass)+'%',
            }
        
        settings = root.find('settings')

        nav = settings.find('navigation')
        nav.attrib = {
            'allowregen': strcons_fix(self.navigation['allowregen']),
            'reverse': strcons_fix(self.navigation['reverse']), 
            'browse': strcons_fix(self.navigation['browse']),
            'showfrontpage': strcons_fix(self.navigation['showfrontpage']),
            'showresultspage': strcons_fix(self.navigation['showresultspage']),
            'preventleave': strcons_fix(self.navigation['preventleave']),
            'startpassword': strcons_fix(self.navigation['startpassword'])
        }

        nav.append(self.navigation['onleave'].toxml())

        timing = settings.find('timing')
        timing.attrib = {
                'duration': strcons_fix(self.duration),
                'allowPause': strcons_fix(self.timing['allowPause']),
        }
        timing.append(self.timing['timeout'].toxml())
        timing.append(self.timing['timedwarning'].toxml())

        feedback = settings.find('feedback')
        feedback.attrib = {
                'showactualmark': strcons_fix(self.showactualmark),
                'showtotalmark': strcons_fix(self.showtotalmark),
                'showanswerstate': strcons_fix(self.showanswerstate),
                'allowrevealanswer': strcons_fix(self.allowrevealanswer),
                'showstudentname': strcons_fix(self.showstudentname),
        }
        feedback.find('intro').append(makeContentNode(self.intro))
        feedbackmessages = feedback.find('feedbackmessages')
        for fm in self.feedbackMessages:
            feedbackmessages.append(fm.toxml())

        rules = settings.find('rulesets')
        for name in self.rulesets.keys():
            st = etree.Element('set',{'name':name})
            for rule in self.rulesets[name]:
                if isinstance(rule,str):
                    st.append(etree.Element('include',{'name':rule}))
                else:
                    st.append(rule.toxml())
            rules.append(st)

        variables = root.find('variables')
        for variable in self.variables:
            variables.append(variable.toxml())

        functions = root.find('functions')
        for function in self.functions:
            functions.append(function.toxml())

        question_groups = root.find('question_groups')
        question_groups.attrib = {
            'showQuestionGroupNames': strcons(self.showQuestionGroupNames),
        }

        for qg in self.question_groups:
            question_groups.append(qg.toxml())

        return root
Exemplo n.º 21
0
    def toxml(self):
        part = super(MultipleChoicePart,self).toxml()
        appendMany(part,['choices','answers','layout',['marking','matrix','maxmarks','minmarks','distractors','warning']])

        part.attrib['showcellanswerstate'] = strcons_fix(self.showCellAnswerState)

        choices = part.find('choices')
        choices.attrib = {
            'minimumexpected': strcons_fix(self.minAnswers),
            'maximumexpected': strcons_fix(self.maxAnswers),
            'displaycolumns': strcons_fix(self.displayColumns),
            'shuffle': strcons_fix(self.shuffleChoices),
            'displaytype': strcons(self.displayType),
        }

        if isinstance(self.choices,str):
            choices.attrib['def'] = strcons(self.choices)
        else:
            for choice in self.choices:
                choices.append(makeTree(['choice',makeContentNode(choice)]))

        answers = part.find('answers')
        answers.attrib = {'shuffle': strcons_fix(self.shuffleAnswers)}
        if isinstance(self.answers,str):
            answers.attrib['def'] = strcons(self.answers)
        else:
            for answer in self.answers:
                answers.append(makeTree(['answer',makeContentNode(answer)]))

        layout = part.find('layout')
        layout.attrib = {
            'type': self.layoutType,
            'expression': self.layoutExpression,
        }

        marking = part.find('marking')
        marking.find('maxmarks').attrib = {'enabled': strcons_fix(self.maxMarksEnabled), 'value': strcons_fix(self.maxMarks)}
        marking.find('minmarks').attrib = {'enabled': strcons_fix(self.minMarksEnabled), 'value': strcons_fix(self.minMarks)}
        matrix = marking.find('matrix')
        if isinstance(self.matrix,str):
            matrix.attrib = {'def': strcons(self.matrix)}
        else:
            for i in range(len(self.matrix)):
                for j in range(len(self.matrix[i])):
                    mark = etree.Element('mark',{
                        'answerindex': strcons_fix(j), 
                        'choiceindex': strcons_fix(i), 
                        'value': strcons_fix(self.matrix[i][j])
                        })
                    matrix.append(mark)

        distractors = marking.find('distractors')
        for i in range(len(self.distractors)):
            for j in range(len(self.distractors[i])):
                distractor = etree.Element('distractor',{
                    'choiceindex': strcons_fix(i),
                    'answerindex': strcons_fix(j)
                })
                distractor.append(makeContentNode(self.distractors[i][j]))
                distractors.append(distractor)

        warning = marking.find('warning')
        warning.attrib = {'type': self.warningType}

        return part
Exemplo n.º 22
0
    def toxml(self):
        restriction = super().toxml()
        restriction.attrib['pattern'] = strcons_fix(self.pattern)
        restriction.attrib['nameToCompare'] = strcons_fix(self.nameToCompare)

        return restriction
Exemplo n.º 23
0
    def toxml(self):
        part = super(MatrixEntryPart, self).toxml()
        part.append(makeTree([
            'answer',
            ['precision', 'message'],
        ]))

        answer = part.find('answer')
        answer.attrib = {
            'correctanswer': strcons(self.correctAnswer),
            'correctanswerfractions': strcons_fix(self.correctAnswerFractions),
            'rows': strcons_fix(self.numRows),
            'columns': strcons_fix(self.numColumns),
            'allowresize': strcons_fix(self.allowResize),
            'tolerance': strcons_fix(self.tolerance),
            'markpercell': strcons_fix(self.markPerCell),
            'allowfractions': strcons_fix(self.allowFractions),
        }

        answer.find('precision').attrib = {
            'type': strcons_fix(self.precisionType),
            'precision': strcons_fix(self.precision),
            'partialcredit': strcons_fix(self.precisionPartialCredit) + '%',
            'strict': strcons_fix(self.strictPrecision)
        }
        answer.find('precision/message').append(
            makeContentNode(self.precisionMessage))

        return part
Exemplo n.º 24
0
    def toxml(self):
        part = super(MatrixEntryPart,self).toxml()
        part.append(makeTree(['answer',
                                ['precision','message'],
                            ]
        ))

        answer = part.find('answer')
        answer.attrib = {
            'correctanswer': strcons(self.correctAnswer),
            'correctanswerfractions': strcons_fix(self.correctAnswerFractions),
            'rows': strcons_fix(self.numRows),
            'columns': strcons_fix(self.numColumns),
            'allowresize': strcons_fix(self.allowResize),
            'tolerance': strcons_fix(self.tolerance),
            'markpercell': strcons_fix(self.markPerCell),
            'allowfractions': strcons_fix(self.allowFractions),
        }

        answer.find('precision').attrib = {
            'type': strcons_fix(self.precisionType), 
            'precision': strcons_fix(self.precision), 
            'partialcredit': strcons_fix(self.precisionPartialCredit)+'%',
            'strict': strcons_fix(self.strictPrecision)
        }
        answer.find('precision/message').append(makeContentNode(self.precisionMessage))

        return part
Exemplo n.º 25
0
    def toxml(self):
        part = super(NumberEntryPart, self).toxml()
        part.append(makeTree([
            'answer',
            ['precision', 'message'],
        ]))

        answer = part.find('answer')
        answer.attrib = {
            'checkingType': strcons(self.checkingType),
            'inputstep': strcons_fix(self.inputStep),
            'allowfractions': strcons_fix(self.allowFractions),
            'showfractionhint': strcons_fix(self.showFractionHint),
            'notationstyles': strcons_fix(','.join(self.notationStyles)),
            'correctanswerfraction': strcons_fix(self.correctAnswerFraction),
            'correctanswerstyle': strcons_fix(self.correctAnswerStyle),
            'mustbereduced': strcons_fix(self.mustBeReduced),
            'mustbereducedpc': strcons_fix(self.mustBeReducedPC) + '%'
        }
        if self.checkingType == 'range':
            answer.attrib['minvalue'] = strcons_fix(self.minvalue)
            answer.attrib['maxvalue'] = strcons_fix(self.maxvalue)
        else:
            answer.attrib['answer'] = strcons_fix(self.answer)
            answer.attrib['accuracy'] = strcons_fix(self.checkingAccuracy)
        answer.find('precision').attrib = {
            'type': strcons(self.precisionType),
            'precision': strcons_fix(self.precision),
            'partialcredit': strcons_fix(self.precisionPartialCredit) + '%',
            'strict': strcons_fix(self.strictPrecision),
            'showprecisionhint': strcons_fix(self.showPrecisionHint),
        }
        answer.find('precision/message').append(
            makeContentNode(self.precisionMessage))

        return part
Exemplo n.º 26
0
    def toxml(self):
        restriction = super().toxml()
        restriction.attrib['pattern'] = strcons_fix(self.pattern)
        restriction.attrib['nameToCompare'] = strcons_fix(self.nameToCompare)

        return restriction
Exemplo n.º 27
0
    def toxml(self):
        part = Part.toxml(self)
        part.append(
            makeTree([
                'answer',
                ['allowonlyintegeranswers'],
                ['precision', 'message'],
            ]))

        answer = part.find('answer')
        answer.attrib = {
            'checkingType': strcons(self.checkingType),
            'inputstep': strcons_fix(self.inputStep),
            'allowfractions': strcons_fix(self.allowFractions),
            'correctanswerfraction': strcons_fix(self.correctAnswerFraction),
        }
        if self.checkingType == 'range':
            answer.attrib['minvalue'] = strcons_fix(self.minvalue)
            answer.attrib['maxvalue'] = strcons_fix(self.maxvalue)
        else:
            answer.attrib['answer'] = strcons_fix(self.answer)
            answer.attrib['accuracy'] = strcons_fix(self.checkingAccuracy)
        answer.find('allowonlyintegeranswers').attrib = {
            'value': strcons_fix(self.integerAnswer),
            'partialcredit': strcons_fix(self.integerPartialCredit) + '%'
        }
        answer.find('precision').attrib = {
            'type': strcons(self.precisionType),
            'precision': strcons_fix(self.precision),
            'partialcredit': strcons_fix(self.precisionPartialCredit) + '%',
            'strict': strcons_fix(self.strictPrecision),
            'showprecisionhint': strcons_fix(self.showPrecisionHint),
        }
        answer.find('precision/message').append(
            makeContentNode(self.precisionMessage))

        return part
Exemplo n.º 28
0
    def toxml(self):
        restriction = super().toxml()
        if int(self.length)>=0:
            restriction.attrib['length'] = strcons_fix(self.length)

        return restriction
Exemplo n.º 29
0
	def toxml(self):
		part = Part.toxml(self)
		part.append(makeTree(['answer',
								['allowonlyintegeranswers'],
								['precision','message'],
							]
							))

		answer = part.find('answer')
		answer.attrib = {
				'checkingType': strcons_fix(self.checkingType),
				'inputstep': strcons_fix(self.inputStep),
				'allowfractions': strcons_fix(self.allowFractions),
				'correctanswerfraction': strcons_fix(self.correctAnswerFraction),
				}
		if self.checkingType == 'range':
			answer.attrib['minvalue'] = strcons_fix(self.minvalue)
			answer.attrib['maxvalue'] = strcons_fix(self.maxvalue)
		else:
			answer.attrib['answer'] = strcons_fix(self.answer)
			answer.attrib['accuracy'] = strcons_fix(self.checkingAccuracy)
		answer.find('allowonlyintegeranswers').attrib = {'value': strcons_fix(self.integerAnswer), 'partialcredit': strcons_fix(self.integerPartialCredit)+'%'}
		answer.find('precision').attrib = {
			'type': strcons_fix(self.precisionType), 
			'precision': strcons_fix(self.precision), 
			'partialcredit': strcons_fix(self.precisionPartialCredit)+'%',
			'strict': strcons_fix(self.strictPrecision)
		}
		answer.find('precision/message').append(makeContentNode(self.precisionMessage))

		return part
Exemplo n.º 30
0
    def toxml(self):
        root = makeTree([
            'exam',
            [
                'settings', ['navigation'], ['timing'],
                [
                    'feedback',
                    ['intro'],
                    ['feedbackmessages'],
                ], ['rulesets']
            ],
            ['functions'],
            ['variables'],
            ['question_groups'],
        ])
        root.attrib = {
            'name': strcons(self.name),
            'percentPass': strcons_fix(self.percentPass) + '%',
        }

        settings = root.find('settings')

        nav = settings.find('navigation')
        nav.attrib = {
            'allowregen': strcons_fix(self.navigation['allowregen']),
            'reverse': strcons_fix(self.navigation['reverse']),
            'browse': strcons_fix(self.navigation['browse']),
            'allowsteps': strcons_fix(self.navigation['allowsteps']),
            'showfrontpage': strcons_fix(self.navigation['showfrontpage']),
            'showresultspage': strcons_fix(self.navigation['showresultspage']),
            'preventleave': strcons_fix(self.navigation['preventleave']),
            'startpassword': strcons_fix(self.navigation['startpassword'])
        }

        nav.append(self.navigation['onleave'].toxml())

        timing = settings.find('timing')
        timing.attrib = {
            'duration': strcons_fix(self.duration),
            'allowPause': strcons_fix(self.timing['allowPause']),
        }
        timing.append(self.timing['timeout'].toxml())
        timing.append(self.timing['timedwarning'].toxml())

        feedback = settings.find('feedback')
        feedback.attrib = {
            'showactualmark': strcons_fix(self.showactualmark),
            'showtotalmark': strcons_fix(self.showtotalmark),
            'showanswerstate': strcons_fix(self.showanswerstate),
            'allowrevealanswer': strcons_fix(self.allowrevealanswer),
            'showstudentname': strcons_fix(self.showstudentname),
            'reviewshowscore': strcons_fix(self.reviewshowscore),
            'reviewshowfeedback': strcons_fix(self.reviewshowfeedback),
            'reviewshowexpectedanswer':
            strcons_fix(self.reviewshowexpectedanswer),
            'reviewshowadvice': strcons_fix(self.reviewshowadvice),
        }
        feedback.find('intro').append(makeContentNode(self.intro))
        feedbackmessages = feedback.find('feedbackmessages')
        for fm in self.feedbackMessages:
            feedbackmessages.append(fm.toxml())

        rules = settings.find('rulesets')
        for name in self.rulesets.keys():
            st = etree.Element('set', {'name': name})
            for rule in self.rulesets[name]:
                if isinstance(rule, str):
                    st.append(etree.Element('include', {'name': rule}))
                else:
                    st.append(rule.toxml())
            rules.append(st)

        variables = root.find('variables')
        for variable in self.variables:
            variables.append(variable.toxml())

        functions = root.find('functions')
        for function in self.functions:
            functions.append(function.toxml())

        question_groups = root.find('question_groups')
        question_groups.attrib = {
            'showQuestionGroupNames': strcons(self.showQuestionGroupNames),
            'shuffleQuestionGroups': strcons(self.shuffleQuestionGroups),
        }

        for qg in self.question_groups:
            question_groups.append(qg.toxml())

        return root
Exemplo n.º 31
0
    def toxml(self):
        part = super(MultipleChoicePart, self).toxml()
        appendMany(part, [
            'choices', 'answers', 'layout',
            [
                'marking', 'matrix', 'maxmarks', 'minmarks', 'distractors',
                'warning'
            ]
        ])

        part.attrib['showcellanswerstate'] = strcons_fix(
            self.showCellAnswerState)

        choices = part.find('choices')
        choices.attrib = {
            'minimumexpected': strcons_fix(self.minAnswers),
            'maximumexpected': strcons_fix(self.maxAnswers),
            'displaycolumns': strcons_fix(self.displayColumns),
            'shuffle': strcons_fix(self.shuffleChoices),
            'displaytype': strcons(self.displayType),
        }

        if isinstance(self.choices, str):
            choices.attrib['def'] = strcons(self.choices)
        else:
            for choice in self.choices:
                choices.append(makeTree(['choice', makeContentNode(choice)]))

        answers = part.find('answers')
        answers.attrib = {'shuffle': strcons_fix(self.shuffleAnswers)}
        if isinstance(self.answers, str):
            answers.attrib['def'] = strcons(self.answers)
        else:
            for answer in self.answers:
                answers.append(makeTree(['answer', makeContentNode(answer)]))

        layout = part.find('layout')
        layout.attrib = {
            'type': self.layoutType,
            'expression': self.layoutExpression,
        }

        marking = part.find('marking')
        marking.find('maxmarks').attrib = {
            'enabled': strcons_fix(self.maxMarksEnabled),
            'value': strcons_fix(self.maxMarks)
        }
        marking.find('minmarks').attrib = {
            'enabled': strcons_fix(self.minMarksEnabled),
            'value': strcons_fix(self.minMarks)
        }
        matrix = marking.find('matrix')
        if isinstance(self.matrix, str):
            matrix.attrib = {'def': strcons(self.matrix)}
        else:
            for i in range(len(self.matrix)):
                for j in range(len(self.matrix[i])):
                    mark = etree.Element(
                        'mark', {
                            'answerindex': strcons_fix(j),
                            'choiceindex': strcons_fix(i),
                            'value': strcons_fix(self.matrix[i][j])
                        })
                    matrix.append(mark)

        distractors = marking.find('distractors')
        for i in range(len(self.distractors)):
            for j in range(len(self.distractors[i])):
                distractor = etree.Element('distractor', {
                    'choiceindex': strcons_fix(i),
                    'answerindex': strcons_fix(j)
                })
                distractor.append(makeContentNode(self.distractors[i][j]))
                distractors.append(distractor)

        warning = marking.find('warning')
        warning.attrib = {'type': self.warningType}

        return part
Exemplo n.º 32
0
    def toxml(self):
        part = super(NumberEntryPart,self).toxml()
        part.append(makeTree(['answer',
                                ['precision','message'],
                            ]
                            ))

        answer = part.find('answer')
        answer.attrib = {
            'checkingType': strcons(self.checkingType),
            'inputstep': strcons_fix(self.inputStep),
            'allowfractions': strcons_fix(self.allowFractions),
            'showfractionhint': strcons_fix(self.showFractionHint),
            'notationstyles': strcons_fix(','.join(self.notationStyles)),
            'correctanswerfraction': strcons_fix(self.correctAnswerFraction),
            'correctanswerstyle': strcons_fix(self.correctAnswerStyle),
            'mustbereduced': strcons_fix(self.mustBeReduced),
            'mustbereducedpc': strcons_fix(self.mustBeReducedPC)+'%'
        }
        if self.checkingType == 'range':
            answer.attrib['minvalue'] = strcons_fix(self.minvalue)
            answer.attrib['maxvalue'] = strcons_fix(self.maxvalue)
        else:
            answer.attrib['answer'] = strcons_fix(self.answer)
            answer.attrib['accuracy'] = strcons_fix(self.checkingAccuracy)
        answer.find('precision').attrib = {
            'type': strcons(self.precisionType), 
            'precision': strcons_fix(self.precision), 
            'partialcredit': strcons_fix(self.precisionPartialCredit)+'%',
            'strict': strcons_fix(self.strictPrecision),
            'showprecisionhint': strcons_fix(self.showPrecisionHint),
        }
        answer.find('precision/message').append(makeContentNode(self.precisionMessage))

        return part
Exemplo n.º 33
0
    def toxml(self):
        restriction = super().toxml()
        if int(self.length) >= 0:
            restriction.attrib['length'] = strcons_fix(self.length)

        return restriction