Search in sources :

Example 16 with QTIResult

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

the class QTIExportManager method selectAndExportResults.

/**
 * @param locale
 * @param olatResource
 * @param shortTitle
 * @param olatResourceDetail
 * @param repositoryRef
 * @param type
 * @param exportDirectory
 * @param anonymizerCallback callback that should be used to anonymize the user names or NULL if row counter
 * should be used (only for type 2 and 3)
 * @return
 */
public boolean selectAndExportResults(QTIExportFormatter qef, Long courseResId, String shortTitle, String olatResourceDetail, Long testReKey, File exportDirectory, String charset, String fileNameSuffix) {
    boolean resultsFoundAndExported = false;
    QTIResultManager qrm = QTIResultManager.getInstance();
    List<QTIResult> results = qrm.selectResults(courseResId, olatResourceDetail, testReKey, null, qef.getType());
    if (results.size() > 0) {
        QTIResult res0 = results.get(0);
        List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(new Long(res0.getResultSet().getRepositoryRef()));
        qef.setQTIItemObjectList(qtiItemObjectList);
        if (results.size() > 0) {
            createContentOfExportFile(results, qtiItemObjectList, qef);
            writeContentToFile(shortTitle, exportDirectory, charset, qef, fileNameSuffix);
            resultsFoundAndExported = true;
        }
    }
    return resultsFoundAndExported;
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) QTIResultManager(org.olat.ims.qti.QTIResultManager) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder)

Example 17 with QTIResult

use of org.olat.ims.qti.QTIResult in project openolat by klemens.

the class IQTestHelper method createResult.

public static QTIResult createResult(String itemIdent, String answer, QTIResultSet set) {
    QTIResult result = new QTIResult();
    result.setResultSet(set);
    long tempDuration = Math.round((Math.random() * 10000.0) + 1);
    result.setDuration(tempDuration);
    result.setIp("127.0.0.1");
    result.setAnswer("asdf");
    int tempScore = (int) Math.round(Math.ceil(Math.random()));
    result.setScore(tempScore);
    result.setItemIdent(itemIdent);
    result.setAnswer(answer);
    result.setLastModified(new Date());
    result.setTstamp(result.getLastModified());
    DB dbInstance = DBFactory.getInstance();
    dbInstance.getCurrentEntityManager().persist(result);
    return result;
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) Date(java.util.Date) DB(org.olat.core.commons.persistence.DB)

Example 18 with QTIResult

use of org.olat.ims.qti.QTIResult in project openolat by klemens.

the class IQManager method persistResults.

/**
 * Create the QTIResults on the database for a given assessments,
 * self-assessment or survey. These database entries can be used for
 * statistical downloads.
 *
 * @param ai
 * @param resId
 * @param resDetail
 * @param ureq
 */
public void persistResults(AssessmentInstance ai) {
    AssessmentContext ac = ai.getAssessmentContext();
    QTIResultSet qtiResultSet = new QTIResultSet();
    qtiResultSet.setLastModified(new Date(System.currentTimeMillis()));
    qtiResultSet.setOlatResource(ai.getCallingResId());
    qtiResultSet.setOlatResourceDetail(ai.getCallingResDetail());
    qtiResultSet.setRepositoryRef(ai.getRepositoryEntryKey());
    qtiResultSet.setIdentity(ai.getAssessedIdentity());
    qtiResultSet.setQtiType(ai.getType());
    qtiResultSet.setAssessmentID(ai.getAssessID());
    qtiResultSet.setDuration(new Long(ai.getAssessmentContext().getDuration()));
    if (ai.isSurvey()) {
        qtiResultSet.setScore(0);
        qtiResultSet.setIsPassed(true);
    } else {
        qtiResultSet.setScore(ac.getScore());
        qtiResultSet.setIsPassed(ac.isPassed());
    }
    dbInstance.getCurrentEntityManager().persist(qtiResultSet);
    // Loop over all sections in this assessment
    int sccnt = ac.getSectionContextCount();
    for (int i = 0; i < sccnt; i++) {
        // Loop over all items in this section
        SectionContext sc = ac.getSectionContext(i);
        int iccnt = sc.getItemContextCount();
        for (int j = 0; j < iccnt; j++) {
            ItemContext ic = sc.getItemContext(j);
            // Create new result item for this item
            QTIResult qtiResult = new QTIResult();
            qtiResult.setResultSet(qtiResultSet);
            qtiResult.setItemIdent(ic.getIdent());
            qtiResult.setDuration(new Long(ic.getTimeSpent()));
            if (ai.isSurvey())
                qtiResult.setScore(0);
            else
                qtiResult.setScore(ic.getScore());
            qtiResult.setTstamp(new Date(ic.getLatestAnswerTime()));
            qtiResult.setLastModified(new Date(System.currentTimeMillis()));
            qtiResult.setIp(ai.getRemoteAddr());
            // Get user answers for this item
            StringBuilder sb = new StringBuilder();
            if (ic.getItemInput() == null) {
            } else {
                ItemInput inp = ic.getItemInput();
                if (inp.isEmpty()) {
                    sb.append("[]");
                } else {
                    Map<String, List<String>> im = inp.getInputMap();
                    // Create answer block
                    Set<String> keys = im.keySet();
                    Iterator<String> iter = keys.iterator();
                    while (iter.hasNext()) {
                        String ident = iter.next();
                        // response_lid ident
                        sb.append(ident);
                        sb.append("[");
                        List<String> answers = inp.getAsList(ident);
                        for (int y = 0; y < answers.size(); y++) {
                            sb.append("[");
                            String answer = answers.get(y);
                            // answer is referenced to response_label ident, if
                            // render_choice
                            // answer is userinput, if render_fib
                            answer = quoteSpecialQTIResultCharacters(answer);
                            sb.append(answer);
                            sb.append("]");
                        }
                        sb.append("]");
                    }
                }
            }
            qtiResult.setAnswer(sb.toString());
            // Persist result data in database
            dbInstance.getCurrentEntityManager().persist(qtiResult);
        }
    }
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) QTIResult(org.olat.ims.qti.QTIResult) HttpItemInput(org.olat.ims.qti.container.HttpItemInput) ItemInput(org.olat.ims.qti.container.ItemInput) Date(java.util.Date) QTIResultSet(org.olat.ims.qti.QTIResultSet) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with QTIResult

use of org.olat.ims.qti.QTIResult in project openolat by klemens.

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

use of org.olat.ims.qti.QTIResult in project openolat by klemens.

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)

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