use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project OpenOLAT by OpenOLAT.
the class SingleChoiceAssessmentItemBuilderTest method createSingleAssessmentItem_allCorrectAnswers.
@Test
public void createSingleAssessmentItem_allCorrectAnswers() throws IOException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "Single choice", qtiSerializer);
itemBuilder.setQuestion("<p>Hello</p>");
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
SimpleChoice choice1 = AssessmentItemFactory.createSimpleChoice(interaction, "One", "sc");
SimpleChoice choice2 = AssessmentItemFactory.createSimpleChoice(interaction, "Two", "sc");
SimpleChoice choice3 = AssessmentItemFactory.createSimpleChoice(interaction, "Three", "sc");
List<SimpleChoice> choiceList = new ArrayList<>();
choiceList.add(choice1);
choiceList.add(choice2);
choiceList.add(choice3);
itemBuilder.setSimpleChoices(choiceList);
itemBuilder.setCorrectAnswer(choice2.getIdentifier());
itemBuilder.setMaxScore(3.0d);
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
itemBuilder.build();
File itemFile = new File(WebappHelper.getTmpDir(), "scAssessmentItem" + UUID.randomUUID() + ".xml");
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(itemBuilder.getAssessmentItem(), out);
} catch (Exception e) {
log.error("", e);
}
{
// correct answers
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData(choice2.getIdentifier().toString()));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(3.0d), score);
}
{
// wrong answer
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData(choice3.getIdentifier().toString()));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(0.0d), score);
}
FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project OpenOLAT by OpenOLAT.
the class RunningItemHelper method run.
public static ItemSessionController run(URI inputUri, Map<Identifier, ResponseData> responseMap, ResourceLocator inputResourceLocator) {
SimpleJqtiFacade simpleJqtiFacade = new SimpleJqtiFacade();
ResolvedAssessmentItem resolvedAssessmentItem = simpleJqtiFacade.loadAndResolveAssessmentItem(inputResourceLocator, inputUri);
ItemProcessingMap itemProcessingMap = new ItemProcessingInitializer(resolvedAssessmentItem, false).initialize();
ItemSessionState itemSessionState = new ItemSessionState();
ItemSessionControllerSettings itemSessionControllerSettings = new ItemSessionControllerSettings();
ItemSessionController itemSessionController = simpleJqtiFacade.createItemSessionController(itemSessionControllerSettings, itemProcessingMap, itemSessionState);
itemSessionController.initialize(new Date());
itemSessionController.performTemplateProcessing(new Date());
itemSessionController.enterItem(new Date());
itemSessionController.bindResponses(new Date(), responseMap);
itemSessionController.commitResponses(new Date());
itemSessionController.performResponseProcessing(new Date());
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
assessmentItem.getItemBody().willShowFeedback(itemSessionController);
itemSessionController.endItem(new Date());
itemSessionController.exitItem(new Date());
return itemSessionController;
}
use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project OpenOLAT by OpenOLAT.
the class AssessmentItemDisplayController method createNewItemSessionStateAndController.
public ItemSessionController createNewItemSessionStateAndController(NotificationRecorder notificationRecorder) {
/* Resolve the underlying JQTI+ object */
final ItemProcessingMap itemProcessingMap = getItemProcessingMap();
if (itemProcessingMap == null) {
return null;
}
/* Create fresh state for session */
final ItemSessionState itemSessionState = new ItemSessionState();
/* Create config for ItemSessionController */
final ItemSessionControllerSettings itemSessionControllerSettings = new ItemSessionControllerSettings();
itemSessionControllerSettings.setTemplateProcessingLimit(computeTemplateProcessingLimit());
itemSessionControllerSettings.setMaxAttempts(10);
/* Create controller and wire up notification recorder */
final ItemSessionController result = new ItemSessionController(qtiService.jqtiExtensionManager(), itemSessionControllerSettings, itemProcessingMap, itemSessionState);
if (notificationRecorder != null) {
result.addNotificationListener(notificationRecorder);
}
return result;
}
use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method resumeSession.
private TestSessionController resumeSession(UserRequest ureq) {
Date requestTimestamp = ureq.getRequestTimestamp();
final NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionController controller = createTestSessionController(notificationRecorder);
if (!controller.getTestSessionState().isEnded() && !controller.getTestSessionState().isExited()) {
controller.unsuspendTestSession(requestTimestamp);
TestSessionState testSessionState = controller.getTestSessionState();
TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
if (currentItemKey != null) {
TestPlanNode currentItemNode = testSessionState.getTestPlan().getNode(currentItemKey);
ItemProcessingContext itemProcessingContext = controller.getItemProcessingContext(currentItemNode);
ItemSessionState itemSessionState = itemProcessingContext.getItemSessionState();
if (itemProcessingContext instanceof ItemSessionController && itemSessionState.isSuspended()) {
ItemSessionController itemSessionController = (ItemSessionController) itemProcessingContext;
itemSessionController.unsuspendItemSession(requestTimestamp);
}
}
}
return controller;
}
use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method suspendAssessmentTest.
/**
* It suspend the current item
* @return
*/
private boolean suspendAssessmentTest(Date requestTimestamp) {
if (!deliveryOptions.isEnableSuspend() || testSessionController == null || testSessionController.getTestSessionState() == null || testSessionController.getTestSessionState().isEnded() || testSessionController.getTestSessionState().isExited() || testSessionController.getTestSessionState().isSuspended()) {
return false;
}
testSessionController.touchDurations(currentRequestTimestamp);
testSessionController.suspendTestSession(requestTimestamp);
TestSessionState testSessionState = testSessionController.getTestSessionState();
TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
if (currentItemKey == null) {
return false;
}
TestPlanNode currentItemNode = testSessionState.getTestPlan().getNode(currentItemKey);
ItemProcessingContext itemProcessingContext = testSessionController.getItemProcessingContext(currentItemNode);
ItemSessionState itemSessionState = itemProcessingContext.getItemSessionState();
if (itemProcessingContext instanceof ItemSessionController && !itemSessionState.isEnded() && !itemSessionState.isExited() && itemSessionState.isOpen() && !itemSessionState.isSuspended()) {
ItemSessionController itemSessionController = (ItemSessionController) itemProcessingContext;
itemSessionController.suspendItemSession(requestTimestamp);
computeAndRecordTestAssessmentResult(requestTimestamp, testSessionState, false);
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.SUSPEND, null, null, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateEvent);
this.lastEvent = candidateEvent;
return true;
}
return false;
}
Aggregations