use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class QTI21StatisticsManagerImpl method getMatchStatistics.
@Override
public List<MatchStatistics> getMatchStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
SimpleMatchSet sourceMatchSets = interaction.getSimpleMatchSets().get(0);
SimpleMatchSet targetMatchSets = interaction.getSimpleMatchSets().get(1);
List<MatchStatistics> matchPoints = new ArrayList<>();
ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
// readable responses
Map<Identifier, List<Identifier>> associations = new HashMap<>();
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
QtiNodesExtractor.extractIdentifiersFromCorrectResponse(correctResponse, associations);
for (SimpleAssociableChoice sourceChoice : sourceMatchSets.getSimpleAssociableChoices()) {
for (SimpleAssociableChoice targetChoice : targetMatchSets.getSimpleAssociableChoices()) {
DirectedPairValue dKey = new DirectedPairValue(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
String choiceIdentifier = dKey.toQtiString();
String marker = "[" + choiceIdentifier + "]";
boolean correct = associations.containsKey(sourceChoice.getIdentifier()) && associations.get(sourceChoice.getIdentifier()).contains(targetChoice.getIdentifier());
long numCorrect = 0;
long numIncorrect = 0;
for (RawData rawData : rawDatas) {
String response = rawData.getStringuifiedResponse();
if (response.indexOf(marker) >= 0) {
if (correct) {
numCorrect += rawData.getCount();
} else {
numIncorrect += rawData.getCount();
}
}
}
matchPoints.add(new MatchStatistics(sourceChoice.getIdentifier(), targetChoice.getIdentifier(), numCorrect, numIncorrect));
}
}
return matchPoints;
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
the class QTI21StatisticsManagerImpl method getKPrimStatistics.
// stringuifiedResponse: [a93247453265982 correct][b93247453265983 correct][c93247453265984 correct][d93247453265985 correct]
@Override
public List<KPrimStatistics> getKPrimStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
List<SimpleMatchSet> matchSets = interaction.getSimpleMatchSets();
List<KPrimStatistics> kprimPoints = new ArrayList<>();
SimpleMatchSet fourMatchSet = matchSets.get(0);
ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
// readable responses
Set<String> rightResponses = new HashSet<>();
List<MapEntry> mapEntries = responseDeclaration.getMapping().getMapEntries();
for (MapEntry mapEntry : mapEntries) {
SingleValue mapKey = mapEntry.getMapKey();
if (mapKey instanceof DirectedPairValue) {
DirectedPairValue pairValue = (DirectedPairValue) mapKey;
String source = pairValue.sourceValue().toString();
String destination = pairValue.destValue().toString();
rightResponses.add("[" + source + " " + destination + "]");
}
}
for (SimpleAssociableChoice choice : fourMatchSet.getSimpleAssociableChoices()) {
String choiceIdentifier = choice.getIdentifier().toString();
String markerCorrect = "[" + choiceIdentifier + " correct]";
String markerWrong = "[" + choiceIdentifier + " wrong]";
boolean isCorrectRight = rightResponses.contains(markerCorrect);
String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
long numCorrect = 0;
long numIncorrect = 0;
long numUnanswered = 0;
for (RawData rawData : rawDatas) {
String response = rawData.getStringuifiedResponse();
if (response.indexOf(rightFlag) >= 0) {
numCorrect += rawData.getCount();
} else if (response.indexOf(wrongFlag) >= 0) {
numIncorrect += rawData.getCount();
} else {
numUnanswered += rawData.getCount();
}
}
kprimPoints.add(new KPrimStatistics(choice.getIdentifier(), isCorrectRight, numCorrect, numIncorrect, numUnanswered));
}
return kprimPoints;
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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));
}
Aggregations