Search in sources :

Example 11 with ParentPartItemRefs

use of org.olat.ims.qti21.model.ParentPartItemRefs in project openolat by klemens.

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)

Example 12 with ParentPartItemRefs

use of org.olat.ims.qti21.model.ParentPartItemRefs in project OpenOLAT by OpenOLAT.

the class AssessmentTestSessionDAOTest method getUserTestSessionsStatistics.

@Test
public void getUserTestSessionsStatistics() {
    // prepare a test and a user
    RepositoryEntry testEntry = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry courseEntry = JunitTestHelper.createAndPersistRepositoryEntry();
    String subIdent = UUID.randomUUID().toString();
    Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("session-3");
    AssessmentEntry assessmentEntry = assessmentService.getOrCreateAssessmentEntry(assessedIdentity, null, courseEntry, subIdent, testEntry);
    dbInstance.commit();
    AssessmentTestSession testSession = testSessionDao.createAndPersistTestSession(testEntry, courseEntry, subIdent, assessmentEntry, assessedIdentity, null, false);
    Assert.assertNotNull(testSession);
    dbInstance.commit();
    for (int i = 0; i < 4; i++) {
        ParentPartItemRefs parentParts = new ParentPartItemRefs();
        String sectionIdentifier = UUID.randomUUID().toString();
        parentParts.setSectionIdentifier(sectionIdentifier);
        String testPartIdentifier = UUID.randomUUID().toString();
        parentParts.setTestPartIdentifier(testPartIdentifier);
        AssessmentItemSession itemSession = itemSessionDao.createAndPersistAssessmentItemSession(testSession, parentParts, UUID.randomUUID().toString());
        Assert.assertNotNull(itemSession);
        dbInstance.commit();
        if (i % 2 == 0) {
            itemSession.setManualScore(new BigDecimal(3));
            itemSessionDao.merge(itemSession);
        }
    }
    dbInstance.commitAndCloseSession();
    List<AssessmentTestSessionStatistics> sessionsStatistics = testSessionDao.getUserTestSessionsStatistics(courseEntry, subIdent, assessedIdentity);
    Assert.assertNotNull(sessionsStatistics);
    Assert.assertEquals(1, sessionsStatistics.size());
    AssessmentTestSessionStatistics sessionStatistics = sessionsStatistics.get(0);
    Assert.assertNotNull(sessionStatistics.getTestSession());
    Assert.assertEquals(testSession, sessionStatistics.getTestSession());
    Assert.assertEquals(2, sessionStatistics.getNumOfCorrectedItems());
}
Also used : ParentPartItemRefs(org.olat.ims.qti21.model.ParentPartItemRefs) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) AssessmentTestSessionStatistics(org.olat.ims.qti21.model.jpa.AssessmentTestSessionStatistics) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 13 with ParentPartItemRefs

use of org.olat.ims.qti21.model.ParentPartItemRefs in project OpenOLAT by OpenOLAT.

the class AssessmentItemSessionDAOTest method createAndGetItemSession.

@Test
public void createAndGetItemSession() {
    // prepare a test and a user
    RepositoryEntry testEntry = JunitTestHelper.createAndPersistRepositoryEntry();
    Identity assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("response-session-1");
    AssessmentEntry assessmentEntry = assessmentService.getOrCreateAssessmentEntry(assessedIdentity, null, testEntry, "-", testEntry);
    dbInstance.commit();
    String itemIdentifier = UUID.randomUUID().toString();
    ParentPartItemRefs parentParts = new ParentPartItemRefs();
    String sectionIdentifier = UUID.randomUUID().toString();
    parentParts.setSectionIdentifier(sectionIdentifier);
    String testPartIdentifier = UUID.randomUUID().toString();
    parentParts.setTestPartIdentifier(testPartIdentifier);
    // make test, item and response
    AssessmentTestSession testSession = testSessionDao.createAndPersistTestSession(testEntry, testEntry, "_", assessmentEntry, assessedIdentity, null, true);
    Assert.assertNotNull(testSession);
    AssessmentItemSession itemSession = itemSessionDao.createAndPersistAssessmentItemSession(testSession, parentParts, itemIdentifier);
    Assert.assertNotNull(itemSession);
    dbInstance.commitAndCloseSession();
    AssessmentItemSession reloadedItemSession = itemSessionDao.getAssessmentItemSession(testSession, itemIdentifier);
    Assert.assertNotNull(reloadedItemSession);
    Assert.assertNotNull(reloadedItemSession.getCreationDate());
    Assert.assertNotNull(reloadedItemSession.getLastModified());
    Assert.assertEquals(itemIdentifier, reloadedItemSession.getAssessmentItemIdentifier());
    Assert.assertEquals(sectionIdentifier, reloadedItemSession.getSectionIdentifier());
    Assert.assertEquals(testPartIdentifier, reloadedItemSession.getTestPartIdentifier());
}
Also used : ParentPartItemRefs(org.olat.ims.qti21.model.ParentPartItemRefs) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Test(org.junit.Test)

