use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class QTI21StatisticsManagerImpl method getTextEntryInteractionsStatistic.
@Override
public List<AbstractTextEntryInteractionStatistics> getTextEntryInteractionsStatistic(String itemRefIdent, AssessmentItem item, List<TextEntryInteraction> interactions, QTI21StatisticSearchParams searchParams) {
List<AbstractTextEntryInteractionStatistics> options = new ArrayList<>();
Map<String, AbstractTextEntryInteractionStatistics> optionMap = new HashMap<>();
for (TextEntryInteraction interaction : interactions) {
Identifier responseIdentifier = interaction.getResponseIdentifier();
ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
if (responseDeclaration.hasBaseType(BaseType.STRING)) {
TextEntryInteractionStatistics stats = getTextEntryInteractionSettings(responseIdentifier, responseDeclaration);
optionMap.put(responseIdentifier.toString(), stats);
options.add(stats);
} else if (responseDeclaration.hasBaseType(BaseType.FLOAT)) {
NumericalInputInteractionStatistics stats = getNumericalInputInteractionSettings(responseIdentifier, responseDeclaration, item);
optionMap.put(responseIdentifier.toString(), stats);
options.add(stats);
}
}
for (TextEntryInteraction interaction : interactions) {
String responseIdentifier = interaction.getResponseIdentifier().toString();
List<RawData> datas = getRawDatas(itemRefIdent, responseIdentifier, searchParams);
for (RawData data : datas) {
Long count = data.getCount();
if (count != null && count.longValue() > 0) {
AbstractTextEntryInteractionStatistics stats = optionMap.get(responseIdentifier);
String response = data.getStringuifiedResponse();
if (response != null && response.length() >= 2 && response.startsWith("[") && response.endsWith("]")) {
response = response.substring(1, response.length() - 1);
}
if (stats.matchResponse(response)) {
stats.addCorrect(count.longValue());
} else {
stats.addIncorrect(count.longValue());
stats.addWrongResponses(response);
}
}
}
}
return options;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
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 klemens.
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 klemens.
the class AuditLogFormatter method logOutcomes.
protected static void logOutcomes(Map<Identifier, String> outcomes, Writer writer) throws IOException {
writer.append("QTI21 audit outcomes=");
if (outcomes == null || outcomes.isEmpty()) {
writer.write("EMPTY");
} else {
writer.write("params=");
for (Map.Entry<Identifier, String> responseEntry : outcomes.entrySet()) {
Identifier identifier = responseEntry.getKey();
String stringuifiedValue = responseEntry.getValue();
writer.append("|");
writer.append(identifier.toString());
writer.append("=");
if (stringuifiedValue == null) {
writer.append("NULL");
} else {
writer.append(stringuifiedValue);
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class AbstractChoiceInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
String stringuifiedResponses = response == null ? null : response.getStringuifiedResponse();
List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectIdentifierResponses(item, interaction);
List<? extends Choice> choices = getChoices(interaction);
if (StringHelper.containsNonWhitespace(stringuifiedResponses)) {
for (int i = 0; i < choices.size(); i++) {
Identifier choiceIdentifier = choices.get(i).getIdentifier();
if (stringuifiedResponses.contains("[" + choiceIdentifier + "]")) {
if (correctAnswers.contains(choiceIdentifier)) {
// the checked answer is correct
dataRow.addCell(col++, "x", workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, "x");
}
} else {
col++;
}
}
} else {
col += choices.size();
}
return col;
}
Aggregations