Search in sources :

Example 36 with AssessmentTestSession

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

the class QTI21ArchiveFormat method exportCourseElement.

public MediaResource exportCourseElement() {
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedDirRoot = frm.unzipFileResource(searchParams.getTestEntry().getOlatResource());
    resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
    ICourse course = CourseFactory.loadCourse(searchParams.getCourseEntry());
    courseNode = course.getRunStructure().getNode(searchParams.getNodeIdent());
    String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".xlsx";
    if ("iqself".equals(courseNode.getType())) {
        anonymizerCallback = course.getCourseEnvironment().getCoursePropertyManager();
    }
    // content
    final List<AssessmentTestSession> sessions = testSessionDao.getTestSessionsOfResponse(searchParams);
    final List<AssessmentResponse> responses = responseDao.getResponse(searchParams);
    return new OpenXMLWorkbookResource(label) {

        @Override
        protected void generate(OutputStream out) {
            try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
                // headers
                OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
                exportSheet.setHeaderRows(2);
                writeHeaders_1(exportSheet, workbook);
                writeHeaders_2(exportSheet, workbook);
                writeData(sessions, responses, exportSheet, workbook);
            } catch (Exception e) {
                log.error("", e);
            }
        }
    };
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ICourse(org.olat.course.ICourse) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Date(java.util.Date) IOException(java.io.IOException) FileResourceManager(org.olat.fileresource.FileResourceManager) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) File(java.io.File)

Example 37 with AssessmentTestSession

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

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 38 with AssessmentTestSession

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

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 39 with AssessmentTestSession

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

the class AssessmentResponseDAO method createAssessmentResponse.

public AssessmentResponse createAssessmentResponse(AssessmentTestSession assessmentTestSession, AssessmentItemSession assessmentItemSession, String responseIdentifier, ResponseLegality legality, ResponseDataType type) {
    AssessmentResponseImpl response = new AssessmentResponseImpl();
    Date now = new Date();
    response.setCreationDate(now);
    response.setLastModified(now);
    response.setResponseDataType(type.name());
    response.setResponseLegality(legality.name());
    response.setAssessmentItemSession(assessmentItemSession);
    response.setAssessmentTestSession(assessmentTestSession);
    response.setResponseIdentifier(responseIdentifier);
    return response;
}
Also used : AssessmentResponseImpl(org.olat.ims.qti21.model.jpa.AssessmentResponseImpl) Date(java.util.Date)

Example 40 with AssessmentTestSession

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

the class AssessmentTestSessionDAO method getUserTestSessionsStatistics.

public List<AssessmentTestSessionStatistics> getUserTestSessionsStatistics(RepositoryEntryRef courseEntry, String courseSubIdent, IdentityRef identity) {
    StringBuilder sb = new StringBuilder();
    sb.append("select session,").append(" (select count(itemSession.key) from qtiassessmentitemsession itemSession").append("   where itemSession.assessmentTestSession.key=session.key and itemSession.manualScore is not null").append(" ) as correctItems").append(" from qtiassessmenttestsession session").append(" left join fetch session.testEntry testEntry").append(" left join fetch testEntry.olatResource testResource").append("  where session.repositoryEntry.key=:repositoryEntryKey and session.identity.key=:identityKey and ");
    if (StringHelper.containsNonWhitespace(courseSubIdent)) {
        sb.append("session.subIdent=:subIdent");
    } else {
        sb.append("session.subIdent is null");
    }
    sb.append(" order by session.creationDate desc");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("repositoryEntryKey", courseEntry.getKey()).setParameter("identityKey", identity.getKey());
    if (StringHelper.containsNonWhitespace(courseSubIdent)) {
        query.setParameter("subIdent", courseSubIdent);
    }
    List<Object[]> raws = query.getResultList();
    List<AssessmentTestSessionStatistics> stats = new ArrayList<>(raws.size());
    for (Object[] raw : raws) {
        AssessmentTestSession testSession = (AssessmentTestSession) raw[0];
        int numOfCorrectedItems = (raw[1] == null ? 0 : ((Number) raw[1]).intValue());
        stats.add(new AssessmentTestSessionStatistics(testSession, numOfCorrectedItems));
    }
    return stats;
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) AssessmentTestSessionStatistics(org.olat.ims.qti21.model.jpa.AssessmentTestSessionStatistics) ArrayList(java.util.ArrayList)

Aggregations

AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)107 Identity (org.olat.core.id.Identity)45 RepositoryEntry (org.olat.repository.RepositoryEntry)36 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)32 File (java.io.File)30 ArrayList (java.util.ArrayList)24 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)24 Date (java.util.Date)22 Test (org.junit.Test)20 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)20 HashMap (java.util.HashMap)17 InMemoryAssessmentTestSession (org.olat.ims.qti21.model.InMemoryAssessmentTestSession)14 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)14 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)12 TestPlanNodeKey (uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)12 IOException (java.io.IOException)10 BigDecimal (java.math.BigDecimal)10 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)10 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)10 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)10