Search in sources :

Example 11 with QTIResult

use of org.olat.ims.qti.QTIResult in project OpenOLAT by OpenOLAT.

the class QTIStatisticsManagerTest method testResultStatistics.

/**
 * retrieve the results of the last modified result set
 */
@Test
public void testResultStatistics() {
    RepositoryEntry re = createRepository();
    long assessmentId = 838l;
    String resSubPath = "1238";
    String firstQuestion = "id:123";
    String secondQuestion = "id:124";
    String thirdQuestion = "id:125";
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-stats-20");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-stats-21");
    // 3 try for id1
    QTIResultSet set1_1 = createSet(2.0f, assessmentId, id1, re, resSubPath, modDate(3, 8, 8), modDate(3, 8, 12));
    QTIResult result1_1_1 = createResult(firstQuestion, "test 1", set1_1);
    QTIResult result1_1_2 = createResult(secondQuestion, "test 2", set1_1);
    QTIResult result1_1_3 = createResult(thirdQuestion, "test 3", set1_1);
    QTIResultSet set1_3 = createSet(6.0f, assessmentId, id1, re, resSubPath, modDate(3, 14, 7), modDate(3, 14, 38));
    QTIResult result1_3_1 = createResult(firstQuestion, "test 1", set1_3);
    QTIResult result1_3_2 = createResult(secondQuestion, "test 2", set1_3);
    QTIResult result1_3_3 = createResult(thirdQuestion, "test 3", set1_3);
    QTIResultSet set1_2 = createSet(4.0f, assessmentId, id1, re, resSubPath, modDate(3, 10, 34), modDate(3, 10, 45));
    QTIResult result1_2_1 = createResult(firstQuestion, "test 1", set1_2);
    QTIResult result1_2_2 = createResult(secondQuestion, "test 2", set1_2);
    QTIResult result1_2_3 = createResult(thirdQuestion, "test 3", set1_2);
    // 1 try for id2
    QTIResultSet set2_1 = createSet(6.0f, assessmentId, id2, re, resSubPath, modDate(3, 9, 21), modDate(3, 9, 45));
    QTIResult result2_1_1 = createResult(firstQuestion, "test 1", set2_1);
    QTIResult result2_1_2 = createResult(secondQuestion, "test 2", set2_1);
    QTIResult result2_1_3 = createResult(thirdQuestion, "test 3", set2_1);
    dbInstance.commit();
    QTIStatisticSearchParams searchParams = new QTIStatisticSearchParams(re.getOlatResource().getResourceableId(), resSubPath);
    List<QTIStatisticResult> results = qtiStatisticsManager.getResults(searchParams);
    Assert.assertNotNull(results);
    Assert.assertEquals(6, results.size());
    List<Long> setKeys = PersistenceHelper.toKeys(results);
    Assert.assertTrue(setKeys.contains(result1_3_1.getKey()));
    Assert.assertTrue(setKeys.contains(result1_3_2.getKey()));
    Assert.assertTrue(setKeys.contains(result1_3_3.getKey()));
    Assert.assertTrue(setKeys.contains(result2_1_1.getKey()));
    Assert.assertTrue(setKeys.contains(result2_1_2.getKey()));
    Assert.assertTrue(setKeys.contains(result2_1_3.getKey()));
    Assert.assertFalse(setKeys.contains(result1_1_1.getKey()));
    Assert.assertFalse(setKeys.contains(result1_1_2.getKey()));
    Assert.assertFalse(setKeys.contains(result1_1_3.getKey()));
    Assert.assertFalse(setKeys.contains(result1_2_1.getKey()));
    Assert.assertFalse(setKeys.contains(result1_2_2.getKey()));
    Assert.assertFalse(setKeys.contains(result1_2_3.getKey()));
}
Also used : QTIResultSet(org.olat.ims.qti.QTIResultSet) QTIResult(org.olat.ims.qti.QTIResult) QTIStatisticSearchParams(org.olat.ims.qti.statistics.QTIStatisticSearchParams) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) QTIStatisticResult(org.olat.ims.qti.statistics.model.QTIStatisticResult) Test(org.junit.Test)

Example 12 with QTIResult

use of org.olat.ims.qti.QTIResult in project OpenOLAT by OpenOLAT.

