Search in sources :

Example 6 with TestPlanNodeKey

use of uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey in project OpenOLAT by OpenOLAT.

the class AssessmentTestDisplayController method handleTemporaryResponse.

private void handleTemporaryResponse(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap) {
    NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
    TestSessionState testSessionState = testSessionController.getTestSessionState();
    TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
    if (currentItemKey == null) {
        // 
        return;
    }
    String cmd = ureq.getParameter("tmpResponse");
    if (!qtiWorksCtrl.validateResponseIdentifierCommand(cmd, currentItemKey)) {
        // this is not the right node in the plan
        return;
    }
    final Date timestamp = ureq.getRequestTimestamp();
    final Map<Identifier, ResponseData> responseDataMap = new HashMap<>();
    if (stringResponseMap != null) {
        for (final Entry<Identifier, ResponseInput> responseEntry : stringResponseMap.entrySet()) {
            final Identifier identifier = responseEntry.getKey();
            final ResponseInput responseData = responseEntry.getValue();
            if (responseData instanceof StringInput) {
                responseDataMap.put(identifier, new StringResponseData(((StringInput) responseData).getResponseData()));
            }
        }
    }
    ParentPartItemRefs parentParts = getParentSection(currentItemKey);
    String assessmentItemIdentifier = currentItemKey.getIdentifier().toString();
    AssessmentItemSession itemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, assessmentItemIdentifier);
    TestPlanNode currentItemRefNode = testSessionState.getTestPlan().getNode(currentItemKey);
    ItemSessionController itemSessionController = (ItemSessionController) testSessionController.getItemProcessingContext(currentItemRefNode);
    ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
    List<Interaction> interactions = itemSessionController.getInteractions();
    Map<Identifier, Interaction> interactionMap = new HashMap<>();
    for (Interaction interaction : interactions) {
        interactionMap.put(interaction.getResponseIdentifier(), interaction);
    }
    Map<Identifier, AssessmentResponse> candidateResponseMap = qtiService.getAssessmentResponses(itemSession);
    for (Entry<Identifier, ResponseData> responseEntry : responseDataMap.entrySet()) {
        Identifier responseIdentifier = responseEntry.getKey();
        ResponseData responseData = responseEntry.getValue();
        AssessmentResponse candidateItemResponse;
        if (candidateResponseMap.containsKey(responseIdentifier)) {
            candidateItemResponse = candidateResponseMap.get(responseIdentifier);
        } else {
            candidateItemResponse = qtiService.createAssessmentResponse(candidateSession, itemSession, responseIdentifier.toString(), ResponseLegality.VALID, responseData.getType());
        }
        switch(responseData.getType()) {
            case STRING:
                {
                    List<String> data = ((StringResponseData) responseData).getResponseData();
                    String stringuifiedResponse = ResponseFormater.format(data);
                    candidateItemResponse.setStringuifiedResponse(stringuifiedResponse);
                    break;
                }
            default:
                throw new OLATRuntimeException("Unexpected switch case: " + responseData.getType());
        }
        candidateResponseMap.put(responseIdentifier, candidateItemResponse);
        itemSessionState.setRawResponseData(responseIdentifier, responseData);
        try {
            Interaction interaction = interactionMap.get(responseIdentifier);
            interaction.bindResponse(itemSessionController, responseData);
        } catch (final ResponseBindingException e) {
        // 
        }
    }
    /* Copy uncommitted responses over */
    for (final Entry<Identifier, Value> uncommittedResponseEntry : itemSessionState.getUncommittedResponseValues().entrySet()) {
        final Identifier identifier = uncommittedResponseEntry.getKey();
        final Value value = uncommittedResponseEntry.getValue();
        itemSessionState.setResponseValue(identifier, value);
    }
    /* Persist CandidateResponse entities */
    qtiService.recordTestAssessmentResponses(itemSession, candidateResponseMap.values());
    /* Record resulting event */
    final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.ITEM_EVENT, null, currentItemKey, testSessionState, notificationRecorder);
    candidateAuditLogger.logCandidateEvent(candidateEvent, candidateResponseMap);
    /* Record current result state */
    AssessmentResult assessmentResult = computeTestAssessmentResult(timestamp, candidateSession);
    synchronized (this) {
        qtiService.recordTestAssessmentResult(candidateSession, testSessionState, assessmentResult, candidateAuditLogger);
    }
}
Also used : TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) HashMap(java.util.HashMap) ResponseBindingException(uk.ac.ed.ph.jqtiplus.exception.ResponseBindingException) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) List(java.util.List) AssessmentResult(uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult) ParentPartItemRefs(org.olat.ims.qti21.model.ParentPartItemRefs) TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) FileResponseData(uk.ac.ed.ph.jqtiplus.types.FileResponseData) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) ResponseData(uk.ac.ed.ph.jqtiplus.types.ResponseData) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) NotificationRecorder(uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Date(java.util.Date) StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Value(uk.ac.ed.ph.jqtiplus.value.Value) NumberValue(uk.ac.ed.ph.jqtiplus.value.NumberValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) BooleanValue(uk.ac.ed.ph.jqtiplus.value.BooleanValue) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 7 with TestPlanNodeKey

use of uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey in project OpenOLAT by OpenOLAT.

the class AssessmentResultController method initFormSections.

private void initFormSections(FormLayoutContainer layoutCont, Results testResults) {
    List<Results> itemResults = new ArrayList<>();
    layoutCont.contextPut("itemResults", itemResults);
    Map<Identifier, AssessmentItemRef> identifierToRefs = new HashMap<>();
    for (AssessmentItemRef itemRef : resolvedAssessmentTest.getAssessmentItemRefs()) {
        identifierToRefs.put(itemRef.getIdentifier(), itemRef);
    }
    Map<TestPlanNode, Results> resultsMap = new HashMap<>();
    TestPlan testPlan = testSessionState.getTestPlan();
    List<TestPlanNode> nodes = testPlan.getTestPlanNodeList();
    for (TestPlanNode node : nodes) {
        TestPlanNodeKey testPlanNodeKey = node.getKey();
        TestNodeType testNodeType = node.getTestNodeType();
        if (testNodeType == TestNodeType.ASSESSMENT_SECTION) {
            Results r = new Results(true, node.getSectionPartTitle(), "o_mi_qtisection", options.isSectionSummary());
            AssessmentSectionSessionState sectionState = testSessionState.getAssessmentSectionSessionStates().get(testPlanNodeKey);
            if (sectionState != null) {
                r.setSessionState(sectionState);
            }
            resultsMap.put(node, r);
            itemResults.add(r);
            testResults.setNumberOfSections(testResults.getNumberOfSections() + 1);
        } else if (testNodeType == TestNodeType.ASSESSMENT_ITEM_REF) {
            Results results = initFormItemResult(layoutCont, node, identifierToRefs, resultsMap);
            if (results != null) {
                itemResults.add(results);
            }
            testResults.setNumberOfQuestions(testResults.getNumberOfQuestions() + 1);
            if (results.sessionStatus == SessionStatus.FINAL) {
                testResults.setNumberOfAnsweredQuestions(testResults.getNumberOfAnsweredQuestions() + 1);
            }
            if (results.hasMaxScore()) {
                testResults.addMaxScore(results);
            }
        }
    }
}
Also used : TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) HashMap(java.util.HashMap) TestPlan(uk.ac.ed.ph.jqtiplus.state.TestPlan) ArrayList(java.util.ArrayList) AssessmentSectionSessionState(uk.ac.ed.ph.jqtiplus.state.AssessmentSectionSessionState) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) TestNodeType(uk.ac.ed.ph.jqtiplus.state.TestPlanNode.TestNodeType) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 8 with TestPlanNodeKey

