use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.
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 klemens.
the class AssessmentItemFactory method appendAssociationMatchResponseDeclaration.
public static ResponseDeclaration appendAssociationMatchResponseDeclaration(ResponseDeclaration responseDeclaration, Map<Identifier, List<Identifier>> associations) {
responseDeclaration.setCardinality(Cardinality.MULTIPLE);
responseDeclaration.setBaseType(BaseType.DIRECTED_PAIR);
// correct response
CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
responseDeclaration.setCorrectResponse(correctResponse);
for (Map.Entry<Identifier, List<Identifier>> association : associations.entrySet()) {
Identifier sourceChoiceId = association.getKey();
List<Identifier> targetChoiceIds = association.getValue();
for (Identifier targetChoiceId : targetChoiceIds) {
DirectedPairValue dpValue = new DirectedPairValue(sourceChoiceId, targetChoiceId);
FieldValue fValue = new FieldValue(correctResponse, dpValue);
correctResponse.getFieldValues().add(fValue);
}
}
return responseDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.
the class CSVToAssessmentItemConverter method processChoice_match.
private void processChoice_match(String[] parts, MatchAssessmentItemBuilder matchBuilder) {
List<SimpleAssociableChoice> targetChoices = matchBuilder.getTargetChoices();
if (targetChoices == null || targetChoices.isEmpty()) {
for (int i = 1; i < parts.length; i++) {
String answer = parts[i];
SimpleAssociableChoice choice = AssessmentItemFactory.createSimpleAssociableChoice(answer, matchBuilder.getTargetMatchSet());
targetChoices.add(choice);
}
} else {
String answer = parts[0];
if (StringHelper.containsNonWhitespace(answer)) {
SimpleAssociableChoice sourceChoice = AssessmentItemFactory.createSimpleAssociableChoice(answer, matchBuilder.getSourceMatchSet());
matchBuilder.getSourceChoices().add(sourceChoice);
// correct answer and points
for (int i = 1; i < parts.length && i < (targetChoices.size() + 1); i++) {
double point = parseFloat(parts[i], 0.0f);
SimpleAssociableChoice targetChoice = targetChoices.get(i - 1);
DirectedPairValue directedPair = new DirectedPairValue(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
matchBuilder.addScore(directedPair, Double.valueOf(point));
if (point > 0.0) {
matchBuilder.addAssociation(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.
the class MatchScoreController method forgeScoreElement.
private void forgeScoreElement(MatchWrapper sourceWrapper, MatchWrapper targetWrapper) {
Identifier sourceIdentifier = sourceWrapper.getChoiceIdentifier();
Identifier targetIdentifier = targetWrapper.getChoiceIdentifier();
DirectedPairValue dKey = new DirectedPairValue(sourceIdentifier, targetIdentifier);
if (!scoreWrappers.containsKey(dKey)) {
String key = sourceIdentifier.toString() + "-" + targetIdentifier.toString();
TextElement textEl = uifactory.addTextElement(key, null, 8, "", scoreCont);
MatchScoreWrapper scoreWrapper = new MatchScoreWrapper(sourceIdentifier, targetIdentifier, textEl);
textEl.setDomReplacementWrapperRequired(false);
textEl.setDisplaySize(5);
textEl.setUserObject(scoreWrapper);
textEl.setEnabled(!restrictedEdit && !readOnly);
Double score = itemBuilder.getScore(sourceIdentifier, targetIdentifier);
if (score == null) {
textEl.setValue("0.0");
} else {
textEl.setValue(AssessmentHelper.getRoundedScore(score));
}
scoreWrappers.put(dKey, scoreWrapper);
scoreCont.contextPut(key, scoreWrapper);
}
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.
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);
}
Aggregations