Search in sources :

Example 86 with AssessmentItem

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());
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) URL(java.net.URL) Test(org.junit.Test)

Example 87 with AssessmentItem

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());
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URL(java.net.URL) Test(org.junit.Test)

Example 88 with AssessmentItem

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>");
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) RenderResult(org.olat.core.gui.render.RenderResult) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Component(org.olat.core.gui.components.Component)

Example 89 with AssessmentItem

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>");
    }
}
Also used : AssessmentRenderFunctions.getOutcomeValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getOutcomeValue) AssessmentRenderFunctions.extractRecordFieldValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.extractRecordFieldValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) AssessmentRenderFunctions.getHtmlAttributeValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getHtmlAttributeValue) AssessmentRenderFunctions.renderOrderedCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderOrderedCardinalityValue) AssessmentRenderFunctions.isMultipleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMultipleCardinalityValue) AssessmentRenderFunctions.renderSingleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderSingleCardinalityValue) AssessmentRenderFunctions.renderMultipleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderMultipleCardinalityValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) AssessmentRenderFunctions.getTemplateValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getTemplateValue) AssessmentRenderFunctions.renderRecordCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderRecordCardinalityValue) AssessmentRenderFunctions.getResponseValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getResponseValue) AssessmentRenderFunctions.isNullValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isNullValue) AssessmentRenderFunctions.isSingleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isSingleCardinalityValue) AssessmentRenderFunctions.isRecordCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isRecordCardinalityValue) AssessmentRenderFunctions.isOrderedCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isOrderedCardinalityValue) AssessmentRenderFunctions.isMathsContentValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMathsContentValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) QtiNode(uk.ac.ed.ph.jqtiplus.node.QtiNode)

Example 90 with AssessmentItem

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>");
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) URI(java.net.URI)

Aggregations

AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)174 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)132 Test (org.junit.Test)56 File (java.io.File)42 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)42 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)42 URL (java.net.URL)34 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)34 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)32 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)32 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)28 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)28 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)28 URI (java.net.URI)26 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)22 URISyntaxException (java.net.URISyntaxException)20 AssessmentItemFactory.appendDefaultItemBody (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody)20 AssessmentItemFactory.createResponseProcessing (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing)20 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)20 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)20