Search in sources :

Example 21 with ItemSessionController

use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project OpenOLAT by OpenOLAT.

the class AssessmentTestComponent method willShowFeedbacks.

/**
 * Check if the assessment item will show some
 * form of feedback like feedbackElement, modalFeedback
 * or message as invalid or bad response.
 *
 * @param itemNode
 * @return
 */
public boolean willShowFeedbacks(TestPlanNode itemNode) {
    if (isHideFeedbacks()) {
        return false;
    }
    try {
        URI itemSystemId = itemNode.getItemSystemId();
        ResolvedAssessmentItem resolvedAssessmentItem = getResolvedAssessmentTest().getResolvedAssessmentItemBySystemIdMap().get(itemSystemId);
        AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        if (assessmentItem.getAdaptive()) {
            return true;
        }
        ItemSessionState itemSessionState = getItemSessionState(itemNode.getKey());
        if (!itemSessionState.isResponded()) {
            return true;
        }
        ItemProcessingContext itemContext = getTestSessionController().getItemProcessingContext(itemNode);
        if (itemContext instanceof ItemSessionController) {
            ItemSessionController itemSessionController = (ItemSessionController) itemContext;
            List<Interaction> interactions = itemSessionController.getInteractions();
            for (Interaction interaction : interactions) {
                if (AssessmentRenderFunctions.isBadResponse(itemSessionState, interaction.getResponseIdentifier())) {
                    return true;
                }
                if (AssessmentRenderFunctions.isInvalidResponse(itemSessionState, interaction.getResponseIdentifier())) {
                    return true;
                }
            }
        }
        if (assessmentItem.getItemBody().willShowFeedback(itemContext)) {
            return true;
        }
        List<ModalFeedback> modalFeedbacks = assessmentItem.getModalFeedbacks();
        for (ModalFeedback modalFeedback : modalFeedbacks) {
            if (isFeedback(modalFeedback, itemSessionState)) {
                return true;
            }
        }
    } catch (Exception e) {
        log.error("", e);
    }
    return false;
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) URI(java.net.URI) ItemProcessingContext(uk.ac.ed.ph.jqtiplus.running.ItemProcessingContext)

Example 22 with ItemSessionController

use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project OpenOLAT by OpenOLAT.

the class UnkownItemEditorController method createNewItemSessionStateAndController.

private ItemSessionController createNewItemSessionStateAndController() {
    /* Resolve the underlying JQTI+ object */
    final ItemProcessingMap itemProcessingMap = new ItemProcessingInitializer(resolvedAssessmentItem, true).initialize();
    /* Create fresh state for session */
    final ItemSessionState itemSessionState = new ItemSessionState();
    final ItemSessionControllerSettings itemSessionControllerSettings = new ItemSessionControllerSettings();
    itemSessionControllerSettings.setTemplateProcessingLimit(25);
    itemSessionControllerSettings.setMaxAttempts(10);
    /* Create controller and wire up notification recorder */
    final ItemSessionController sessionController = new ItemSessionController(qtiService.jqtiExtensionManager(), itemSessionControllerSettings, itemProcessingMap, itemSessionState);
    sessionController.addNotificationListener(new NotificationRecorder(NotificationLevel.ERROR));
    Long randomSeed = new Random().nextLong();
    sessionController.setRandomSeed(randomSeed);
    sessionController.initialize(new Date());
    sessionController.performTemplateProcessing(new Date());
    return sessionController;
}
Also used : ItemSessionControllerSettings(uk.ac.ed.ph.jqtiplus.running.ItemSessionControllerSettings) ItemProcessingMap(uk.ac.ed.ph.jqtiplus.state.ItemProcessingMap) Random(java.util.Random) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) NotificationRecorder(uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder) ItemProcessingInitializer(uk.ac.ed.ph.jqtiplus.running.ItemProcessingInitializer) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) Date(java.util.Date)

Example 23 with ItemSessionController

use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project openolat by klemens.

the class HottextAssessmentItemBuilderTest method createHottextAssessmentItem_perAnswer.

/**
 * This is an hottextInteraction with 3 choices, one with 3.0 points and correct,
 * one with 0.0 points but correct and one false with -1.0 points.
 *
 * @throws IOException
 */
