Search in sources :

Example 16 with DirectedPairValue

use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.

the class CorrectResponsesUtil method getCorrectDirectPairResponses.

/**
 * The list of correct associations
 * @param assessmentItem
 * @param interaction
 * @return A list of string with [ and ] before and after!
 */
public static final Set<String> getCorrectDirectPairResponses(AssessmentItem assessmentItem, Interaction interaction, boolean withDelimiter) {
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    Set<String> correctAnswers = new HashSet<>();
    // readable responses
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, values);
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                multiValue.forEach(oValue -> {
                    if (oValue instanceof DirectedPairValue) {
                        DirectedPairValue pairValue = (DirectedPairValue) oValue;
                        String source = pairValue.sourceValue().toString();
                        String destination = pairValue.destValue().toString();
                        if (withDelimiter) {
                            correctAnswers.add("[" + source + " " + destination + "]");
                        } else {
                            correctAnswers.add(source + " " + destination);
                        }
                    }
                });
            }
        }
    }
    return correctAnswers;
}
Also used : MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) HashSet(java.util.HashSet)

Example 17 with DirectedPairValue

use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.

the class MatchScoreController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (restrictedEdit || readOnly)
        return;
    super.formOK(ureq);
    String maxScoreValue = maxScoreEl.getValue();
    Double maxScore = Double.parseDouble(maxScoreValue);
    itemBuilder.setMaxScore(maxScore);
    String minScoreValue = minScoreEl.getValue();
    Double minScore = Double.parseDouble(minScoreValue);
    itemBuilder.setMinScore(minScore);
    if (assessmentModeEl.isOneSelected() && assessmentModeEl.isSelected(1)) {
        itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
        itemBuilder.clearMapping();
        for (Map.Entry<DirectedPairValue, MatchScoreWrapper> entry : scoreWrappers.entrySet()) {
            DirectedPairValue directedPair = entry.getKey();
            MatchScoreWrapper scoreWrapper = entry.getValue();
            String val = scoreWrapper.getScoreEl().getValue();
            double score = Double.parseDouble(val);
            itemBuilder.addScore(directedPair, score);
        }
    } else {
        itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
        itemBuilder.clearMapping();
    }
    fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), null));
}
Also used : DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) HashMap(java.util.HashMap) Map(java.util.Map) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Example 18 with DirectedPairValue

use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.

the class MatchScoreController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    allOk &= validateMinMaxScores(minScoreEl, maxScoreEl);
    if (assessmentModeEl.isOneSelected() && assessmentModeEl.isSelected(1)) {
        for (Map.Entry<DirectedPairValue, MatchScoreWrapper> entry : scoreWrappers.entrySet()) {
            MatchScoreWrapper scoreWrapper = entry.getValue();
            TextElement scoreEl = scoreWrapper.getScoreEl();
            String val = scoreEl.getValue();
            scoreEl.clearError();
            if (StringHelper.containsNonWhitespace(val)) {
                try {
                    Double.parseDouble(val);
                } catch (NumberFormatException e) {
                    scoreEl.setErrorKey("error.double", null);
                    allOk &= false;
                }
            } else {
                scoreEl.setErrorKey("form.legende.mandatory", null);
                allOk &= false;
            }
        }
    }
    return allOk & super.validateFormLogic(ureq);
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with DirectedPairValue

use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.

the class MatchAssessmentItemBuilder method extractCorrectResponse.

private void extractCorrectResponse() {
    associations = new HashMap<>();
    if (matchInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
            CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
            List<FieldValue> values = correctResponse.getFieldValues();
            for (FieldValue value : values) {
                SingleValue sValue = value.getSingleValue();
                if (sValue instanceof DirectedPairValue) {
                    DirectedPairValue dpValue = (DirectedPairValue) sValue;
                    Identifier sourceId = dpValue.sourceValue();
                    Identifier targetId = dpValue.destValue();
                    List<Identifier> targetIds = associations.get(sourceId);
                    if (targetIds == null) {
                        targetIds = new ArrayList<>();
                        associations.put(sourceId, targetIds);
                    }
                    targetIds.add(targetId);
                }
            }
        }
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) AssessmentItemFactory.appendAssociationMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration) AssessmentItemFactory.createMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 20 with DirectedPairValue

use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.

the class MatchAssessmentItemBuilder method extractScoreEvaluationMode.

private void extractScoreEvaluationMode() {
    boolean hasMapping = false;
    if (matchInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
        if (responseDeclaration != null) {
            Mapping mapping = responseDeclaration.getMapping();
            hasMapping = (mapping != null && mapping.getMapEntries() != null && mapping.getMapEntries().size() > 0);
            if (hasMapping) {
                scoreMapping = new HashMap<>();
                for (MapEntry entry : mapping.getMapEntries()) {
                    SingleValue sValue = entry.getMapKey();
                    if (sValue instanceof DirectedPairValue) {
                        Identifier sourceIdentifier = ((DirectedPairValue) sValue).sourceValue();
                        Identifier destIdentifier = ((DirectedPairValue) sValue).destValue();
                        scoreMapping.put(new DirectedPairValue(sourceIdentifier, destIdentifier), entry.getMappedValue());
                    }
                }
            }
        }
    }
    scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) AssessmentItemFactory.appendAssociationMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration) AssessmentItemFactory.createMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Aggregations

DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)30 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)16 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)14 Map (java.util.Map)12 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)12 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)12 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)12 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)10 HashMap (java.util.HashMap)8 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)8 ArrayList (java.util.ArrayList)6 AssessmentItemFactory.appendAssociationMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration)6 AssessmentItemFactory.createMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration)6 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)6 Mapping (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping)6 HashSet (java.util.HashSet)4 List (java.util.List)4 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)4 SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)4 KPrimStatistics (org.olat.ims.qti21.model.statistics.KPrimStatistics)2