Search in sources :

Example 16 with AbstractEntry

use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry 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)

Example 17 with AbstractEntry

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

the class CorrectResponsesUtil method getCorrectTextResponses.

public static final AbstractEntry getCorrectTextResponses(AssessmentItem assessmentItem, TextEntryInteraction interaction) {
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration.hasBaseType(BaseType.STRING) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
        TextEntry textEntry = new TextEntry(interaction);
        FIBAssessmentItemBuilder.extractTextEntrySettingsFromResponseDeclaration(textEntry, responseDeclaration, new AtomicInteger(), new DoubleAdder());
        return textEntry;
    } else if (responseDeclaration.hasBaseType(BaseType.FLOAT) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
        NumericalEntry numericalEntry = new NumericalEntry(interaction);
        FIBAssessmentItemBuilder.extractNumericalEntrySettings(assessmentItem, numericalEntry, responseDeclaration, new AtomicInteger(), new DoubleAdder());
        return numericalEntry;
    }
    return null;
}
Also used : DoubleAdder(java.util.concurrent.atomic.DoubleAdder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) NumericalEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)

Example 18 with AbstractEntry

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

the class FIBAssessmentItemBuilder method buildItemBody.

@Override
protected void buildItemBody() {
    // remove current blocks
    List<Block> blocks = assessmentItem.getItemBody().getBlocks();
    blocks.clear();
    // add question
    getHtmlHelper().appendHtml(assessmentItem.getItemBody(), question);
    // transfer text entry to the interactions
    List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
    List<String> usedResponseIdentifiers = new ArrayList<>(interactions.size());
    for (Interaction interaction : interactions) {
        if (interaction instanceof TextEntryInteraction && interaction.getResponseIdentifier() != null) {
            TextEntryInteraction textEntryInteraction = (TextEntryInteraction) interaction;
            String responseIdentifier = interaction.getResponseIdentifier().toString();
            AbstractEntry entry = responseIdentifierToTextEntry.get(responseIdentifier);
            if (entry != null) {
                textEntryInteraction.setPlaceholderText(entry.getPlaceholder());
                textEntryInteraction.setExpectedLength(entry.getExpectedLength());
            }
            usedResponseIdentifiers.add(responseIdentifier);
        }
    }
    List<String> mappedResponseIdentifiers = new ArrayList<>(responseIdentifierToTextEntry.keySet());
    mappedResponseIdentifiers.removeAll(usedResponseIdentifiers);
    for (String mappedResponseIdentifier : mappedResponseIdentifiers) {
        responseIdentifierToTextEntry.remove(mappedResponseIdentifier);
    }
}
Also used : AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) 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) ArrayList(java.util.ArrayList) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block)

Example 19 with AbstractEntry

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

the class FIBAssessmentItemBuilder method getOrderedTextEntries.

public List<AbstractEntry> getOrderedTextEntries() {
    List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
    List<AbstractEntry> entries = getTextEntries();
    List<AbstractEntry> orderedEntries = new ArrayList<>();
    for (Interaction interaction : interactions) {
        AbstractEntry entry = getTextEntry(interaction.getResponseIdentifier().toString());
        if (entry != null) {
            orderedEntries.add(entry);
            entries.remove(entry);
        }
    }
    if (entries.size() > 0) {
        // security
        orderedEntries.addAll(entries);
    }
    return orderedEntries;
}
Also used : 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) ArrayList(java.util.ArrayList)

Example 20 with AbstractEntry

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

the class FIBScoreController method sync.

@Override
public void sync(UserRequest ureq, AssessmentItemBuilder assessmentItemBuilder) {
    if (itemBuilder == assessmentItemBuilder) {
        List<AbstractEntry> entries = itemBuilder.getOrderedTextEntries();
        for (AbstractEntry entry : entries) {
            FIBEntryWrapper wrapper = getTextEntryWrapper(entry);
            if (wrapper == null) {
                wrappers.add(createTextEntryWrapper(entry));
            }
        }
        // remove removed entry
        for (Iterator<FIBEntryWrapper> wrapperIt = wrappers.iterator(); wrapperIt.hasNext(); ) {
            Identifier responseIdentifier = wrapperIt.next().getEntry().getResponseIdentifier();
            if (itemBuilder.getTextEntry(responseIdentifier.toString()) == null) {
                wrapperIt.remove();
            }
        }
        // reorder the wrappers
        Map<AbstractEntry, FIBEntryWrapper> wrapperMap = new HashMap<>();
        for (FIBEntryWrapper wrapper : wrappers) {
            wrapperMap.put(wrapper.getEntry(), wrapper);
        }
        List<FIBEntryWrapper> reorderedWrappers = new ArrayList<>();
        for (AbstractEntry entry : entries) {
            FIBEntryWrapper wrapper = wrapperMap.get(entry);
            if (wrapper != null) {
                reorderedWrappers.add(wrapper);
                wrapperMap.remove(entry);
            }
        }
        if (wrapperMap.size() > 0) {
            // paranoid security
            for (FIBEntryWrapper wrapper : wrapperMap.values()) {
                if (!reorderedWrappers.contains(wrapper)) {
                    reorderedWrappers.add(wrapper);
                }
            }
        }
        wrappers.clear();
        wrappers.addAll(reorderedWrappers);
    }
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

AbstractEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry)10 TextEntryInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction)8 ArrayList (java.util.ArrayList)6 AssessmentItemFactory.appendTextEntryInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction)6 NumericalEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)6 TextEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry)6 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)6 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)6 HashMap (java.util.HashMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DoubleAdder (java.util.concurrent.atomic.DoubleAdder)4 AssessmentItemFactory.createNumericalEntryResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createNumericalEntryResponseDeclaration)4 AssessmentItemFactory.createTextEntryResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createTextEntryResponseDeclaration)4 Map (java.util.Map)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 ScoreBuilder (org.olat.ims.qti21.model.xml.ScoreBuilder)2 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)2 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)2