use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectOrderedIdentifierResponses.
public static final List<Identifier> getCorrectOrderedIdentifierResponses(AssessmentItem assessmentItem, Interaction interaction) {
List<Identifier> 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.ORDERED)) {
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.ORDERED, values);
if (value instanceof OrderedValue) {
OrderedValue multiValue = (OrderedValue) value;
multiValue.forEach(oValue -> {
if (oValue instanceof IdentifierValue) {
IdentifierValue identifierValue = (IdentifierValue) oValue;
Identifier correctAnswer = identifierValue.identifierValue();
correctAnswers.add(correctAnswer);
}
});
}
}
}
return correctAnswers;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectAnsweredResponses.
/**
* Calculate the list of correct responses found in the response of the assessed user.
*
* @param item
* @param choiceInteraction
* @param stringuifiedResponse
* @return
*/
public static final List<Identifier> getCorrectAnsweredResponses(AssessmentItem assessmentItem, ChoiceInteraction choiceInteraction, String stringuifiedResponse) {
List<Identifier> correctAnsweredResponses;
if (StringHelper.containsNonWhitespace(stringuifiedResponse)) {
List<Identifier> correctResponses = getCorrectIdentifierResponses(assessmentItem, choiceInteraction);
correctAnsweredResponses = new ArrayList<>(correctResponses.size());
for (Identifier correctResponse : correctResponses) {
String correctIdentifier = correctResponse.toString();
boolean correct = stringuifiedResponse.contains("[" + correctIdentifier + "]");
if (correct) {
correctAnsweredResponses.add(correctResponse);
}
}
} else {
correctAnsweredResponses = Collections.emptyList();
}
return correctAnsweredResponses;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectIdentifierResponses.
public static final List<Identifier> getCorrectIdentifierResponses(AssessmentItem assessmentItem, Identifier responseIdentifier) {
List<Identifier> correctAnswers = new ArrayList<>(5);
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(responseIdentifier);
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 IdentifierValue) {
IdentifierValue identifierValue = (IdentifierValue) value;
Identifier correctAnswer = identifierValue.identifierValue();
correctAnswers.add(correctAnswer);
}
} 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 IdentifierValue) {
IdentifierValue identifierValue = (IdentifierValue) sValue;
Identifier correctAnswer = identifierValue.identifierValue();
correctAnswers.add(correctAnswer);
}
}
}
}
}
return correctAnswers;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier 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.types.Identifier in project OpenOLAT by OpenOLAT.
the class AssessmentTestHelper method getParentSection.
public static ParentPartItemRefs getParentSection(TestPlanNodeKey itemKey, TestSessionState testSessionState, ResolvedAssessmentTest resolvedAssessmentTest) {
ParentPartItemRefs parentParts = new ParentPartItemRefs();
try {
TestPlanNode currentItem = testSessionState.getTestPlan().getNode(itemKey);
List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getItemRefsBySystemIdMap().get(currentItem.getItemSystemId());
AssessmentItemRef itemRef = null;
if (itemRefs.size() == 1) {
itemRef = itemRefs.get(0);
} else {
Identifier itemId = itemKey.getIdentifier();
for (AssessmentItemRef ref : itemRefs) {
if (ref.getIdentifier().equals(itemId)) {
itemRef = ref;
break;
}
}
}
if (itemRef != null) {
for (QtiNode parentPart = itemRef.getParent(); parentPart != null; parentPart = parentPart.getParent()) {
if (parentParts.getSectionIdentifier() == null && parentPart instanceof AssessmentSection) {
AssessmentSection section = (AssessmentSection) parentPart;
parentParts.setSectionIdentifier(section.getIdentifier().toString());
} else if (parentParts.getTestPartIdentifier() == null && parentPart instanceof TestPart) {
TestPart testPart = (TestPart) parentPart;
parentParts.setTestPartIdentifier(testPart.getIdentifier().toString());
}
}
}
} catch (Exception e) {
log.error("", e);
}
return parentParts;
}
Aggregations