use of uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey in project OpenOLAT by OpenOLAT.

the class AssessmentResultController method initFormItemResult.

private Results initFormItemResult(FormLayoutContainer layoutCont, TestPlanNode node, Map<Identifier, AssessmentItemRef> identifierToRefs, Map<TestPlanNode, Results> resultsMap) {
    TestPlanNodeKey testPlanNodeKey = node.getKey();
    Identifier identifier = testPlanNodeKey.getIdentifier();
    AssessmentItemRef itemRef = identifierToRefs.get(identifier);
    ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
    AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
    QTI21QuestionType type = QTI21QuestionType.getType(assessmentItem);
    AssessmentItemSession itemSession = identifierToItemSession.get(identifier.toString());
    Results r = new Results(false, node.getSectionPartTitle(), type.getCssClass(), options.isQuestionSummary());
    // init
    r.setSessionStatus(null);
    r.setItemIdentifier(node.getIdentifier().toString());
    ItemSessionState sessionState = testSessionState.getItemSessionStates().get(testPlanNodeKey);
    if (sessionState != null) {
        r.setSessionState(sessionState);
        SessionStatus sessionStatus = sessionState.getSessionStatus();
        if (sessionState != null) {
            r.setSessionStatus(sessionStatus);
        }
    }
    ItemResult itemResult = assessmentResult.getItemResult(identifier.toString());
    if (itemResult != null) {
        extractOutcomeVariable(itemResult.getItemVariables(), r);
    }
    if (itemSession != null) {
        if (itemSession.getManualScore() != null) {
            r.setScore(itemSession.getManualScore());
            r.setManualScore(itemSession.getManualScore());
        }
        r.setComment(itemSession.getCoachComment());
    }
    // update max score of section
    if (options.isUserSolutions() || options.isCorrectSolutions()) {
        InteractionResults interactionResults = initFormItemInteractions(layoutCont, sessionState, resolvedAssessmentItem);
        r.setInteractionResults(interactionResults);
        if (options.isCorrectSolutions()) {
            String correctSolutionId = "correctSolutionItem" + count++;
            FeedbackResultFormItem correctSolutionItem = new FeedbackResultFormItem(correctSolutionId, resolvedAssessmentItem);
            initInteractionResultFormItem(correctSolutionItem, sessionState);
            layoutCont.add(correctSolutionId, correctSolutionItem);
            r.setCorrectSolutionItem(correctSolutionItem);
        }
    }
    updateSectionScoreInformations(node, r, resultsMap);
    return r;
}
Also used : 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) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ItemResult(uk.ac.ed.ph.jqtiplus.node.result.ItemResult) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) SessionStatus(uk.ac.ed.ph.jqtiplus.node.result.SessionStatus) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) QTI21QuestionType(org.olat.ims.qti21.model.QTI21QuestionType) FeedbackResultFormItem(org.olat.ims.qti21.ui.components.FeedbackResultFormItem) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 9 with TestPlanNodeKey

