Search in sources :

Example 1 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.

the class QTI21StatisticsManagerImpl method getMatchStatistics.

@Override
public List<MatchStatistics> getMatchStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
    List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
    SimpleMatchSet sourceMatchSets = interaction.getSimpleMatchSets().get(0);
    SimpleMatchSet targetMatchSets = interaction.getSimpleMatchSets().get(1);
    List<MatchStatistics> matchPoints = new ArrayList<>();
    ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
    // readable responses
    Map<Identifier, List<Identifier>> associations = new HashMap<>();
    CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
    QtiNodesExtractor.extractIdentifiersFromCorrectResponse(correctResponse, associations);
    for (SimpleAssociableChoice sourceChoice : sourceMatchSets.getSimpleAssociableChoices()) {
        for (SimpleAssociableChoice targetChoice : targetMatchSets.getSimpleAssociableChoices()) {
            DirectedPairValue dKey = new DirectedPairValue(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
            String choiceIdentifier = dKey.toQtiString();
            String marker = "[" + choiceIdentifier + "]";
            boolean correct = associations.containsKey(sourceChoice.getIdentifier()) && associations.get(sourceChoice.getIdentifier()).contains(targetChoice.getIdentifier());
            long numCorrect = 0;
            long numIncorrect = 0;
            for (RawData rawData : rawDatas) {
                String response = rawData.getStringuifiedResponse();
                if (response.indexOf(marker) >= 0) {
                    if (correct) {
                        numCorrect += rawData.getCount();
                    } else {
                        numIncorrect += rawData.getCount();
                    }
                }
            }
            matchPoints.add(new MatchStatistics(sourceChoice.getIdentifier(), targetChoice.getIdentifier(), numCorrect, numIncorrect));
        }
    }
    return matchPoints;
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) MatchStatistics(org.olat.ims.qti21.model.statistics.MatchStatistics) List(java.util.List) ArrayList(java.util.ArrayList) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 2 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.

the class QTI21StatisticsManagerImpl method getKPrimStatistics.

// stringuifiedResponse: [a93247453265982 correct][b93247453265983 correct][c93247453265984 correct][d93247453265985 correct]
@Override
public List<KPrimStatistics> getKPrimStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
    List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
    List<SimpleMatchSet> matchSets = interaction.getSimpleMatchSets();
    List<KPrimStatistics> kprimPoints = new ArrayList<>();
    SimpleMatchSet fourMatchSet = matchSets.get(0);
    ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
    // readable responses
    Set<String> rightResponses = new HashSet<>();
    List<MapEntry> mapEntries = responseDeclaration.getMapping().getMapEntries();
    for (MapEntry mapEntry : mapEntries) {
        SingleValue mapKey = mapEntry.getMapKey();
        if (mapKey instanceof DirectedPairValue) {
            DirectedPairValue pairValue = (DirectedPairValue) mapKey;
            String source = pairValue.sourceValue().toString();
            String destination = pairValue.destValue().toString();
            rightResponses.add("[" + source + " " + destination + "]");
        }
    }
    for (SimpleAssociableChoice choice : fourMatchSet.getSimpleAssociableChoices()) {
        String choiceIdentifier = choice.getIdentifier().toString();
        String markerCorrect = "[" + choiceIdentifier + " correct]";
        String markerWrong = "[" + choiceIdentifier + " wrong]";
        boolean isCorrectRight = rightResponses.contains(markerCorrect);
        String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
        String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
        long numCorrect = 0;
        long numIncorrect = 0;
        long numUnanswered = 0;
        for (RawData rawData : rawDatas) {
            String response = rawData.getStringuifiedResponse();
            if (response.indexOf(rightFlag) >= 0) {
                numCorrect += rawData.getCount();
            } else if (response.indexOf(wrongFlag) >= 0) {
                numIncorrect += rawData.getCount();
            } else {
                numUnanswered += rawData.getCount();
            }
        }
        kprimPoints.add(new KPrimStatistics(choice.getIdentifier(), isCorrectRight, numCorrect, numIncorrect, numUnanswered));
    }
    return kprimPoints;
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ArrayList(java.util.ArrayList) KPrimStatistics(org.olat.ims.qti21.model.statistics.KPrimStatistics) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) HashSet(java.util.HashSet)

Example 3 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.

the class MatchEditorController method doAddTargetColumn.

private void doAddTargetColumn(UserRequest ureq) {
    SimpleAssociableChoice newChoice = createSimpleAssociableChoice("Text", itemBuilder.getTargetMatchSet());
    newChoice.setMatchMax(0);
    itemBuilder.getTargetMatchSet().getSimpleAssociableChoices().add(newChoice);
    wrapAnswer(ureq, newChoice, targetWrappers);
    answersCont.setDirty(true);
}
Also used : AssessmentItemFactory.createSimpleAssociableChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)

Example 4 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.

