use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectIntegerResponses.
public static final List<Integer> getCorrectIntegerResponses(AssessmentItem assessmentItem, Interaction interaction) {
List<Integer> correctAnswers = new ArrayList<>(5);
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse.getCardinality().isOneOf(Cardinality.SINGLE)) {
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
if (value instanceof IntegerValue) {
IntegerValue identifierValue = (IntegerValue) value;
correctAnswers.add(identifierValue.intValue());
}
} else if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
if (value instanceof MultipleValue) {
MultipleValue multiValue = (MultipleValue) value;
for (SingleValue sValue : multiValue.getAll()) {
if (sValue instanceof IntegerValue) {
IntegerValue identifierValue = (IntegerValue) value;
correctAnswers.add(identifierValue.intValue());
}
}
}
}
}
return correctAnswers;
}
use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue 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);
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method createOutcomeDeclarationForScoreResponse.
/*
<outcomeDeclaration identifier="SCORE_RESPONSE_2" cardinality="single" baseType="float" view="testConstructor">
<defaultValue>
<value>0</value>
</defaultValue>
</outcomeDeclaration>
*/
public static OutcomeDeclaration createOutcomeDeclarationForScoreResponse(AssessmentItem assessmentItem, String scoreIdentifier) {
OutcomeDeclaration scoreOutcomeDeclaration = new OutcomeDeclaration(assessmentItem);
scoreOutcomeDeclaration.setIdentifier(Identifier.parseString(scoreIdentifier));
scoreOutcomeDeclaration.setCardinality(Cardinality.SINGLE);
scoreOutcomeDeclaration.setBaseType(BaseType.FLOAT);
DefaultValue scoreDefaultVal = new DefaultValue(scoreOutcomeDeclaration);
scoreOutcomeDeclaration.setDefaultValue(scoreDefaultVal);
FieldValue scoreDefaultFieldVal = new FieldValue(scoreDefaultVal, FloatValue.ZERO);
scoreDefaultVal.getFieldValues().add(scoreDefaultFieldVal);
return scoreOutcomeDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendFloatValue.
private static void appendFloatValue(CorrectResponse correctResponse, double response) {
FieldValue fieldValue = new FieldValue(correctResponse);
FloatValue identifierValue = new FloatValue(response);
fieldValue.setSingleValue(identifierValue);
correctResponse.getFieldValues().add(fieldValue);
}
use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendIdentifierValue.
private static void appendIdentifierValue(CorrectResponse correctResponse, Identifier correctResponseId) {
FieldValue fieldValue = new FieldValue(correctResponse);
IdentifierValue identifierValue = new IdentifierValue(correctResponseId);
fieldValue.setSingleValue(identifierValue);
correctResponse.getFieldValues().add(fieldValue);
}
Aggregations