Search in sources :

Example 21 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice 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 22 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice 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 23 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project openolat by klemens.

the class AssessmentObjectVelocityRenderDecorator method getRespondedVisibleChoices.

/*
		<xsl:variable name="respondedChoiceIdentifiers" select="qw:extract-iterable-elements(qw:get-response-value(/, @responseIdentifier))" as="xs:string*"/>
        <xsl:variable name="unselectedVisibleChoices" select="$visibleOrderedChoices[not(@identifier = $respondedChoiceIdentifiers)]" as="element(qti:simpleChoice)*"/>
        
        <xsl:variable name="respondedVisibleChoices" as="element(qti:simpleChoice)*">
          <xsl:for-each select="$respondedChoiceIdentifiers">
            <xsl:sequence select="$thisInteraction/qti:simpleChoice[@identifier=current() and qw:is-visible(.)]"/>
          </xsl:for-each>
        </xsl:variable>
	 */
public OrderChoices getRespondedVisibleChoices(OrderInteraction interaction) {
    List<SimpleChoice> visibleChoices = getVisibleOrderedSimpleChoices(interaction);
    Value responseValue = getResponseValue(interaction.getResponseIdentifier());
    List<String> responseIdentifiers = new ArrayList<>();
    if (responseValue instanceof ListValue) {
        for (SingleValue singleValue : (ListValue) responseValue) {
            responseIdentifiers.add(singleValue.toQtiString());
        }
    }
    List<SimpleChoice> unselectedVisibleChoices = new ArrayList<>(visibleChoices);
    for (Iterator<SimpleChoice> it = unselectedVisibleChoices.iterator(); it.hasNext(); ) {
        SimpleChoice choice = it.next();
        if (responseIdentifiers.contains(choice.getIdentifier().toString())) {
            it.remove();
        }
    }
    List<SimpleChoice> respondedVisibleChoices = new ArrayList<>();
    for (String responseIdentifier : responseIdentifiers) {
        for (SimpleChoice visibleChoice : visibleChoices) {
            if (responseIdentifier.equals(visibleChoice.getIdentifier().toString())) {
                respondedVisibleChoices.add(visibleChoice);
            }
        }
    }
    return new OrderChoices(respondedVisibleChoices, unselectedVisibleChoices);
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) AssessmentRenderFunctions.renderValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) FileValue(uk.ac.ed.ph.jqtiplus.value.FileValue) ArrayList(java.util.ArrayList)

Example 24 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project openolat by klemens.