Example 14 with ParentPartItemRefs

use of org.olat.ims.qti21.model.ParentPartItemRefs in project OpenOLAT by OpenOLAT.

the class AssessmentTestDisplayController method handleResponse.

// public CandidateSession handleResponses(final CandidateSessionContext candidateSessionContext,
// final Map<Identifier, StringResponseData> stringResponseMap,
// final Map<Identifier, MultipartFile> fileResponseMap,
// final String candidateComment)
private void handleResponse(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap, Map<Identifier, ResponseInput> fileResponseMap, String candidateComment) {
    NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
    TestSessionState testSessionState = testSessionController.getTestSessionState();
    TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
    if (currentItemKey == null && getLastEvent() != null && getLastEvent().getTestEventType() == CandidateTestEventType.REVIEW_ITEM) {
        // someone try to send the form in review with tab / return
        return;
    }
    if (!qtiWorksCtrl.validatePresentedItem(currentItemKey)) {
        logError("Response send by browser doesn't match current item key", null);
        ServletUtil.printOutRequestParameters(ureq.getHttpReq());
        if (candidateSession != null && candidateSession.getFinishTime() != null) {
            showWarning("error.test.closed");
        } else {
            showWarning("error.reload.question");
        }
        // this is not the right node in the plan
        return;
    }
    final Map<Identifier, File> fileSubmissionMap = new HashMap<>();
    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()));
            } else if (responseData instanceof Base64Input) {
                // only used from drawing interaction
                Base64Input fileInput = (Base64Input) responseData;
                String filename = "submitted_image.png";
                File storedFile = qtiService.importFileSubmission(candidateSession, filename, fileInput.getResponseData());
                responseDataMap.put(identifier, new FileResponseData(storedFile, fileInput.getContentType(), storedFile.getName()));
                fileSubmissionMap.put(identifier, storedFile);
            } else if (responseData instanceof FileInput) {
                FileInput fileInput = (FileInput) responseData;
                File storedFile = qtiService.importFileSubmission(candidateSession, fileInput.getMultipartFileInfos());
                responseDataMap.put(identifier, new FileResponseData(storedFile, fileInput.getContentType(), storedFile.getName()));
                fileSubmissionMap.put(identifier, storedFile);
            }
        }
    }
    ParentPartItemRefs parentParts = getParentSection(currentItemKey);
    String assessmentItemIdentifier = currentItemKey.getIdentifier().toString();
    AssessmentItemSession itemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, assessmentItemIdentifier);
    if (fileResponseMap != null) {
        for (Entry<Identifier, ResponseInput> fileResponseEntry : fileResponseMap.entrySet()) {
            Identifier identifier = fileResponseEntry.getKey();
            FileInput multipartFile = (FileInput) fileResponseEntry.getValue();
            if (!multipartFile.isEmpty()) {
                File storedFile = qtiService.importFileSubmission(candidateSession, multipartFile.getMultipartFileInfos());
                responseDataMap.put(identifier, new FileResponseData(storedFile, multipartFile.getContentType(), storedFile.getName()));
                fileSubmissionMap.put(identifier, storedFile);
            }
        }
    }
    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;
                }
            case FILE:
                {
                    if (fileSubmissionMap.get(responseIdentifier) != null) {
                        File storedFile = fileSubmissionMap.get(responseIdentifier);
                        candidateItemResponse.setStringuifiedResponse(storedFile.getName());
                    }
                    break;
                }
            default:
                throw new OLATRuntimeException("Unexpected switch case: " + responseData.getType());
        }
        candidateResponseMap.put(responseIdentifier, candidateItemResponse);
    }
    boolean allResponsesValid = true;
    boolean allResponsesBound = true;
    final Date timestamp = ureq.getRequestTimestamp();
    if (candidateComment != null) {
        testSessionController.setCandidateCommentForCurrentItem(timestamp, candidateComment);
    }
    /* Attempt to bind responses (and maybe perform RP & OP) */
    testSessionController.handleResponsesToCurrentItem(timestamp, responseDataMap);
    /* Classify this event */
    final SubmissionMode submissionMode = testSessionController.getCurrentTestPart().getSubmissionMode();
    final CandidateItemEventType candidateItemEventType;
    if (allResponsesValid) {
        candidateItemEventType = submissionMode == SubmissionMode.INDIVIDUAL ? CandidateItemEventType.ATTEMPT_VALID : CandidateItemEventType.RESPONSE_VALID;
    } else {
        candidateItemEventType = allResponsesBound ? CandidateItemEventType.RESPONSE_INVALID : CandidateItemEventType.RESPONSE_BAD;
    }
    /* Record resulting event */
    final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.ITEM_EVENT, candidateItemEventType, currentItemKey, testSessionState, notificationRecorder);
    candidateAuditLogger.logCandidateEvent(candidateEvent, candidateResponseMap);
    this.lastEvent = candidateEvent;
    /* Record current result state */
    AssessmentResult assessmentResult = computeAndRecordTestAssessmentResult(timestamp, testSessionState, false);
    ItemSessionState itemSessionState = testSessionState.getCurrentItemSessionState();
    long itemDuration = itemSessionState.getDurationAccumulated();
    itemSession.setDuration(itemDuration);
    ItemResult itemResult = assessmentResult.getItemResult(assessmentItemIdentifier);
    collectOutcomeVariablesForItemSession(itemResult, itemSession);
    /* Persist CandidateResponse entities */
    qtiService.recordTestAssessmentResponses(itemSession, candidateResponseMap.values());
    /* Save any change to session state */
    candidateSession = qtiService.updateAssessmentTestSession(candidateSession);
    addToHistory(ureq, this);
    checkConcurrentExit(ureq);
}
Also used : TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) HashMap(java.util.HashMap) FileInput(org.olat.ims.qti21.ui.ResponseInput.FileInput) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SubmissionMode(uk.ac.ed.ph.jqtiplus.node.test.SubmissionMode) 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) CandidateItemEventType(org.olat.ims.qti21.model.audit.CandidateItemEventType) 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) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Date(java.util.Date) StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) ItemResult(uk.ac.ed.ph.jqtiplus.node.result.ItemResult) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileResponseData(uk.ac.ed.ph.jqtiplus.types.FileResponseData) Base64Input(org.olat.ims.qti21.ui.ResponseInput.Base64Input) File(java.io.File) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 15 with ParentPartItemRefs