the class MatchEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout("metadata", getTranslator());
    if (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop) {
        metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_draganddrop");
    } else {
        metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_match");
    }
    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.setEnabled(!readOnly);
    textEl.setVisible(!readOnly);
    if (readOnly) {
        FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
        textReadOnlyEl.setLabel("form.imd.descr", null);
        textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
        textReadOnlyEl.setMapperUri(mapperUri);
        metadata.add(textReadOnlyEl);
    }
    // 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);
    }
    // single choice / multiple choice
    String[] singleMultiValues = new String[] { translate("form.imd.match.single.choice"), translate("form.imd.match.multiple.choice") };
    singleMultiEl = uifactory.addRadiosHorizontal("singleMulti", "form.imd.match.single.multiple", metadata, singleMultiKeys, singleMultiValues);
    singleMultiEl.setElementCssClass("o_sel_match_single");
    singleMultiEl.setEnabled(!restrictedEdit && !readOnly);
    singleMultiEl.addActionListener(FormEvent.ONCHANGE);
    if (itemBuilder.isMultipleChoice()) {
        singleMultiEl.select(singleMultiKeys[1], true);
    } else {
        singleMultiEl.select(singleMultiKeys[0], true);
    }
    if (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop) {
        String[] layoutValues = new String[] { translate("form.imd.layout.left"), translate("form.imd.layout.top"), translate("form.imd.layout.right"), translate("form.imd.layout.bottom") };
        layoutEl = uifactory.addRadiosHorizontal("layout", "form.imd.layout", metadata, layoutKeys, layoutValues);
        layoutEl.setElementCssClass("o_sel_match_layout");
        layoutEl.setEnabled(!restrictedEdit && !readOnly);
        boolean found = false;
        for (String layoutKey : layoutKeys) {
            if (itemBuilder.hasMatchInteractionClass(layoutKey)) {
                layoutEl.select(layoutKey, true);
                found = true;
            }
        }
        if (!found) {
            layoutEl.select(layoutKeys[0], true);
        }
    }
    // responses
    String page = velocity_root + "/match_choices.html";
    answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
    answersCont.setRootForm(mainForm);
    answersCont.contextPut("showHeaders", (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop));
    formLayout.add(answersCont);
    formLayout.add("answers", answersCont);
    MatchInteraction interaction = itemBuilder.getMatchInteraction();
    if (interaction != null) {
        List<SimpleAssociableChoice> sourceChoices = itemBuilder.getSourceChoices();
        for (SimpleAssociableChoice sourceChoice : sourceChoices) {
            wrapAnswer(ureq, sourceChoice, sourceWrappers);
        }
        List<SimpleAssociableChoice> targetChoices = itemBuilder.getTargetChoices();
        for (SimpleAssociableChoice targetChoice : targetChoices) {
            wrapAnswer(ureq, targetChoice, targetWrappers);
        }
    }
    answersCont.contextPut("sourceChoices", sourceWrappers);
    answersCont.contextPut("targetChoices", targetWrappers);
    answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
    answersCont.contextPut("responseIdentifier", itemBuilder.getResponseIdentifier());
    int maxAssociations = itemBuilder.getMatchInteraction().getMaxAssociations();
    answersCont.contextPut("interactionMaxAssociations", maxAssociations);
    JSAndCSSFormItem js = new JSAndCSSFormItem("js", new String[] { "js/jquery/qti/jquery.match.js" });
    formLayout.add(js);
    if (!readOnly) {
        uifactory.addFormSubmitButton("submit", answersCont);
    }
    if (!restrictedEdit && !readOnly) {
        addColumnButton = uifactory.addFormLink("add.match.column", answersCont, Link.BUTTON);
        addColumnButton.setElementCssClass("o_sel_match_add_column");
        addColumnButton.setIconLeftCSS("o_icon o_icon_add");
        addRowButton = uifactory.addFormLink("add.match.row", answersCont, Link.BUTTON);
        addRowButton.setElementCssClass("o_sel_match_add_row");
        addRowButton.setIconLeftCSS("o_icon o_icon_add");
    }
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) AssessmentItemFactory.createSimpleAssociableChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) JSAndCSSFormItem(org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 5 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.

the class MatchEditorController 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) {
        boolean singleChoice = singleMultiEl.isOneSelected() && singleMultiEl.isSelected(0);
        itemBuilder.setMultipleChoice(!singleChoice);
    }
    // shuffle
    if (!restrictedEdit) {
        itemBuilder.setShuffle(shuffleEl.isOneSelected() && shuffleEl.isSelected(0));
    }
    // layout
    if (!restrictedEdit && layoutEl != null) {
        itemBuilder.removeMatchInteractionClass(layoutKeys);
        String cssClass = layoutEl.getSelectedKey();
        itemBuilder.addMatchInteractionClass(cssClass);
    }
    // update
    for (MatchWrapper sourceWrapper : sourceWrappers) {
        SimpleAssociableChoice choice = sourceWrapper.getSimpleChoice();
        String answer = sourceWrapper.getText().getRawValue();
        itemBuilder.getHtmlHelper().appendHtml(choice, answer);
    }
    for (MatchWrapper sourceWrapper : targetWrappers) {
        SimpleAssociableChoice choice = sourceWrapper.getSimpleChoice();
        String answer = sourceWrapper.getText().getRawValue();
        itemBuilder.getHtmlHelper().appendHtml(choice, answer);
    }
    // correct answers
    commitAssociations(ureq);
    fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.match));
}
Also used : AssessmentItemFactory.createSimpleAssociableChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Aggregations

SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)54 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)20 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)18 ArrayList (java.util.ArrayList)17 SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)16 AssessmentItemFactory.createSimpleAssociableChoice (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice)14 HashMap (java.util.HashMap)12 List (java.util.List)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)10 AssessmentItemEvent (org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)10 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)10 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)10 FlowFormItem (org.olat.ims.qti21.ui.components.FlowFormItem)7 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6 File (java.io.File)4 UserRequest (org.olat.core.gui.UserRequest)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4