Search in sources :

Example 6 with NumericalEntry

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project openolat by klemens.

the class FIBEditorController method createEntry.

private AbstractEntry createEntry(String responseIdentifier, String selectedText, String type, boolean newEntry) {
    AbstractEntry interaction = null;
    if ("string".equalsIgnoreCase(type)) {
        TextEntry textInteraction = itemBuilder.createTextEntry(responseIdentifier);
        if (StringHelper.containsNonWhitespace(selectedText)) {
            String[] alternatives = selectedText.split(",");
            for (String alternative : alternatives) {
                if (StringHelper.containsNonWhitespace(alternative)) {
                    alternative = alternative.trim();
                    if (textInteraction.getSolution() == null) {
                        textInteraction.setSolution(alternative);
                    } else {
                        textInteraction.addAlternative(alternative, textInteraction.getScore());
                    }
                }
            }
            if (alternatives.length > 0) {
                String solution = alternatives[0];
                if (newEntry && "gap".equals(solution)) {
                    solution = "";
                }
                textInteraction.setSolution(solution);
            }
        }
        interaction = textInteraction;
    } else if ("float".equalsIgnoreCase(type)) {
        NumericalEntry numericalInteraction = itemBuilder.createNumericalEntry(responseIdentifier);
        if (newEntry && "gap".equals(selectedText)) {
        // skip it, it's a placeholder
        } else if (StringHelper.containsNonWhitespace(selectedText)) {
            try {
                Double val = Double.parseDouble(selectedText.trim());
                numericalInteraction.setSolution(val);
            } catch (NumberFormatException e) {
            // 
            }
        }
        interaction = numericalInteraction;
    }
    return interaction;
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry) NumericalEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)

Example 7 with NumericalEntry

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project openolat by klemens.

the class FIBEditorController method doGapEntry.

private void doGapEntry(UserRequest ureq, String responseIdentifier, String selectedText, String emptySolution, String type, boolean newEntry) {
    if (textEntrySettingsCtrl != null || numericalEntrySettingsCtrl != null)
        return;
    AbstractEntry interaction = itemBuilder.getEntry(responseIdentifier);
    if (interaction == null) {
        interaction = createEntry(responseIdentifier, selectedText, type, newEntry);
    } else if (StringHelper.containsNonWhitespace(selectedText)) {
        updateSolution(interaction, selectedText, emptySolution);
    }
    if (interaction instanceof TextEntry) {
        textEntrySettingsCtrl = new FIBTextEntrySettingsController(ureq, getWindowControl(), (TextEntry) interaction, restrictedEdit, readOnly);
        listenTo(textEntrySettingsCtrl);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), textEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
        cmc.activate();
        listenTo(cmc);
    } else if (interaction instanceof NumericalEntry) {
        numericalEntrySettingsCtrl = new FIBNumericalEntrySettingsController(ureq, getWindowControl(), (NumericalEntry) interaction, restrictedEdit, readOnly);
        listenTo(numericalEntrySettingsCtrl);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), numericalEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
        cmc.activate();
        listenTo(cmc);
    }
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry) NumericalEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)

Example 8 with NumericalEntry

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project OpenOLAT by OpenOLAT.

the class FIBEditorController method createEntry.

private AbstractEntry createEntry(String responseIdentifier, String selectedText, String type, boolean newEntry) {
    AbstractEntry interaction = null;
    if ("string".equalsIgnoreCase(type)) {
        TextEntry textInteraction = itemBuilder.createTextEntry(responseIdentifier);
        if (StringHelper.containsNonWhitespace(selectedText)) {
            String[] alternatives = selectedText.split(",");
            for (String alternative : alternatives) {
                if (StringHelper.containsNonWhitespace(alternative)) {
                    alternative = alternative.trim();
                    if (textInteraction.getSolution() == null) {
                        textInteraction.setSolution(alternative);
                    } else {
                        textInteraction.addAlternative(alternative, textInteraction.getScore());
                    }
                }
            }
            if (alternatives.length > 0) {
                String solution = alternatives[0];
                if (newEntry && "gap".equals(solution)) {
                    solution = "";
                }
                textInteraction.setSolution(solution);
            }
        }
        interaction = textInteraction;
    } else if ("float".equalsIgnoreCase(type)) {
        NumericalEntry numericalInteraction = itemBuilder.createNumericalEntry(responseIdentifier);
        if (newEntry && "gap".equals(selectedText)) {
        // skip it, it's a placeholder
        } else if (StringHelper.containsNonWhitespace(selectedText)) {
            try {
                Double val = Double.parseDouble(selectedText.trim());
                numericalInteraction.setSolution(val);
            } catch (NumberFormatException e) {
            // 
            }
        }
        interaction = numericalInteraction;
    }
    return interaction;
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry) NumericalEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)

