Search in sources :

Example 16 with AssessmentResponse

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

the class AssessmentResponseDAOTest method createResponse.

@Test
public void createResponse() {
    // 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();
    String responseIdentifier = UUID.randomUUID().toString();
    // make test, item and response
    AssessmentTestSession testSession = testSessionDao.createAndPersistTestSession(testEntry, testEntry, "_", assessmentEntry, assessedIdentity, null, true);
    Assert.assertNotNull(testSession);
    AssessmentItemSession itemSession = itemSessionDao.createAndPersistAssessmentItemSession(testSession, null, itemIdentifier);
    Assert.assertNotNull(itemSession);
    AssessmentResponse response = responseDao.createAssessmentResponse(testSession, itemSession, responseIdentifier, ResponseLegality.VALID, ResponseDataType.FILE);
    Assert.assertNotNull(response);
    dbInstance.commit();
}
Also used : 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) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Test(org.junit.Test)

Example 17 with AssessmentResponse

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

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 18 with AssessmentResponse

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

the class QTI21ArchiveFormat method writeDataRow.

private void writeDataRow(int num, SessionResponses responses, OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
    int col = 0;
    Row dataRow = exportSheet.newRow();
    // sequence number
    dataRow.addCell(col++, num, null);
    AssessmentTestSession testSession = responses.getTestSession();
    AssessmentEntry entry = testSession.getAssessmentEntry();
    Identity assessedIdentity = entry.getIdentity();
    // user properties
    if (assessedIdentity == null) {
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            if (userPropertyHandler != null) {
                if (userPropertyHandlers.get(0) == userPropertyHandler) {
                    dataRow.addCell(col++, translator.translate("anonym.user"), null);
                } else {
                    col++;
                }
            }
        }
    } else if (anonymizerCallback != null) {
        String anonymizedName = anonymizerCallback.getAnonymizedUserName(assessedIdentity);
        dataRow.addCell(col++, anonymizedName, null);
    } else {
        User assessedUser = assessedIdentity.getUser();
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            if (userPropertyHandler != null) {
                String property = userPropertyHandler.getUserProperty(assessedUser, translator.getLocale());
                dataRow.addCell(col++, property, null);
            }
        }
    }
    // homepage
    if (anonymizerCallback == null) {
        String homepage;
        if (entry.getIdentity() == null) {
            homepage = "";
        } else {
            ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(entry.getIdentity());
            homepage = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
        }
        dataRow.addCell(col++, homepage, null);
    }
    // course node points and passed
    if (courseNode instanceof AssessableCourseNode) {
        AssessableCourseNode assessableCourseNode = (AssessableCourseNode) courseNode;
        if (assessableCourseNode.hasScoreConfigured()) {
            if (entry.getScore() != null) {
                dataRow.addCell(col++, entry.getScore(), null);
            } else {
                col++;
            }
        }
        if (assessableCourseNode.hasPassedConfigured()) {
            if (entry.getPassed() != null) {
                dataRow.addCell(col++, entry.getPassed().toString(), null);
            } else {
                col++;
            }
        }
    }
    // assesspoints, passed, ipaddress, date, duration
    if (testSession.getScore() != null) {
        dataRow.addCell(col++, testSession.getScore(), null);
    } else {
        col++;
    }
    if (testSession.getManualScore() != null) {
        dataRow.addCell(col++, testSession.getManualScore(), null);
    } else {
        col++;
    }
    if (testSession.getFinalScore() != null) {
        dataRow.addCell(col++, testSession.getFinalScore(), null);
    } else {
        col++;
    }
    if (testSession.getPassed() != null) {
        dataRow.addCell(col++, testSession.getPassed().toString(), null);
    } else {
        col++;
    }
    if (anonymizerCallback == null) {
        dataRow.addCell(col++, testSession.getCreationDate(), workbook.getStyles().getDateStyle());
    }
    dataRow.addCell(col++, toDurationInMilliseconds(testSession.getDuration()), null);
    List<AbstractInfos> infos = getItemInfos();
    for (int i = 0; i < infos.size(); i++) {
        AbstractInfos info = infos.get(i);
        if (info instanceof ItemInfos) {
            ItemInfos item = (ItemInfos) info;
            AssessmentItemRef itemRef = item.getAssessmentItemRef();
            String itemRefIdentifier = itemRef.getIdentifier().toString();
            AssessmentItemSession itemSession = responses.getItemSession(itemRefIdentifier);
            if (exportConfig.isResponseCols()) {
                List<Interaction> interactions = item.getInteractions();
                for (int j = 0; j < interactions.size(); j++) {
                    Interaction interaction = interactions.get(j);
                    AssessmentResponse response = responses.getResponse(itemRefIdentifier, interaction.getResponseIdentifier());
                    col = interactionArchiveMap.get(interaction.getQtiClassName()).writeInteractionData(item.getAssessmentItem(), response, interaction, j, dataRow, col, workbook);
                }
            }
            // score, start, duration
            if (itemSession == null) {
                if (exportConfig.isPointCol()) {
                    col++;
                }
                if (exportConfig.isCommentCol()) {
                    col++;
                }
                if (exportConfig.isTimeCols()) {
                    col += anonymizerCallback != null ? 1 : 2;
                }
            } else {
                if (exportConfig.isPointCol()) {
                    if (itemSession.getManualScore() != null) {
                        dataRow.addCell(col++, itemSession.getManualScore(), null);
                    } else {
                        dataRow.addCell(col++, itemSession.getScore(), null);
                    }
                }
                if (exportConfig.isCommentCol()) {
                    dataRow.addCell(col++, itemSession.getCoachComment(), null);
                }
                if (exportConfig.isTimeCols()) {
                    if (anonymizerCallback == null) {
                        dataRow.addCell(col++, itemSession.getCreationDate(), workbook.getStyles().getTimeStyle());
                    }
                    dataRow.addCell(col++, toDurationInMilliseconds(itemSession.getDuration()), null);
                }
            }
        } else if (numOfSections > 1 && info instanceof SectionInfos) {
            SectionInfos section = (SectionInfos) info;
            if (!section.getItemInfos().isEmpty()) {
                BigDecimal score = calculateSectionScore(responses, section);
                if (score != null) {
                    dataRow.addCell(col++, score, workbook.getStyles().getLightGrayStyle());
                } else {
                    col++;
                }
            }
        }
    }
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) User(org.olat.core.id.User) DrawingInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.DrawingInteraction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) GraphicOrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicOrderInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) OrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.OrderInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) GraphicAssociateInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicAssociateInteraction) CustomInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.CustomInteraction) InlineChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.InlineChoiceInteraction) HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) UploadInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.UploadInteraction) AssociateInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.AssociateInteraction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SelectPointInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.SelectPointInteraction) SliderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.SliderInteraction) PositionObjectInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.PositionObjectInteraction) GraphicGapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicGapMatchInteraction) MediaInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MediaInteraction) GapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GapMatchInteraction) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) ContextEntry(org.olat.core.id.context.ContextEntry) BigDecimal(java.math.BigDecimal) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 19 with AssessmentResponse

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

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 20 with AssessmentResponse

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