the class MultipleChoiceEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout_2_10("metadata", getTranslator());
    metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_mc");
    metadata.setRootForm(mainForm);
    formLayout.add(metadata);
    formLayout.add("metadata", metadata);
    titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), metadata);
    titleEl.setElementCssClass("o_sel_assessment_item_title");
    titleEl.setMandatory(true);
    titleEl.setEnabled(!readOnly);
    String description = itemBuilder.getQuestion();
    textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", description, 8, -1, itemContainer, metadata, ureq.getUserSession(), getWindowControl());
    textEl.setVisible(!readOnly);
    if (readOnly) {
        FlowFormItem choiceReadOnlyEl = new FlowFormItem("descro", itemFile);
        choiceReadOnlyEl.setLabel("form.imd.descr", null);
        choiceReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
        choiceReadOnlyEl.setMapperUri(mapperUri);
        metadata.add(choiceReadOnlyEl);
    }
    // shuffle
    String[] yesnoValues = new String[] { translate("yes"), translate("no") };
    shuffleEl = uifactory.addRadiosHorizontal("shuffle", "form.imd.shuffle", metadata, yesnoKeys, yesnoValues);
    shuffleEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.isShuffle()) {
        shuffleEl.select("y", true);
    } else {
        shuffleEl.select("n", true);
    }
    // layout
    String[] layoutValues = new String[] { translate("form.imd.layout.vertical"), translate("form.imd.layout.horizontal") };
    orientationEl = uifactory.addRadiosHorizontal("layout", "form.imd.layout", metadata, layoutKeys, layoutValues);
    orientationEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.getOrientation() == null || Orientation.VERTICAL.equals(itemBuilder.getOrientation())) {
        orientationEl.select(Orientation.VERTICAL.name(), true);
    } else {
        orientationEl.select(Orientation.HORIZONTAL.name(), true);
    }
    // alignment
    String[] alignmentValues = new String[] { translate("form.imd.alignment.left"), translate("form.imd.alignment.right") };
    alignmentEl = uifactory.addRadiosHorizontal("alignment", "form.imd.alignment", metadata, alignmentKeys, alignmentValues);
    alignmentEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.hasClassAttr(QTI21Constants.CHOICE_ALIGN_RIGHT)) {
        alignmentEl.select(alignmentKeys[1], true);
    } else {
        alignmentEl.select(alignmentKeys[0], true);
    }
    // responses
    String page = velocity_root + "/multiple_choices.html";
    answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
    answersCont.setRootForm(mainForm);
    formLayout.add(answersCont);
    formLayout.add("answers", answersCont);
    ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
    if (interaction != null) {
        List<SimpleChoice> choices = itemBuilder.getChoices();
        for (SimpleChoice choice : choices) {
            wrapAnswer(ureq, choice);
        }
    }
    answersCont.contextPut("choices", choiceWrappers);
    answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
    recalculateUpDownLinks();
    // Submit Button
    FormLayoutContainer buttonsContainer = FormLayoutContainer.createDefaultFormLayout_2_10("buttons", getTranslator());
    buttonsContainer.setElementCssClass("o_sel_choices_save");
    buttonsContainer.setRootForm(mainForm);
    buttonsContainer.setVisible(!readOnly);
    formLayout.add(buttonsContainer);
    formLayout.add("buttons", buttonsContainer);
    uifactory.addFormSubmitButton("submit", buttonsContainer);
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)

Example 25 with SimpleChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project openolat by klemens.

the class MultipleChoiceEditorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (readOnly)
        return;
    // title
    itemBuilder.setTitle(titleEl.getValue());
    // question
    String questionText = textEl.getRawValue();
    itemBuilder.setQuestion(questionText);
    if (!restrictedEdit) {
        // correct response
        String[] correctAnswers = ureq.getHttpReq().getParameterValues("correct");
        List<Identifier> correctAnswerList = new ArrayList<>();
        if (correctAnswers != null) {
            for (String correctAnswer : correctAnswers) {
                correctAnswerList.add(Identifier.parseString(correctAnswer));
            }
        }
        itemBuilder.setCorrectAnswers(correctAnswerList);
        // shuffle
        itemBuilder.setShuffle(shuffleEl.isOneSelected() && shuffleEl.isSelected(0));
        // orientation
        itemBuilder.setOrientation(Orientation.valueOf(orientationEl.getSelectedKey()));
        // alignment
        if (alignmentEl.isOneSelected() && alignmentEl.isSelected(1)) {
            itemBuilder.addClass(QTI21Constants.CHOICE_ALIGN_RIGHT);
        } else {
            itemBuilder.removeClass(QTI21Constants.CHOICE_ALIGN_RIGHT);
        }
    }
    // replace simple choices
    List<SimpleChoice> choiceList = new ArrayList<>();
    for (SimpleChoiceWrapper choiceWrapper : choiceWrappers) {
        SimpleChoice choice = choiceWrapper.getSimpleChoice();
        // text
        String answer = choiceWrapper.getAnswer().getRawValue();
        itemBuilder.getHtmlHelper().appendHtml(choice, answer);
        choiceList.add(choice);
    }
    itemBuilder.setSimpleChoices(choiceList);
    fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.sc));
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ArrayList(java.util.ArrayList) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Aggregations

SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)54 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)32 Test (org.junit.Test)16 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)16 ArrayList (java.util.ArrayList)14 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)14 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)14 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)14 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)14 URL (java.net.URL)12 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)12 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)12 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)10 HashMap (java.util.HashMap)8 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)8 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)8 Value (uk.ac.ed.ph.jqtiplus.value.Value)6 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)5 IOException (java.io.IOException)4 Map (java.util.Map)4