use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet in project openolat by klemens.
the class MatchInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
MatchInteraction matchInteraction = (MatchInteraction) interaction;
String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
if (!StringHelper.containsNonWhitespace(stringuifiedResponse)) {
col += matchInteraction.getSimpleMatchSets().get(0).getSimpleAssociableChoices().size();
} else {
boolean kprim = matchInteraction.getResponseIdentifier().toString().startsWith("KPRIM_") || QTI21QuestionType.hasClass(matchInteraction, QTI21Constants.CSS_MATCH_KPRIM);
Set<String> correctAnswers = CorrectResponsesUtil.getCorrectDirectPairResponses(item, matchInteraction, false);
List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
SimpleMatchSet firstMatchSet = matchInteraction.getSimpleMatchSets().get(0);
SimpleMatchSet secondMatchSet = matchInteraction.getSimpleMatchSets().get(1);
for (SimpleAssociableChoice choice : firstMatchSet.getSimpleAssociableChoices()) {
String choiceIdentifier = choice.getIdentifier().toString();
if (kprim) {
String markerCorrect = choiceIdentifier + " correct";
String markerWrong = choiceIdentifier + " wrong";
boolean isCorrectRight = correctAnswers.contains(markerCorrect);
String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
String value = null;
if (stringuifiedResponse.contains(markerCorrect)) {
value = "+";
} else if (stringuifiedResponse.contains(markerWrong)) {
value = "-";
}
if (stringuifiedResponse.indexOf(rightFlag) >= 0) {
dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
} else if (stringuifiedResponse.indexOf(wrongFlag) >= 0) {
dataRow.addCell(col++, value, null);
} else {
col++;
}
} else {
String aResponse = null;
for (String r : responses) {
if (r.startsWith(choiceIdentifier)) {
aResponse = r;
}
}
if (StringHelper.containsNonWhitespace(aResponse)) {
boolean correct = correctAnswers.contains(aResponse);
String value = null;
for (SimpleAssociableChoice association : secondMatchSet.getSimpleAssociableChoices()) {
if (aResponse.endsWith(association.getIdentifier().toString())) {
value = getContent(association);
break;
}
}
if (correct) {
dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, value, null);
}
} else {
col++;
}
}
}
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet in project openolat by klemens.
the class AssessmentItemBuilderTest method buildAssessmentItem_kprim.
@Test
public void buildAssessmentItem_kprim() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem singleChoiceItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(singleChoiceItem);
AssessmentItem reloadedItem = itemResult.getResolvedAssessmentItem().getItemLookup().extractIfSuccessful();
List<Interaction> interactions = reloadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof MatchInteraction);
MatchInteraction interaction = (MatchInteraction) interactions.get(0);
Assert.assertNotNull(interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
Assert.assertNotNull(responseDeclaration);
Assert.assertEquals(2, interaction.getSimpleMatchSets().size());
SimpleMatchSet matchSet = interaction.getSimpleMatchSets().get(0);
Assert.assertEquals(4, matchSet.getSimpleAssociableChoices().size());
SimpleMatchSet correctWrongSet = interaction.getSimpleMatchSets().get(1);
Assert.assertEquals(2, correctWrongSet.getSimpleAssociableChoices().size());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet in project openolat by klemens.
the class MatchScoreController method sync.
private List<MatchWrapper> sync(SimpleMatchSet matchSet, List<MatchWrapper> wrappers) {
Map<Identifier, MatchWrapper> currentMapping = wrappers.stream().collect(Collectors.toMap(w -> w.getChoiceIdentifier(), w -> w));
List<MatchWrapper> newWrappers = new ArrayList<>();
List<SimpleAssociableChoice> choices = matchSet.getSimpleAssociableChoices();
for (SimpleAssociableChoice choice : choices) {
if (currentMapping.containsKey(choice.getIdentifier())) {
newWrappers.add(currentMapping.get(choice.getIdentifier()));
} else {
newWrappers.add(createMatchWrapper(choice));
}
}
return newWrappers;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet in project OpenOLAT by OpenOLAT.
the class MatchInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
MatchInteraction matchInteraction = (MatchInteraction) interaction;
String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
if (!StringHelper.containsNonWhitespace(stringuifiedResponse)) {
col += matchInteraction.getSimpleMatchSets().get(0).getSimpleAssociableChoices().size();
} else {
boolean kprim = matchInteraction.getResponseIdentifier().toString().startsWith("KPRIM_") || QTI21QuestionType.hasClass(matchInteraction, QTI21Constants.CSS_MATCH_KPRIM);
Set<String> correctAnswers = CorrectResponsesUtil.getCorrectDirectPairResponses(item, matchInteraction, false);
List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
SimpleMatchSet firstMatchSet = matchInteraction.getSimpleMatchSets().get(0);
SimpleMatchSet secondMatchSet = matchInteraction.getSimpleMatchSets().get(1);
for (SimpleAssociableChoice choice : firstMatchSet.getSimpleAssociableChoices()) {
String choiceIdentifier = choice.getIdentifier().toString();
if (kprim) {
String markerCorrect = choiceIdentifier + " correct";
String markerWrong = choiceIdentifier + " wrong";
boolean isCorrectRight = correctAnswers.contains(markerCorrect);
String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
String value = null;
if (stringuifiedResponse.contains(markerCorrect)) {
value = "+";
} else if (stringuifiedResponse.contains(markerWrong)) {
value = "-";
}
if (stringuifiedResponse.indexOf(rightFlag) >= 0) {
dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
} else if (stringuifiedResponse.indexOf(wrongFlag) >= 0) {
dataRow.addCell(col++, value, null);
} else {
col++;
}
} else {
String aResponse = null;
for (String r : responses) {
if (r.startsWith(choiceIdentifier)) {
aResponse = r;
}
}
if (StringHelper.containsNonWhitespace(aResponse)) {
boolean correct = correctAnswers.contains(aResponse);
String value = null;
for (SimpleAssociableChoice association : secondMatchSet.getSimpleAssociableChoices()) {
if (aResponse.endsWith(association.getIdentifier().toString())) {
value = getContent(association);
break;
}
}
if (correct) {
dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, value, null);
}
} else {
col++;
}
}
}
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet in project OpenOLAT by OpenOLAT.
the class KPrimStatisticsController method getKPrim.
public Series getKPrim() {
List<KPrimStatistics> statisticResponses = qtiStatisticsManager.getKPrimStatistics(itemRef.getIdentifier().toString(), assessmentItem, interaction, resourceResult.getSearchParams());
// TODO String mediaBaseURL = resourceResult.getMediaBaseURL();
boolean survey = QTIType.survey.equals(resourceResult.getType());
int numOfParticipants = resourceResult.getQTIStatisticAssessment().getNumOfParticipants();
List<SimpleMatchSet> matchSets = interaction.getSimpleMatchSets();
SimpleMatchSet fourMatchSet = matchSets.get(0);
int i = 0;
BarSeries d1 = new BarSeries("bar_green", "green", translate("answer.correct"));
BarSeries d2 = new BarSeries("bar_red", "red", translate("answer.false"));
BarSeries d3 = new BarSeries("bar_grey", "grey", translate("answer.noanswer"));
List<ResponseInfos> responseInfos = new ArrayList<>();
for (KPrimStatistics statisticResponse : statisticResponses) {
Identifier choiceIdentifier = statisticResponse.getChoiceIdentifier();
boolean correctRight = statisticResponse.isCorrectRight();
double right = statisticResponse.getNumOfCorrect();
double wrong = statisticResponse.getNumOfIncorrect();
double notanswered = numOfParticipants - right - wrong;
String label = Integer.toString(++i);
d1.add(right, label);
d2.add(wrong, label);
d3.add(notanswered, label);
String text = "";
for (SimpleAssociableChoice choice : fourMatchSet.getSimpleAssociableChoices()) {
if (choice.getIdentifier().equals(choiceIdentifier)) {
String textFlow = assessmentHtmlBuilder.flowStaticString(choice.getFlowStatics());
text = Formatter.formatLatexFormulas(textFlow);
}
}
responseInfos.add(new ResponseInfos(label, text, null, correctRight, survey, true));
}
List<BarSeries> serieList = new ArrayList<>(3);
serieList.add(d1);
serieList.add(d2);
serieList.add(d3);
Series series = new Series(serieList, responseInfos, numOfParticipants, !survey);
series.setChartType(survey ? SeriesFactory.BAR_ANSWERED : SeriesFactory.BAR_CORRECT_WRONG_NOT);
series.setItemCss("o_mi_qtikprim");
return series;
}
Aggregations