use of org.olat.ims.qti21.model.ParentPartItemRefs in project openolat by klemens.

the class AssessmentTestHelper method getParentSection.

public static ParentPartItemRefs getParentSection(TestPlanNodeKey itemKey, TestSessionState testSessionState, ResolvedAssessmentTest resolvedAssessmentTest) {
    ParentPartItemRefs parentParts = new ParentPartItemRefs();
    try {
        TestPlanNode currentItem = testSessionState.getTestPlan().getNode(itemKey);
        List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getItemRefsBySystemIdMap().get(currentItem.getItemSystemId());
        AssessmentItemRef itemRef = null;
        if (itemRefs.size() == 1) {
            itemRef = itemRefs.get(0);
        } else {
            Identifier itemId = itemKey.getIdentifier();
            for (AssessmentItemRef ref : itemRefs) {
                if (ref.getIdentifier().equals(itemId)) {
                    itemRef = ref;
                    break;
                }
            }
        }
        if (itemRef != null) {
            for (QtiNode parentPart = itemRef.getParent(); parentPart != null; parentPart = parentPart.getParent()) {
                if (parentParts.getSectionIdentifier() == null && parentPart instanceof AssessmentSection) {
                    AssessmentSection section = (AssessmentSection) parentPart;
                    parentParts.setSectionIdentifier(section.getIdentifier().toString());
                } else if (parentParts.getTestPartIdentifier() == null && parentPart instanceof TestPart) {
                    TestPart testPart = (TestPart) parentPart;
                    parentParts.setTestPartIdentifier(testPart.getIdentifier().toString());
                }
            }
        }
    } catch (Exception e) {
        log.error("", e);
    }
    return parentParts;
}
Also used : ParentPartItemRefs(org.olat.ims.qti21.model.ParentPartItemRefs) TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) QtiNode(uk.ac.ed.ph.jqtiplus.node.QtiNode)

Aggregations

ParentPartItemRefs (org.olat.ims.qti21.model.ParentPartItemRefs)14 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)12 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)8 Date (java.util.Date)6 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)6 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)6 TestPlanNode (uk.ac.ed.ph.jqtiplus.state.TestPlanNode)6 TestPlanNodeKey (uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)6 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)6 HashMap (java.util.HashMap)4 List (java.util.List)4 Test (org.junit.Test)4 Identity (org.olat.core.id.Identity)4 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)4 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)4 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)4 StringInput (org.olat.ims.qti21.ui.ResponseInput.StringInput)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 AssessmentResult (uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult)4