Example 9 with NumericalEntry

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project OpenOLAT by OpenOLAT.

the class FIBEditorController method doGapEntry.

private void doGapEntry(UserRequest ureq, String responseIdentifier, String selectedText, String emptySolution, String type, boolean newEntry) {
    if (textEntrySettingsCtrl != null || numericalEntrySettingsCtrl != null)
        return;
    AbstractEntry interaction = itemBuilder.getEntry(responseIdentifier);
    if (interaction == null) {
        interaction = createEntry(responseIdentifier, selectedText, type, newEntry);
    } else if (StringHelper.containsNonWhitespace(selectedText)) {
        updateSolution(interaction, selectedText, emptySolution);
    }
    if (interaction instanceof TextEntry) {
        textEntrySettingsCtrl = new FIBTextEntrySettingsController(ureq, getWindowControl(), (TextEntry) interaction, restrictedEdit, readOnly);
        listenTo(textEntrySettingsCtrl);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), textEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
        cmc.activate();
        listenTo(cmc);
    } else if (interaction instanceof NumericalEntry) {
        numericalEntrySettingsCtrl = new FIBNumericalEntrySettingsController(ureq, getWindowControl(), (NumericalEntry) interaction, restrictedEdit, readOnly);
        listenTo(numericalEntrySettingsCtrl);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), numericalEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
        cmc.activate();
        listenTo(cmc);
    }
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry) NumericalEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)

Example 10 with NumericalEntry

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project OpenOLAT by OpenOLAT.

the class FIBAssessmentItemBuilder method extractEntriesSettingsFromResponseDeclaration.

/**
 * We loop around the textEntryInteraction, search the responseDeclaration. responseDeclaration
 * of type string are gap text, of type float are numerical.
 */
public void extractEntriesSettingsFromResponseDeclaration() {
    DoubleAdder mappedScore = new DoubleAdder();
    AtomicInteger countAlternatives = new AtomicInteger(0);
    responseIdentifierToTextEntry = new HashMap<>();
    List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
    for (Interaction interaction : interactions) {
        if (interaction instanceof TextEntryInteraction && interaction.getResponseIdentifier() != null) {
            AbstractEntry entry = null;
            TextEntryInteraction textInteraction = (TextEntryInteraction) interaction;
            ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
            if (responseDeclaration != null) {
                if (responseDeclaration.hasBaseType(BaseType.STRING) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
                    TextEntry textEntry = new TextEntry(textInteraction);
                    extractTextEntrySettingsFromResponseDeclaration(textEntry, responseDeclaration, countAlternatives, mappedScore);
                    String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
                    question = question.replace(marker, marker + " openolatType=\"string\"");
                    if (StringHelper.containsNonWhitespace(textEntry.getSolution())) {
                        question = question.replace(marker, marker + " data-qti-solution=\"" + escapeForDataQtiSolution(textEntry.getSolution()) + "\"");
                    }
                    entry = textEntry;
                } else if (responseDeclaration.hasBaseType(BaseType.FLOAT) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
                    NumericalEntry numericalEntry = new NumericalEntry(textInteraction);
                    entry = numericalEntry;
                    extractNumericalEntrySettings(assessmentItem, numericalEntry, responseDeclaration, countAlternatives, mappedScore);
                    String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
                    question = question.replace(marker, marker + " openolatType=\"float\"");
                    if (numericalEntry.getSolution() != null) {
                        question = question.replace(marker, marker + " data-qti-solution=\"" + Double.toString(numericalEntry.getSolution()) + "\"");
                    }
                }
            }
            if (entry != null) {
                responseIdentifierToTextEntry.put(interaction.getResponseIdentifier().toString(), entry);
            }
        }
    }
    boolean hasMapping = Math.abs(mappedScore.doubleValue() - (-1.0 * countAlternatives.get())) > 0.0001;
    scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Also used : DoubleAdder(java.util.concurrent.atomic.DoubleAdder) AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) AssessmentItemFactory.createNumericalEntryResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createNumericalEntryResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createTextEntryResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createTextEntryResponseDeclaration)

Aggregations

NumericalEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 DoubleAdder (java.util.concurrent.atomic.DoubleAdder)6 TextEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry)6 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)6 AssessmentItemFactory.createNumericalEntryResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createNumericalEntryResponseDeclaration)4 AssessmentItemFactory.createTextEntryResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createTextEntryResponseDeclaration)4 AbstractEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 NumericalInputInteractionStatistics (org.olat.ims.qti21.model.statistics.NumericalInputInteractionStatistics)2 AssessmentItemFactory.appendTextEntryInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction)2 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)2 TextEntryInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction)2