Search in sources :

Example 1 with AssessmentItemSession

use of org.olat.ims.qti21.AssessmentItemSession in project OpenOLAT by OpenOLAT.

the class QTI21ArchiveFormat method calculateSectionScore.

private BigDecimal calculateSectionScore(SessionResponses responses, SectionInfos section) {
    BigDecimal sectionScore = BigDecimal.valueOf(0l);
    for (ItemInfos item : section.getItemInfos()) {
        AssessmentItemRef itemRef = item.getAssessmentItemRef();
        String itemRefIdentifier = itemRef.getIdentifier().toString();
        AssessmentItemSession itemSession = responses.getItemSession(itemRefIdentifier);
        if (itemSession != null) {
            if (itemSession.getManualScore() != null) {
                sectionScore = sectionScore.add(itemSession.getManualScore());
            } else if (itemSession.getScore() != null) {
                sectionScore = sectionScore.add(itemSession.getScore());
            }
        }
    }
    return sectionScore;
}
Also used : AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) BigDecimal(java.math.BigDecimal)

Example 2 with AssessmentItemSession

use of org.olat.ims.qti21.AssessmentItemSession in project OpenOLAT by OpenOLAT.

the class QTI21ArchiveFormat method writeData.

/**
 * The 2 lists, sessions and responses are order by the user name and the test session key.
 * @param sessions A list of test sessions ordered by test session key
 * @param responses A list of responses ordered by test session key
 * @param exportSheet
 * @param workbook
 */
private void writeData(List<AssessmentTestSession> sessions, List<AssessmentResponse> responses, OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
    int numOfSessions = sessions.size();
    Map<AssessmentTestSession, SessionResponses> sessionToResponses = new HashMap<>();
    for (int i = 0; i < numOfSessions; i++) {
        AssessmentTestSession testSession = sessions.get(i);
        sessionToResponses.put(testSession, new SessionResponses(testSession));
    }
    int numOfResponses = responses.size();
    for (int j = 0; j < numOfResponses; j++) {
        AssessmentResponse response = responses.get(j);
        AssessmentItemSession itemSession = response.getAssessmentItemSession();
        AssessmentTestSession responseTestSession = itemSession.getAssessmentTestSession();
        SessionResponses sessionResponses = sessionToResponses.get(responseTestSession);
        if (sessionResponses != null) {
            sessionResponses.addResponse(itemSession, response);
        }
    }
    for (int i = 0; i < numOfSessions; i++) {
        AssessmentTestSession testSession = sessions.get(i);
        SessionResponses sessionResponses = sessionToResponses.get(testSession);
        writeDataRow(i + 2, sessionResponses, exportSheet, workbook);
    }
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) HashMap(java.util.HashMap) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse)

Example 3 with AssessmentItemSession

use of org.olat.ims.qti21.AssessmentItemSession in project OpenOLAT by OpenOLAT.

the class AssessmentItemSessionDAO method createAndPersistAssessmentItemSession.

public AssessmentItemSession createAndPersistAssessmentItemSession(AssessmentTestSession assessmentTestSession, ParentPartItemRefs parentParts, String assessmentItemIdentifier) {
    AssessmentItemSessionImpl itemSession = new AssessmentItemSessionImpl();
    Date now = new Date();
    itemSession.setCreationDate(now);
    itemSession.setLastModified(now);
    itemSession.setAssessmentItemIdentifier(assessmentItemIdentifier);
    itemSession.setAssessmentTestSession(assessmentTestSession);
    if (parentParts != null) {
        itemSession.setSectionIdentifier(parentParts.getSectionIdentifier());
        itemSession.setTestPartIdentifier(parentParts.getTestPartIdentifier());
    }
    dbInstance.getCurrentEntityManager().persist(itemSession);
    return itemSession;
}
Also used : AssessmentItemSessionImpl(org.olat.ims.qti21.model.jpa.AssessmentItemSessionImpl) Date(java.util.Date)

Example 4 with AssessmentItemSession

use of org.olat.ims.qti21.AssessmentItemSession in project OpenOLAT by OpenOLAT.

the class QTI21ServiceImpl method getAssessmentResponses.

@Override
public Map<Identifier, AssessmentResponse> getAssessmentResponses(AssessmentItemSession assessmentItemSession) {
    List<AssessmentResponse> responses = testResponseDao.getResponses(assessmentItemSession);
    Map<Identifier, AssessmentResponse> responseMap = new HashMap<>();
    for (AssessmentResponse response : responses) {
        responseMap.put(Identifier.assumedLegal(response.getResponseIdentifier()), response);
    }
    return responseMap;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse)

Example 5 with AssessmentItemSession

use of org.olat.ims.qti21.AssessmentItemSession 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)

Aggregations

AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)40 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)24 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)18 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)18 HashMap (java.util.HashMap)16 Identity (org.olat.core.id.Identity)16 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)16 TestPlanNodeKey (uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)16 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)12 ParentPartItemRefs (org.olat.ims.qti21.model.ParentPartItemRefs)12 BigDecimal (java.math.BigDecimal)10 ArrayList (java.util.ArrayList)10 Date (java.util.Date)8 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)8 TestPlanNode (uk.ac.ed.ph.jqtiplus.state.TestPlanNode)8 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)8 Test (org.junit.Test)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6