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;
}
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));
}
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);
}
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);
}
}
}
}
}
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;
}
Aggregations