the class QTIStatisticsResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    CourseNode courseNode = resourceResult.getTestCourseNode();
    String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
    String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
    hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
    hres.setHeader("Content-Description", urlEncodedLabel);
    try {
        // fields separated by
        String sep = "\\t";
        // fields embedded by
        String emb = "\"";
        // carriage return
        String car = "\\r\\n";
        sep = QTIArchiver.convert2CtrlChars(sep);
        car = QTIArchiver.convert2CtrlChars(car);
        int exportType = 1;
        QTIExportFormatter formatter;
        if (QTIType.test.equals(resourceResult.getType())) {
            exportType = 1;
            formatter = new QTIExportFormatterCSVType1(locale, sep, emb, car, true);
        } else if (QTIType.survey.equals(resourceResult.getType())) {
            exportType = 2;
            formatter = new QTIExportFormatterCSVType3(locale, null, sep, emb, car, true);
        } else {
            return;
        }
        Long qtiRepoEntryKey = resourceResult.getQTIRepositoryEntry().getKey();
        List<QTIItemObject> itemList = new QTIObjectTreeBuilder().getQTIItemObjectList(resourceResult.getResolver());
        formatter.setMapWithExportItemConfigs(getQTIItemConfigs(itemList));
        QTIResultManager qrm = QTIResultManager.getInstance();
        QTIStatisticSearchParams params = resourceResult.getSearchParams();
        List<Group> limitToGroups = params.isMayViewAllUsersAssessments() ? null : params.getLimitToGroups();
        List<QTIResult> results = qrm.selectResults(resourceResult.getCourseOres().getResourceableId(), courseNode.getIdent(), qtiRepoEntryKey, limitToGroups, exportType);
        QTIExportManager.getInstance().exportResults(formatter, results, itemList, hres.getOutputStream());
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) Group(org.olat.basesecurity.Group) QTIResultManager(org.olat.ims.qti.QTIResultManager) QTIExportFormatterCSVType1(org.olat.ims.qti.export.QTIExportFormatterCSVType1) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Date(java.util.Date) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) CourseNode(org.olat.course.nodes.CourseNode)

Example 13 with QTIResult

use of org.olat.ims.qti.QTIResult in project OpenOLAT by OpenOLAT.

the class IQConfigurationController method doChangeTestAndSurvey.

private void doChangeTestAndSurvey(UserRequest ureq, RepositoryEntry re) {
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(searchController);
    String[] types;
    if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) {
        // test
        types = new String[] { TestFileResource.TYPE_NAME, ImsQTI21Resource.TYPE_NAME };
    } else {
        // survey
        types = new String[] { SurveyFileResource.TYPE_NAME };
    }
    if (moduleConfiguration.get(IQEditController.CONFIG_KEY_TYPE_QTI) == null) {
        updateQtiType(re);
    }
    int onyxSuccess = 0;
    if (moduleConfiguration.get(IQEditController.CONFIG_KEY_TYPE_QTI) != null && moduleConfiguration.get(IQEditController.CONFIG_KEY_TYPE_QTI).equals(IQEditController.CONFIG_VALUE_QTI2)) {
        if (courseNode.getClass().equals(IQSURVCourseNode.class)) {
            File surveyDir = new File(course.getCourseEnvironment().getCourseBaseContainer().getBasefile() + File.separator + courseNode.getIdent() + File.separator);
            if (surveyDir != null && surveyDir.exists() && surveyDir.listFiles().length > 0) {
                onyxSuccess = surveyDir.listFiles().length;
            }
        } else {
            onyxSuccess = QTIResultManager.getInstance().countResults(course.getResourceableId(), courseNode.getIdent(), re.getKey());
        }
    }
    if (moduleConfiguration.get(IQEditController.CONFIG_KEY_TYPE_QTI) != null && moduleConfiguration.get(IQEditController.CONFIG_KEY_TYPE_QTI).equals(IQEditController.CONFIG_VALUE_QTI2) && onyxSuccess > 0) {
        showError("error.onyx");
    } else {
        List<QTIResult> results = QTIResultManager.getInstance().selectResults(course.getResourceableId(), courseNode.getIdent(), re.getKey(), null, 1);
        // test was passed from an user
        boolean passed = (results != null && !results.isEmpty()) ? true : false;
        // test was started and not passed
        // it exists partly results for this test
        List<Identity> identitiesWithQtiSerEntry = iqManager.getIdentitiesWithQtiSerEntry(course.getResourceableId(), courseNode.getIdent());
        if (passed || !identitiesWithQtiSerEntry.isEmpty()) {
            learners = new ArrayList<>();
            for (QTIResult result : results) {
                Identity identity = result.getResultSet().getIdentity();
                if (identity != null && !learners.contains(identity)) {
                    learners.add(identity);
                }
            }
            // add identities with qti.ser entry
            for (Identity identity : identitiesWithQtiSerEntry) {
                if (!learners.contains(identity)) {
                    learners.add(identity);
                }
            }
            replaceWizard = new IQEditReplaceWizard(ureq, getWindowControl(), course, courseNode, types, learners, results, identitiesWithQtiSerEntry.size());
            replaceWizard.addControllerListener(this);
            cmc = new CloseableModalController(getWindowControl(), translate("close"), replaceWizard.getInitialComponent());
            cmc.activate();
        } else {
            if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) {
                // test
                searchController = new ReferencableEntriesSearchController(getWindowControl(), ureq, types, translate("command.chooseTest"));
            } else {
                // survey
                searchController = new ReferencableEntriesSearchController(getWindowControl(), ureq, types, translate("command.chooseSurvey"));
            }
            listenTo(searchController);
            cmc = new CloseableModalController(getWindowControl(), translate("close"), searchController.getInitialComponent());
            cmc.activate();
        }
    }
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ReferencableEntriesSearchController(org.olat.repository.controllers.ReferencableEntriesSearchController) Identity(org.olat.core.id.Identity) File(java.io.File)