@Test
public void createHottextAssessmentItem_perAnswer() throws IOException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder("Hot texts", "This is a hot ", "text", qtiSerializer);
    itemBuilder.setQuestion("<p>This is <hottext identifier=\"RESPONSE_HOT_1\">hot</hottext>, <hottext identifier=\"RESPONSE_HOT_2\">cold</hottext> or <hottext identifier=\"RESPONSE_HOT_3\">freezing</hottext></p>");
    itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_2"));
    itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_3"));
    itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_1"), -1.0d);
    itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_2"), 0.0d);
    itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_3"), 3.0d);
    itemBuilder.setMaxScore(3.0d);
    itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
    itemBuilder.build();
    File itemFile = new File(WebappHelper.getTmpDir(), "hottextAssessmentItem" + 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("RESPONSE_HOT_2", "RESPONSE_HOT_3"));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(3.0d), score);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.CORRECT_IDENTIFIER), feedbackBasic);
    }
    {
        // max score but not all correct
        Map<Identifier, ResponseData> responseMap = new HashMap<>();
        Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
        responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_3"));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(3.0d), score);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
    }
    {
        // all wrong
        Map<Identifier, ResponseData> responseMap = new HashMap<>();
        Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
        responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_1"));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(0.0d), score);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
    }
    FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
Also used : HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) FileOutputStream(java.io.FileOutputStream) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 24 with ItemSessionController

use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project openolat by klemens.

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;
}
Also used : ItemSessionControllerSettings(uk.ac.ed.ph.jqtiplus.running.ItemSessionControllerSettings) ItemProcessingMap(uk.ac.ed.ph.jqtiplus.state.ItemProcessingMap) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ItemProcessingInitializer(uk.ac.ed.ph.jqtiplus.running.ItemProcessingInitializer) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) SimpleJqtiFacade(uk.ac.ed.ph.jqtiplus.SimpleJqtiFacade) Date(java.util.Date)

Example 25 with ItemSessionController

use of uk.ac.ed.ph.jqtiplus.running.ItemSessionController in project openolat by klemens.

the class AssessmentTestComponent method willShowFeedbacks.

/**
 * Check if the assessment item will show some
 * form of feedback like feedbackElement, modalFeedback
 * or message as invalid or bad response.
 *
 * @param itemNode
 * @return
 */
public boolean willShowFeedbacks(TestPlanNode itemNode) {
    if (isHideFeedbacks()) {
        return false;
    }
    try {
        URI itemSystemId = itemNode.getItemSystemId();
        ResolvedAssessmentItem resolvedAssessmentItem = getResolvedAssessmentTest().getResolvedAssessmentItemBySystemIdMap().get(itemSystemId);
        AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        if (assessmentItem.getAdaptive()) {
            return true;
        }
        ItemSessionState itemSessionState = getItemSessionState(itemNode.getKey());
        if (!itemSessionState.isResponded()) {
            return true;
        }
        ItemProcessingContext itemContext = getTestSessionController().getItemProcessingContext(itemNode);
        if (itemContext instanceof ItemSessionController) {
            ItemSessionController itemSessionController = (ItemSessionController) itemContext;
            List<Interaction> interactions = itemSessionController.getInteractions();
            for (Interaction interaction : interactions) {
                if (AssessmentRenderFunctions.isBadResponse(itemSessionState, interaction.getResponseIdentifier())) {
                    return true;
                }
                if (AssessmentRenderFunctions.isInvalidResponse(itemSessionState, interaction.getResponseIdentifier())) {
                    return true;
                }
            }
        }
        if (assessmentItem.getItemBody().willShowFeedback(itemContext)) {
            return true;
        }
        List<ModalFeedback> modalFeedbacks = assessmentItem.getModalFeedbacks();
        for (ModalFeedback modalFeedback : modalFeedbacks) {
            if (isFeedback(modalFeedback, itemSessionState)) {
                return true;
            }
        }
    } catch (Exception e) {
        log.error("", e);
    }
    return false;
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) URI(java.net.URI) ItemProcessingContext(uk.ac.ed.ph.jqtiplus.running.ItemProcessingContext)

Aggregations

ItemSessionController (uk.ac.ed.ph.jqtiplus.running.ItemSessionController)26 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)20 Date (java.util.Date)12 NotificationRecorder (uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder)10 HashMap (java.util.HashMap)8 ItemProcessingContext (uk.ac.ed.ph.jqtiplus.running.ItemProcessingContext)8 ItemSessionControllerSettings (uk.ac.ed.ph.jqtiplus.running.ItemSessionControllerSettings)8 ItemProcessingMap (uk.ac.ed.ph.jqtiplus.state.ItemProcessingMap)8 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)8 StringResponseData (uk.ac.ed.ph.jqtiplus.types.StringResponseData)8 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)8 Value (uk.ac.ed.ph.jqtiplus.value.Value)8 File (java.io.File)6 FileOutputStream (java.io.FileOutputStream)6 IOException (java.io.IOException)6 URISyntaxException (java.net.URISyntaxException)6 Map (java.util.Map)6 Test (org.junit.Test)6 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)6 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)6