Search in sources :

Example 6 with QTIResult

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

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

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

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

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

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)

Example 9 with QTIResult

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

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

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

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)

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