Example 14 with QTIResult

use of org.olat.ims.qti.QTIResult in project OpenOLAT by OpenOLAT.

the class QTIArchiver method exportQTI12.

public MediaResource exportQTI12() {
    RepositoryEntry testRe = courseNode.getReferencedRepositoryEntry();
    // fields separated by
    String sep = "\\t";
    // fields embedded by
    String emb = "\"";
    // carriage return
    String car = "\\r\\n";
    sep = convert2CtrlChars(sep);
    car = convert2CtrlChars(car);
    boolean tagLess = true;
    QTIExportFormatter formatter = getFormatter(sep, emb, car, tagLess);
    formatter.setMapWithExportItemConfigs(qtiItemConfigs);
    return new DefaultMediaResource() {

        @Override
        public String getContentType() {
            return "text/csv";
        }

        @Override
        public void prepare(HttpServletResponse hres) {
            try {
                hres.setCharacterEncoding("UTF-8");
            } catch (Exception e) {
                log.error("", e);
            }
            String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
            String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
            hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
            hres.setHeader("Content-Description", urlEncodedLabel);
            try (OutputStream out = hres.getOutputStream()) {
                List<QTIResult> qtiResults = qrm.selectResults(courseOres.getResourceableId(), courseNode.getIdent(), testRe.getKey(), null, 5);
                qem.exportResults(formatter, qtiResults, qtiItemObjectList, out);
            } catch (IOException e) {
                log.error("", e);
            }
        }
    };
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) DefaultMediaResource(org.olat.core.gui.media.DefaultMediaResource) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) Date(java.util.Date)

Example 15 with QTIResult

use of org.olat.ims.qti.QTIResult in project OpenOLAT by OpenOLAT.

the class QTIExportManager method stripNextAssessID.

/**
 * @param queryResult
 * @return List of results with the same assessmentid
 */
private List<QTIResult> stripNextAssessID(List<QTIResult> queryResult) {
    List<QTIResult> result = new ArrayList<>();
    if (queryResult.size() == 0)
        return result;
    QTIResult qtir = queryResult.remove(0);
    long currentAssessmentID = qtir.getResultSet().getAssessmentID();
    result.add(qtir);
    while (queryResult.size() > 0) {
        qtir = queryResult.remove(0);
        if (qtir.getResultSet().getAssessmentID() == currentAssessmentID)
            result.add(qtir);
        else {
            queryResult.add(0, qtir);
            break;
        }
    }
    return result;
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) ArrayList(java.util.ArrayList)

Aggregations

QTIResult (org.olat.ims.qti.QTIResult)22 Date (java.util.Date)10 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)8 QTIResultManager (org.olat.ims.qti.QTIResultManager)6 QTIResultSet (org.olat.ims.qti.QTIResultSet)6 QTIObjectTreeBuilder (org.olat.ims.qti.export.helper.QTIObjectTreeBuilder)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 ArrayList (java.util.ArrayList)4 Identity (org.olat.core.id.Identity)4 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)4 File (java.io.File)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Calendar (java.util.Calendar)2 List (java.util.List)2 ZipEntry (java.util.zip.ZipEntry)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Group (org.olat.basesecurity.Group)2