Search in sources :

Example 1 with QTIResult

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

the class QTIExportManager method createContentOfExportFile.

/**
 * @param locale Locale used for export file headers / default values
 * @param results
 * @param type
 * @param anonymizerCallback
 * @return String
 */
private void createContentOfExportFile(List<QTIResult> qtiResults, List<QTIItemObject> qtiItemObjectList, QTIExportFormatter qef) {
    qef.openReport();
    // formatter has information about how to format the different qti objects
    Map<Class<?>, QTIExportItemFormatConfig> mapWithConfigs = qef.getMapWithExportItemConfigs();
    QTIExportItemFactory qeif = new QTIExportItemFactory(mapWithConfigs);
    while (qtiResults.size() > 0) {
        List<QTIResult> assessIDresults = stripNextAssessID(qtiResults);
        qef.openResultSet(new QTIExportSet(assessIDresults.get(0)));
        for (QTIItemObject element : qtiItemObjectList) {
            QTIResult qtir = element.extractQTIResult(assessIDresults);
            qef.visit(qeif.getExportItem(qtir, element));
        }
        qef.closeResultSet();
    }
    qef.closeReport();
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject)

Example 2 with QTIResult

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

the class QTIExportManager method selectAndExportResults.

public boolean selectAndExportResults(QTIExportFormatter qef, Long courseResId, String shortTitle, String olatResourceDetail, RepositoryEntry testRe, ZipOutputStream exportStream, Locale locale, String fileNameSuffix) throws IOException {
    boolean resultsFoundAndExported = false;
    QTIResultManager qrm = QTIResultManager.getInstance();
    List<QTIResult> results = qrm.selectResults(courseResId, olatResourceDetail, testRe.getKey(), null, qef.getType());
    if (results.size() > 0) {
        List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(testRe);
        qef.setQTIItemObjectList(qtiItemObjectList);
        if (results.size() > 0) {
            createContentOfExportFile(results, qtiItemObjectList, qef);
            String targetFileName = getFilename(shortTitle, fileNameSuffix);
            exportStream.putNextEntry(new ZipEntry(targetFileName));
            IOUtils.write(qef.getReport(), exportStream);
            exportStream.closeEntry();
            resultsFoundAndExported = true;
        }
    } else {
        String targetFileName = getFilename(shortTitle, fileNameSuffix);
        exportStream.putNextEntry(new ZipEntry(targetFileName));
        Translator translator = Util.createPackageTranslator(QTIExportFormatter.class, locale);
        IOUtils.write(translator.translate("archive.noresults.short"), exportStream);
        exportStream.closeEntry();
        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) Translator(org.olat.core.gui.translator.Translator) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) ZipEntry(java.util.zip.ZipEntry)

Example 3 with QTIResult

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

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

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

the class QTIStatisticsManagerLargeTest method setUp.