use of uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey in project OpenOLAT by OpenOLAT.

the class CorrectionIdentityInteractionsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    TestPlanNode node = correction.getItemNode();
    TestPlanNodeKey testPlanNodeKey = node.getKey();
    AssessmentItemSession itemSession = correction.getItemSession();
    AssessmentTestSession testSession = correction.getTestSession();
    TestSessionState testSessionState = correction.getTestSessionState();
    answerItem = initFormExtendedTextInteraction(testPlanNodeKey, testSessionState, testSession, formLayout);
    formLayout.add("answer", answerItem);
    viewSolutionButton = uifactory.addFormLink("view.solution", formLayout);
    viewSolutionButton.setIconLeftCSS("o_icon o_icon_open_togglebox");
    solutionItem = initFormExtendedTextInteraction(testPlanNodeKey, testSessionState, testSession, formLayout);
    solutionItem.setVisible(false);
    solutionItem.setShowSolution(true);
    formLayout.add("solution", solutionItem);
    List<InteractionResultFormItem> responseItems = new ArrayList<>(interactions.size());
    for (Interaction interaction : interactions) {
        if (interaction instanceof UploadInteraction || interaction instanceof DrawingInteraction || interaction instanceof ExtendedTextInteraction) {
            manualScore = true;
            File submissionDir = qtiService.getSubmissionDirectory(testSession);
            if (submissionDir != null) {
                submissionDirectoryMaps.put(testSession.getKey(), submissionDir);
            }
        }
    }
    String mScore = "";
    String coachComment = "";
    if (itemSession != null) {
        if (itemSession.getManualScore() != null) {
            mScore = AssessmentHelper.getRoundedScore(itemSession.getManualScore());
        }
        coachComment = itemSession.getCoachComment();
    }
    FormLayoutContainer scoreCont = FormLayoutContainer.createDefaultFormLayout("score.container", getTranslator());
    formLayout.add("score.container", scoreCont);
    statusEl = uifactory.addStaticTextElement("status", "status", "", scoreCont);
    statusEl.setValue(getStatus());
    String fullname = userManager.getUserDisplayName(correction.getAssessedIdentity());
    if (manualScore) {
        scoreEl = uifactory.addTextElement("scoreItem", "score", 6, mScore, scoreCont);
    } else {
        overrideAutoScore = itemSession == null ? null : itemSession.getManualScore();
        String page = velocity_root + "/override_score.html";
        overrideScoreCont = FormLayoutContainer.createCustomFormLayout("extra.score", getTranslator(), page);
        overrideScoreCont.setRootForm(mainForm);
        scoreCont.add(overrideScoreCont);
        overrideScoreCont.setLabel("score", null);
        BigDecimal score = null;
        if (itemSession != null) {
            score = itemSession.getManualScore();
            if (score == null) {
                score = itemSession.getScore();
            }
        }
        overrideScoreCont.contextPut("score", AssessmentHelper.getRoundedScore(score));
        overrideScoreButton = uifactory.addFormLink("override.score", overrideScoreCont, Link.BUTTON_SMALL);
        overrideScoreButton.setDomReplacementWrapperRequired(false);
    }
    commentEl = uifactory.addTextAreaElement("commentItem", "comment", 2500, 4, 60, false, coachComment, scoreCont);
    commentEl.setHelpText(translate("comment.help"));
    IdentityAssessmentItemWrapper wrapper = new IdentityAssessmentItemWrapper(fullname, assessmentItem, correction, responseItems, scoreEl, commentEl, statusEl);
    toReviewEl = uifactory.addCheckboxesHorizontal("to.review", "to.review", scoreCont, onKeys, new String[] { "" });
    if (itemSession != null && itemSession.isToReview()) {
        toReviewEl.select(onKeys[0], true);
    }
    Double minScore = QtiNodesExtractor.extractMinScore(assessmentItem);
    Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
    if (maxScore != null) {
        if (minScore == null) {
            minScore = 0.0d;
        }
        wrapper.setMinScore(AssessmentHelper.getRoundedScore(minScore));
        wrapper.setMaxScore(AssessmentHelper.getRoundedScore(maxScore));
        wrapper.setMinScoreVal(minScore);
        wrapper.setMaxScoreVal(maxScore);
        if (scoreEl != null) {
            scoreEl.setExampleKey("correction.min.max.score", new String[] { wrapper.getMinScore(), wrapper.getMaxScore() });
        }
        if (overrideScoreCont != null) {
            overrideScoreCont.setExampleKey("correction.min.max.score", new String[] { wrapper.getMinScore(), wrapper.getMaxScore() });
        }
    }
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("interactionWrapper", wrapper);
    }
}
Also used : TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) UploadInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.UploadInteraction) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) DrawingInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction) UploadInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.UploadInteraction) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) InteractionResultFormItem(org.olat.ims.qti21.ui.components.InteractionResultFormItem) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) DrawingInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction) BigDecimal(java.math.BigDecimal) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) File(java.io.File) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 10 with TestPlanNodeKey

