use of uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction in project OpenOLAT by OpenOLAT.
the class MultipleChoiceAssessmentItemBuilderTest method readMultipleChoice_allAnswers_1110.
@Test
public void readMultipleChoice_allAnswers_1110() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/multiple-choice-score-all-11-1-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(2, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof ChoiceInteraction);
Assert.assertTrue(interactions.get(1) instanceof EndAttemptInteraction);
// choices
SimpleChoice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("mc1959a495d449f9af65b38695d3aff1"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
SimpleChoice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("mca856e7adb54d3f9af06ecf9c00da69"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
SimpleChoice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("mcd39be64a6b4f20a2372cba44340e59"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
SimpleChoice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("mc18648f96a84d479817cb5e81165c80"));
Assert.assertFalse(itemBuilder.isCorrect(wrong2));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(2.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// correct feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertNotNull(correctFeedback.getText());
Assert.assertTrue(correctFeedback.getText().contains("All answers are correct"));
// incorrect
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertNotNull(incorrectFeedback.getText());
Assert.assertTrue(incorrectFeedback.getText().contains("You missed something"));
// hint
ModalFeedbackBuilder hint = itemBuilder.getHint();
Assert.assertNotNull(hint);
Assert.assertNotNull(hint.getText());
Assert.assertTrue(hint.getText().contains("This is the correct solution"));
// per answer
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest method buildAssessmentItem_singleChoice.
/**
* Check if a bare bone single choice created with our builder make a valid assessmentItem.
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void buildAssessmentItem_singleChoice() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(assessmentItem);
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 ChoiceInteraction);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest method buildAssessmentItem_essay.
@Test
public void buildAssessmentItem_essay() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
EssayAssessmentItemBuilder itemBuilder = new EssayAssessmentItemBuilder("Essay", qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(assessmentItem);
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 ExtendedTextInteraction);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method writeDataRow.
private void writeDataRow(int num, SessionResponses responses, OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
int col = 0;
Row dataRow = exportSheet.newRow();
// sequence number
dataRow.addCell(col++, num, null);
AssessmentTestSession testSession = responses.getTestSession();
AssessmentEntry entry = testSession.getAssessmentEntry();
Identity assessedIdentity = entry.getIdentity();
// user properties
if (assessedIdentity == null) {
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
if (userPropertyHandlers.get(0) == userPropertyHandler) {
dataRow.addCell(col++, translator.translate("anonym.user"), null);
} else {
col++;
}
}
}
} else if (anonymizerCallback != null) {
String anonymizedName = anonymizerCallback.getAnonymizedUserName(assessedIdentity);
dataRow.addCell(col++, anonymizedName, null);
} else {
User assessedUser = assessedIdentity.getUser();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
String property = userPropertyHandler.getUserProperty(assessedUser, translator.getLocale());
dataRow.addCell(col++, property, null);
}
}
}
// homepage
if (anonymizerCallback == null) {
String homepage;
if (entry.getIdentity() == null) {
homepage = "";
} else {
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(entry.getIdentity());
homepage = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
}
dataRow.addCell(col++, homepage, null);
}
// course node points and passed
if (courseNode instanceof AssessableCourseNode) {
AssessableCourseNode assessableCourseNode = (AssessableCourseNode) courseNode;
if (assessableCourseNode.hasScoreConfigured()) {
if (entry.getScore() != null) {
dataRow.addCell(col++, entry.getScore(), null);
} else {
col++;
}
}
if (assessableCourseNode.hasPassedConfigured()) {
if (entry.getPassed() != null) {
dataRow.addCell(col++, entry.getPassed().toString(), null);
} else {
col++;
}
}
}
// assesspoints, passed, ipaddress, date, duration
if (testSession.getScore() != null) {
dataRow.addCell(col++, testSession.getScore(), null);
} else {
col++;
}
if (testSession.getManualScore() != null) {
dataRow.addCell(col++, testSession.getManualScore(), null);
} else {
col++;
}
if (testSession.getFinalScore() != null) {
dataRow.addCell(col++, testSession.getFinalScore(), null);
} else {
col++;
}
if (testSession.getPassed() != null) {
dataRow.addCell(col++, testSession.getPassed().toString(), null);
} else {
col++;
}
if (anonymizerCallback == null) {
dataRow.addCell(col++, testSession.getCreationDate(), workbook.getStyles().getDateStyle());
}
dataRow.addCell(col++, toDurationInMilliseconds(testSession.getDuration()), null);
List<AbstractInfos> infos = getItemInfos();
for (int i = 0; i < infos.size(); i++) {
AbstractInfos info = infos.get(i);
if (info instanceof ItemInfos) {
ItemInfos item = (ItemInfos) info;
AssessmentItemRef itemRef = item.getAssessmentItemRef();
String itemRefIdentifier = itemRef.getIdentifier().toString();
AssessmentItemSession itemSession = responses.getItemSession(itemRefIdentifier);
if (exportConfig.isResponseCols()) {
List<Interaction> interactions = item.getInteractions();
for (int j = 0; j < interactions.size(); j++) {
Interaction interaction = interactions.get(j);
AssessmentResponse response = responses.getResponse(itemRefIdentifier, interaction.getResponseIdentifier());
col = interactionArchiveMap.get(interaction.getQtiClassName()).writeInteractionData(item.getAssessmentItem(), response, interaction, j, dataRow, col, workbook);
}
}
// score, start, duration
if (itemSession == null) {
if (exportConfig.isPointCol()) {
col++;
}
if (exportConfig.isCommentCol()) {
col++;
}
if (exportConfig.isTimeCols()) {
col += anonymizerCallback != null ? 1 : 2;
}
} else {
if (exportConfig.isPointCol()) {
if (itemSession.getManualScore() != null) {
dataRow.addCell(col++, itemSession.getManualScore(), null);
} else {
dataRow.addCell(col++, itemSession.getScore(), null);
}
}
if (exportConfig.isCommentCol()) {
dataRow.addCell(col++, itemSession.getCoachComment(), null);
}
if (exportConfig.isTimeCols()) {
if (anonymizerCallback == null) {
dataRow.addCell(col++, itemSession.getCreationDate(), workbook.getStyles().getTimeStyle());
}
dataRow.addCell(col++, toDurationInMilliseconds(itemSession.getDuration()), null);
}
}
} else if (numOfSections > 1 && info instanceof SectionInfos) {
SectionInfos section = (SectionInfos) info;
if (!section.getItemInfos().isEmpty()) {
BigDecimal score = calculateSectionScore(responses, section);
if (score != null) {
dataRow.addCell(col++, score, workbook.getStyles().getLightGrayStyle());
} else {
col++;
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method writeHeaders_1.
private void writeHeaders_1(OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
CellStyle headerStyle = workbook.getStyles().getHeaderStyle();
// first header
Row header1Row = exportSheet.newRow();
int col = 1;
if (anonymizerCallback != null) {
// anonymized name -> test duration
col += 0;
} else {
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
col++;
}
}
// homepage -> test duration
col += 1;
}
// course node points and passed
if (courseNode instanceof AssessableCourseNode) {
AssessableCourseNode assessableCourseNode = (AssessableCourseNode) courseNode;
if (assessableCourseNode.hasScoreConfigured()) {
header1Row.addCell(col++, translator.translate("archive.table.header.node"), headerStyle);
}
if (assessableCourseNode.hasPassedConfigured()) {
if (assessableCourseNode.hasScoreConfigured()) {
col++;
} else {
header1Row.addCell(col++, translator.translate("archive.table.header.node"), headerStyle);
}
}
}
// test points, passed and dates
header1Row.addCell(col++, translator.translate("archive.table.header.test"), headerStyle);
col += 5;
List<AbstractInfos> infos = getItemInfos();
for (int i = 0; i < infos.size(); i++) {
int delta = col;
AbstractInfos info = infos.get(i);
if (info instanceof ItemInfos) {
ItemInfos item = (ItemInfos) info;
if (exportConfig.isResponseCols() || exportConfig.isPointCol() || exportConfig.isTimeCols() || exportConfig.isCommentCol()) {
List<Interaction> interactions = item.getInteractions();
for (int j = 0; j < interactions.size(); j++) {
Interaction interaction = interactions.get(j);
col = interactionArchiveMap.get(interaction.getQtiClassName()).writeHeader1(item.getAssessmentItem(), interaction, i, j, header1Row, col, workbook);
}
}
if (!exportConfig.isResponseCols()) {
col -= col - delta;
}
if (exportConfig.isPointCol()) {
col++;
}
if (exportConfig.isCommentCol()) {
col++;
}
if (exportConfig.isTimeCols()) {
col += anonymizerCallback != null ? 1 : 2;
}
} else if (numOfSections > 1 && info instanceof SectionInfos) {
SectionInfos section = (SectionInfos) info;
if (!section.getItemInfos().isEmpty()) {
String sectionTitle = translator.translate("archive.table.header.section", new String[] { section.getAssessmentSection().getTitle() });
header1Row.addCell(col++, sectionTitle, headerStyle);
}
}
}
}
Aggregations