use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class MultipleChoiceAssessmentItemBuilderTest method readMultipleChoice_perAnswer_1123.
@Test
public void readMultipleChoice_perAnswer_1123() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/multiple-choice-per-answer-11-2-3.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof ChoiceInteraction);
// choices
SimpleChoice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("mc80677ac3f4449ebc689cf60c230a3d"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
SimpleChoice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("mc7e5667abeb415fa05a8c7d8fd3d6bb"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
SimpleChoice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("mcaacc51e0ca4027b3adb3107cda4e30"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
SimpleChoice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("mc1b7b8257e2419b880936ea11bff1f1"));
Assert.assertFalse(itemBuilder.isCorrect(wrong2));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(1.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// correct feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertNotNull(correctFeedback.getText());
Assert.assertTrue(correctFeedback.getText().contains("All answers correct"));
// incorrect
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertNotNull(incorrectFeedback.getText());
Assert.assertTrue(incorrectFeedback.getText().contains("Some choices are wrong"));
// per answer
Assert.assertEquals(ScoreEvaluation.perAnswer, itemBuilder.getScoreEvaluationMode());
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class OnyxToAssessmentItemBuilderTest method extractsingleChoiceWithFeedbacks.
@Test
public void extractsingleChoiceWithFeedbacks() throws URISyntaxException {
URL itemUrl = OnyxToAssessmentItemBuilderTest.class.getResource("resources/onyx/single-choice-1-with-feedbacks_5-11.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
// correct answer
List<SimpleChoice> choices = itemBuilder.getChoices();
Assert.assertNotNull(choices);
SimpleChoice choice = choices.get(3);
Assert.assertTrue(itemBuilder.isCorrect(choice));
// scoring
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
ScoreBuilder maxScoreBuilder = itemBuilder.getMaxScoreBuilder();
Assert.assertEquals(4.0d, maxScoreBuilder.getScore(), 0.00001d);
// check standard feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertTrue(correctFeedback.isCorrectRule());
Assert.assertEquals("<p>Richtig Text</p>", correctFeedback.getText());
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertTrue(incorrectFeedback.isIncorrectRule());
Assert.assertEquals("<p>Falsch Text</p>", incorrectFeedback.getText());
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class AssessmentItemComponentRenderer method renderTestItemBody.
private void renderTestItemBody(AssessmentRenderer renderer, StringOutput sb, AssessmentItemComponent component, ItemSessionState itemSessionState, URLBuilder ubu, Translator translator) {
final AssessmentItem assessmentItem = component.getAssessmentItem();
final ResolvedAssessmentItem resolvedAssessmentItem = component.getResolvedAssessmentItem();
sb.append("<div class='o_assessmentitem_wrapper'>");
// title + status
sb.append("<h4 class='itemTitle'>");
renderItemStatus(renderer, sb, itemSessionState, translator);
sb.append(StringHelper.escapeHtml(assessmentItem.getTitle())).append("</h4>").append("<div id='itemBody' class='clearfix'>");
// TODO prompt
// render itemBody
assessmentItem.getItemBody().getBlocks().forEach((block) -> renderBlock(renderer, sb, component, resolvedAssessmentItem, itemSessionState, block, ubu, translator));
// comment
renderComment(renderer, sb, component, itemSessionState, translator);
// end body
sb.append("</div>");
// Display active modal feedback (only after responseProcessing)
if (itemSessionState.getSessionStatus() == SessionStatus.FINAL) {
renderTestItemModalFeedback(renderer, sb, component, resolvedAssessmentItem, itemSessionState, ubu, translator);
}
// controls
sb.append("<div class='o_button_group o_assessmentitem_controls'>");
// submit button
if (component.isItemSessionOpen(itemSessionState, renderer.isSolutionMode())) {
Component submit = component.getQtiItem().getSubmitButton().getComponent();
submit.getHTMLRendererSingleton().render(renderer.getRenderer(), sb, submit, ubu, translator, new RenderResult(), null);
}
sb.append("</div>");
// end wrapper
sb.append("</div>");
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class AssessmentObjectComponentRenderer method renderHottext.
/*
<xsl:template match="qti:hottext">
<xsl:if test="qw:is-visible(.)">
<xsl:variable name="hottextInteraction" select="ancestor::qti:hottextInteraction" as="element(qti:hottextInteraction)"/>
<xsl:variable name="responseIdentifier" select="$hottextInteraction/@responseIdentifier" as="xs:string"/>
<span class="hottext">
<input type="{if ($hottextInteraction/@maxChoices=1) then 'radio' else 'checkbox'}"
name="qtiworks_response_{$responseIdentifier}"
value="{@identifier}">
<xsl:if test="$isItemSessionEnded">
<xsl:attribute name="disabled">disabled</xsl:attribute>
</xsl:if>
<xsl:if test="qw:value-contains(qw:get-response-value(/, $responseIdentifier), @identifier)">
<xsl:attribute name="checked" select="'checked'"/>
</xsl:if>
</input>
<xsl:apply-templates/>
</span>
</xsl:if>
</xsl:template>
*/
private void renderHottext(AssessmentRenderer renderer, StringOutput sb, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, Hottext hottext, AssessmentObjectComponent component, URLBuilder ubu, Translator translator) {
if (!isVisible(hottext, itemSessionState))
return;
HottextInteraction interaction = null;
for (QtiNode parentNode = hottext.getParent(); parentNode.getParent() != null; parentNode = parentNode.getParent()) {
if (parentNode instanceof HottextInteraction) {
interaction = (HottextInteraction) parentNode;
break;
}
}
if (interaction != null) {
sb.append("<span class='hottext'><input type='");
if (interaction.getMaxChoices() == 1) {
sb.append("radio");
} else {
sb.append("checkbox");
}
String guid = "oo_" + CodeHelper.getRAMUniqueID();
String responseUniqueId = component.getResponseUniqueIdentifier(itemSessionState, interaction);
sb.append("' id='").append(guid).append("' name='qtiworks_response_").append(responseUniqueId).append("'").append(" value='").append(hottext.getIdentifier().toString()).append("'");
if (component.isItemSessionEnded(itemSessionState, renderer.isSolutionMode())) {
sb.append(" disabled");
}
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
Value responseValue = getResponseValue(assessmentItem, itemSessionState, interaction.getResponseIdentifier(), renderer.isSolutionMode());
if (valueContains(responseValue, hottext.getIdentifier())) {
sb.append(" checked");
}
sb.append(" />");
sb.append("<label for='").append(guid).append("'>");
hottext.getInlineStatics().forEach((inline) -> renderInline(renderer, sb, component, resolvedAssessmentItem, itemSessionState, inline, ubu, translator));
FormJSHelper.appendFlexiFormDirtyOn(sb, component.getQtiItem().getRootForm(), "change click", guid);
sb.append("</label></span>");
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class AssessmentTestComponentRenderer method renderTestItemBody.
private void renderTestItemBody(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, TestPlanNode itemNode, URLBuilder ubu, Translator translator, RenderingRequest options) {
final ItemSessionState itemSessionState = component.getItemSessionState(itemNode.getKey());
URI itemSystemId = itemNode.getItemSystemId();
ResolvedAssessmentItem resolvedAssessmentItem = component.getResolvedAssessmentTest().getResolvedAssessmentItemBySystemIdMap().get(itemSystemId);
if (resolvedAssessmentItem == null) {
log.error("Missing assessment item: " + itemSystemId);
renderMissingItem(sb, translator);
return;
}
final AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
sb.append("<div class='o_assessmentitem_wrapper'>");
// title + status
sb.append("<h4 class='itemTitle'>");
renderItemStatus(sb, itemSessionState, options, translator);
renderMaxScoreItem(sb, component, itemSessionState, translator);
String title;
if (component.isShowTitles()) {
title = StringHelper.escapeHtml(itemNode.getSectionPartTitle());
} else {
int num = component.getCandidateSessionContext().getNumber(itemNode);
title = translator.translate("question.title", new String[] { Integer.toString(num) });
}
sb.append(title).append("</h4>").append("<div id='itemBody' class='o_qti_item_body clearfix'>");
// render itemBody
assessmentItem.getItemBody().getBlocks().forEach(block -> renderBlock(renderer, sb, component, resolvedAssessmentItem, itemSessionState, block, ubu, translator));
// comment
renderComment(renderer, sb, component, itemSessionState, translator);
// end body
sb.append("</div>");
// Display active modal feedback (only after responseProcessing)
if (component.isItemFeedbackAllowed(itemNode, assessmentItem, options)) {
renderTestItemModalFeedback(renderer, sb, component, resolvedAssessmentItem, itemSessionState, ubu, translator);
}
// end wrapper
sb.append("</div>");
}
Aggregations