use of uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey in project OpenOLAT by OpenOLAT.

the class CorrectionIdentityAssessmentItemController method doSave.

private void doSave() {
    TestSessionState testSessionState = itemCorrection.getTestSessionState();
    AssessmentTestSession candidateSession = itemCorrection.getTestSession();
    try (AssessmentSessionAuditLogger candidateAuditLogger = qtiService.getAssessmentSessionAuditLogger(candidateSession, false)) {
        TestPlanNodeKey testPlanNodeKey = itemCorrection.getItemNode().getKey();
        String stringuifiedIdentifier = testPlanNodeKey.getIdentifier().toString();
        ParentPartItemRefs parentParts = AssessmentTestHelper.getParentSection(testPlanNodeKey, testSessionState, resolvedAssessmentTest);
        AssessmentItemSession itemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, stringuifiedIdentifier);
        itemSession.setManualScore(identityInteractionsCtrl.getManualScore());
        itemSession.setCoachComment(identityInteractionsCtrl.getComment());
        itemSession.setToReview(identityInteractionsCtrl.isToReview());
        itemSession = qtiService.updateAssessmentItemSession(itemSession);
        itemCorrection.setItemSession(itemSession);
        candidateAuditLogger.logCorrection(candidateSession, itemSession, getIdentity());
        candidateSession = qtiService.recalculateAssessmentTestSessionScores(candidateSession.getKey());
        itemCorrection.setTestSession(candidateSession);
        model.updateLastSession(itemCorrection.getAssessedIdentity(), candidateSession);
    } catch (IOException e) {
        logError("", e);
    }
}
Also used : ParentPartItemRefs(org.olat.ims.qti21.model.ParentPartItemRefs) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) AssessmentSessionAuditLogger(org.olat.ims.qti21.AssessmentSessionAuditLogger) IOException(java.io.IOException) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Aggregations

TestPlanNodeKey (uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)52 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)42 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)26 TestPlanNode (uk.ac.ed.ph.jqtiplus.state.TestPlanNode)26 HashMap (java.util.HashMap)18 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)18 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)16 NotificationRecorder (uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder)16 ArrayList (java.util.ArrayList)12 Date (java.util.Date)12 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)12 Map (java.util.Map)10 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)10 TestPlan (uk.ac.ed.ph.jqtiplus.state.TestPlan)10 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)10 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)8 TestPartSessionState (uk.ac.ed.ph.jqtiplus.state.TestPartSessionState)8 ParentPartItemRefs (org.olat.ims.qti21.model.ParentPartItemRefs)6 QtiCandidateStateException (uk.ac.ed.ph.jqtiplus.exception.QtiCandidateStateException)6 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6