@Before
public void setUp() throws Exception {
    if (isInitialized)
        return;
    RepositoryEntry re = createRepository();
    olatResource = re.getOlatResource().getResourceableId();
    repositoryRef = re.getKey();
    olatResourceDetail = UUID.randomUUID().toString().replace("-", "");
    getItemObjectList();
    double scoreQuestion1 = 0.0d, scoreQuestion2 = 0.0d, scoreQuestion3 = 0.0d, scoreQuestion4 = 0.0d;
    float maxScoreQ1 = 0, maxScoreQ2 = 0, maxScoreQ3 = 0, maxScoreQ4 = 0;
    // insert value into resultset
    for (int i = 0; i < numberOfParticipants; i++) {
        QTIResultSet test = new QTIResultSet();
        float setScore = (float) Math.ceil(Math.random() * maxScore);
        if (setScore >= 4.0d) {
            numberOfTestPassed++;
            test.setIsPassed(true);
        } else {
            numberOfTestFailed++;
            test.setIsPassed(false);
        }
        long tempTestDuration = Math.round((Math.random() * 100000) + 1.0);
        averageDuration += tempTestDuration;
        averageScore += setScore;
        scorePerParticipant.add(setScore);
        assertNotNull(allDurations);
        allDurations.add(tempTestDuration);
        test.setOlatResource(olatResource);
        test.setOlatResourceDetail(olatResourceDetail);
        test.setRepositoryRef(repositoryRef);
        test.setScore(setScore);
        test.setDuration(tempTestDuration);
        test.setIdentity(JunitTestHelper.createAndPersistIdentityAsUser("test" + i));
        test.setAssessmentID(111L);
        Calendar cal = Calendar.getInstance();
        cal.set(2013, 8, 23, (int) (Math.random() * 1000 % 60), (int) (Math.random() * 1000 % 60), (int) (Math.random() * 1000 % 60));
        test.setLastModified(cal.getTime());
        dbInstance.saveObject(test);
        // insert values into result
        for (int j = 0; j < numberOfQuestions; j++) {
            QTIResult testres = new QTIResult();
            testres.setResultSet(test);
            long tempDuration = Math.round((Math.random() * 10000) + 1.0);
            testres.setDuration(tempDuration);
            testres.setIp("127.0.0.1");
            testres.setAnswer("asdf");
            if (j == 0) {
                testres.setItemIdent("QTIEDIT:SCQ:1000007885");
                if (i % 4 == 0) {
                    testres.setAnswer("1000007887[[1000007890]]");
                } else if (i % 4 == 1) {
                    testres.setAnswer("1000007887[[1000009418]]");
                } else if (i % 4 == 2) {
                    testres.setAnswer("1000007887[[1000009464]]");
                } else if (i % 4 == 3) {
                    testres.setAnswer("1000007887[[1000007890]]");
                }
                float score = (float) Math.ceil(Math.random());
                scoreQ1 += score;
                testres.setScore(score);
                scoreQuestion1 += score;
                if (score == 1.0f) {
                    maxScoreQ1++;
                }
            } else if (j == 1) {
                testres.setItemIdent("QTIEDIT:MCQ:1000009738");
                float score = (float) Math.ceil(Math.random() * 3);
                scoreQ2 += score;
                testres.setScore(score);
                scoreQuestion2 += score;
                if (score < 3.0f) {
                    wrongAnswersQ2++;
                } else {
                    rightAnswersQ2++;
                    maxScoreQ2++;
                }
            } else if (j == 2) {
                testres.setItemIdent("QTIEDIT:KPRIM:1000010376");
                durationQ3 += tempDuration;
                float score = (float) Math.ceil(Math.random() * 2);
                testres.setScore(score);
                scoreQuestion3 += score;
                if (score == 2.0f) {
                    maxScoreQ3++;
                }
            } else if (j == 3) {
                testres.setItemIdent("QTIEDIT:FIB:1000010792");
                if (i % 4 == 0) {
                    testres.setAnswer("Huagagaagaga");
                    fibAnswers.add("Huagagaagaga");
                } else if (i % 4 == 1) {
                    testres.setAnswer("Yikes");
                    fibAnswers.add("Yikes");
                } else if (i % 4 == 2 || i % 4 == 3) {
                    testres.setAnswer("Muragarara");
                    fibAnswers.add("Muragarara");
                }
                float score = (float) Math.ceil(Math.random());
                testres.setScore(score);
                scoreQuestion4 += score;
                if (score == 1.0f) {
                    maxScoreQ4++;
                }
            }
            testres.setLastModified(new Date());
            testres.setTstamp(new Date());
            dbInstance.saveObject(testres);
        }
        dbInstance.commitAndCloseSession();
    }
    dbInstance.commitAndCloseSession();
    durationQ3 = (durationQ3 / numberOfParticipants);
    scoreQ1 = scoreQ1 / numberOfParticipants;
    scoreQ2 = scoreQ2 / numberOfParticipants;
    averageScore = averageScore / numberOfParticipants;
    averageDuration = averageDuration / numberOfParticipants;
    averageScorePerQuestion.put("QTIEDIT:SCQ:1000007885", scoreQuestion1 / numberOfParticipants);
    averageScorePerQuestion.put("QTIEDIT:MCQ:1000009738", scoreQuestion2 / numberOfParticipants);
    averageScorePerQuestion.put("QTIEDIT:KPRIM:1000010376", scoreQuestion3 / numberOfParticipants);
    averageScorePerQuestion.put("QTIEDIT:FIB:1000010792", scoreQuestion4 / numberOfParticipants);
    averageRightAnswersInPercent.add(maxScoreQ1 / numberOfParticipants);
    averageRightAnswersInPercent.add(maxScoreQ2 / numberOfParticipants);
    averageRightAnswersInPercent.add(maxScoreQ3 / numberOfParticipants);
    averageRightAnswersInPercent.add(maxScoreQ4 / numberOfParticipants);
    identToANumOfRightAnswers.put("QTIEDIT:SCQ:1000007885", maxScoreQ1);
    identToANumOfRightAnswers.put("QTIEDIT:MCQ:1000009738", maxScoreQ2);
    identToANumOfRightAnswers.put("QTIEDIT:KPRIM:1000010376", maxScoreQ3);
    identToANumOfRightAnswers.put("QTIEDIT:FIB:1000010792", maxScoreQ4);
    // sort allDurations List asc
    Collections.sort(allDurations);
    Collections.sort(scorePerParticipant);
    isInitialized = true;
}
Also used : QTIResultSet(org.olat.ims.qti.QTIResultSet) QTIResult(org.olat.ims.qti.QTIResult) Calendar(java.util.Calendar) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) Before(org.junit.Before)

Example 5 with QTIResult

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

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)

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