the class QTI21ArchiveFormat method exportWorkbook.

public void exportWorkbook(OutputStream exportStream) {
    RepositoryEntry testEntry = searchParams.getTestEntry();
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
    resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
    // content
    final List<AssessmentTestSession> sessions = testSessionDao.getTestSessionsOfResponse(searchParams);
    final List<AssessmentResponse> responses = responseDao.getResponse(searchParams);
    try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(exportStream, 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) FileResourceManager(org.olat.fileresource.FileResourceManager) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) RepositoryEntry(org.olat.repository.RepositoryEntry) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) File(java.io.File) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) IOException(java.io.IOException)

Aggregations

AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)22 Date (java.util.Date)12 HashMap (java.util.HashMap)12 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)12 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)12 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)10 File (java.io.File)8 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)8 StringInput (org.olat.ims.qti21.ui.ResponseInput.StringInput)8 NotificationRecorder (uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder)8 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)8 FileResponseData (uk.ac.ed.ph.jqtiplus.types.FileResponseData)8 ResponseData (uk.ac.ed.ph.jqtiplus.types.ResponseData)8 StringResponseData (uk.ac.ed.ph.jqtiplus.types.StringResponseData)8 CandidateItemEventType (org.olat.ims.qti21.model.audit.CandidateItemEventType)6 IOException (java.io.IOException)4 AssessmentResponseData (org.olat.ims.qti21.model.audit.AssessmentResponseData)4 QtiCandidateStateException (uk.ac.ed.ph.jqtiplus.exception.QtiCandidateStateException)4 List (java.util.List)3 Identity (org.olat.core.id.Identity)3