Search in sources :

Example 1 with QTIResultSet

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

the class QTI12ResultsExportMediaResource method createResultDetail.

private List<ResultDetail> createResultDetail(Identity identity, ZipOutputStream zout, String idDir) throws IOException {
    Long resourceId = courseEnv.getCourseResourceableId();
    String resourceDetail = courseNode.getIdent();
    Long resid = courseNode.getReferencedRepositoryEntry().getKey();
    List<QTIResultSet> resultSets = qtiResultManager.getResultSets(resourceId, resourceDetail, resid, identity);
    List<ResultDetail> assessments = new ArrayList<ResultDetail>();
    for (QTIResultSet qtiResultSet : resultSets) {
        Long assessmentID = qtiResultSet.getAssessmentID();
        String idPath = idDir + translator.translate("table.user.attempt") + (resultSets.indexOf(qtiResultSet) + 1) + SEP;
        createZipDirectory(zout, idPath);
        String linkToHTML = createHTMLfromQTIResultSet(idPath, idDir, zout, identity, qtiResultSet);
        // content of result table
        ResultDetail resultDetail = new ResultDetail(createLink(String.valueOf(assessmentID), linkToHTML, true), assessmentDateFormat.format(qtiResultSet.getCreationDate()), displayDateFormat.format(new Date(qtiResultSet.getDuration())), qtiResultSet.getScore(), createPassedIcons(qtiResultSet.getIsPassed()), linkToHTML);
        assessments.add(resultDetail);
    }
    return assessments;
}
Also used : QTIResultSet(org.olat.ims.qti.QTIResultSet) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 2 with QTIResultSet

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

the class QTIStatisticsManagerTest method testLastQTIResultsSetQuery.

/**
 * Test retrieve the last modified result set for every assessed users
 */
@Test
public void testLastQTIResultsSetQuery() {
    RepositoryEntry re = createRepository();
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-stats-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-stats-2");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-stats-3");
    dbInstance.commit();
    long assessmentId = 835l;
    String resSubPath = "1234";
    // 3 try for id1
    QTIResultSet set1_1 = createSet(2.0f, assessmentId, id1, re, resSubPath, modDate(3, 8, 8), modDate(3, 8, 12));
    QTIResultSet set1_3 = createSet(6.0f, assessmentId, id1, re, resSubPath, modDate(3, 14, 7), modDate(3, 14, 38));
    QTIResultSet set1_2 = createSet(4.0f, assessmentId, id1, re, resSubPath, modDate(3, 10, 34), modDate(3, 10, 45));
    // 2 try for id2
    QTIResultSet set2_1 = createSet(6.0f, assessmentId, id2, re, resSubPath, modDate(3, 9, 21), modDate(3, 9, 45));
    QTIResultSet set2_2 = createSet(5.0f, assessmentId, id2, re, resSubPath, modDate(3, 12, 45), modDate(3, 12, 55));
    // 1 try for id1
    QTIResultSet set3_1 = createSet(1.0f, assessmentId, id3, re, resSubPath, modDate(3, 12, 1), modDate(3, 12, 12));
    dbInstance.commit();
    QTIStatisticSearchParams searchParams = new QTIStatisticSearchParams(re.getOlatResource().getResourceableId(), resSubPath);
    List<QTIStatisticResultSet> sets = qtiStatisticsManager.getAllResultSets(searchParams);
    Assert.assertNotNull(sets);
    Assert.assertEquals(3, sets.size());
    List<Long> setKeys = PersistenceHelper.toKeys(sets);
    Assert.assertTrue(setKeys.contains(set1_3.getKey()));
    Assert.assertTrue(setKeys.contains(set2_2.getKey()));
    Assert.assertTrue(setKeys.contains(set3_1.getKey()));
    Assert.assertFalse(setKeys.contains(set1_1.getKey()));
    Assert.assertFalse(setKeys.contains(set1_2.getKey()));
    Assert.assertFalse(setKeys.contains(set2_1.getKey()));
}
Also used : QTIResultSet(org.olat.ims.qti.QTIResultSet) QTIStatisticSearchParams(org.olat.ims.qti.statistics.QTIStatisticSearchParams) RepositoryEntry(org.olat.repository.RepositoryEntry) QTIStatisticResultSet(org.olat.ims.qti.statistics.model.QTIStatisticResultSet) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 3 with QTIResultSet

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

the class CourseAssessmentWebService method importTestItems.

private void importTestItems(ICourse course, String nodeKey, Identity identity, AssessableResultsVO resultsVO) {
    try {
        IQManager iqManager = CoreSpringFactory.getImpl(IQManager.class);
        // load the course and the course node
        CourseNode courseNode = getParentNode(course, nodeKey);
        ModuleConfiguration modConfig = courseNode.getModuleConfiguration();
        // check if the result set is already saved
        QTIResultSet set = iqManager.getLastResultSet(identity, course.getResourceableId(), courseNode.getIdent());
        if (set == null) {
            String resourcePathInfo = course.getResourceableId() + File.separator + courseNode.getIdent();
            // The use of these classes AssessmentInstance, AssessmentContext and
            // Navigator
            // allow the use of the persistence mechanism of OLAT without
            // duplicating the code.
            // The consequence is that we must loop on section and items and set the
            // navigator on
            // the right position before submitting the inputs.
            AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(identity, "", modConfig, false, course.getResourceableId(), courseNode.getIdent(), resourcePathInfo, null);
            Navigator navigator = ai.getNavigator();
            navigator.startAssessment();
            // The type of the navigator depends on the setting of the course node
            boolean perItem = (navigator instanceof MenuItemNavigator);
            Map<String, ItemInput> datas = convertToHttpItemInput(resultsVO.getResults());
            AssessmentContext ac = ai.getAssessmentContext();
            int sectioncnt = ac.getSectionContextCount();
            // loop on the sections
            for (int i = 0; i < sectioncnt; i++) {
                SectionContext sc = ac.getSectionContext(i);
                navigator.goToSection(i);
                ItemsInput iips = new ItemsInput();
                int itemcnt = sc.getItemContextCount();
                // loop on the items
                for (int j = 0; j < itemcnt; j++) {
                    ItemContext it = sc.getItemContext(j);
                    if (datas.containsKey(it.getIdent())) {
                        if (perItem) {
                            // save the datas on a per item base
                            navigator.goToItem(i, j);
                            // the navigator can give informations on its current status
                            Info info = navigator.getInfo();
                            if (info.containsError()) {
                            // some items cannot processed twice
                            } else {
                                iips.addItemInput(datas.get(it.getIdent()));
                                navigator.submitItems(iips);
                                iips = new ItemsInput();
                            }
                        } else {
                            // put for a section
                            iips.addItemInput(datas.get(it.getIdent()));
                        }
                    }
                }
                if (!perItem) {
                    // save the inputs of the section. In a section based navigation,
                    // we must saved the inputs of the whole section at once
                    navigator.submitItems(iips);
                }
            }
            navigator.submitAssessment();
            // persist the QTIResultSet (o_qtiresultset and o_qtiresult) on the
            // database
            // TODO iqManager.persistResults(ai, course.getResourceableId(),
            // courseNode.getIdent(), identity, "127.0.0.1");
            // write the reporting file on the file system
            // The path is <olatdata> / resreporting / <username> / Assessment /
            // <assessId>.xml
            // TODO Document docResReporting = iqManager.getResultsReporting(ai,
            // identity, Locale.getDefault());
            // TODO FilePersister.createResultsReporting(docResReporting, identity,
            // ai.getFormattedType(), ai.getAssessID());
            // prepare all instances needed to save the score at the course node
            // level
            CourseEnvironment cenv = course.getCourseEnvironment();
            IdentityEnvironment identEnv = new IdentityEnvironment();
            identEnv.setIdentity(identity);
            UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identEnv, cenv);
            // update scoring overview for the user in the current course
            Float score = ac.getScore();
            Boolean passed = ac.isPassed();
            // perhaps don't pass this key directly
            ScoreEvaluation sceval = new ScoreEvaluation(score, passed, passed, new Long(nodeKey));
            AssessableCourseNode acn = (AssessableCourseNode) courseNode;
            // assessment nodes are assessable
            boolean incrementUserAttempts = true;
            acn.updateUserScoreEvaluation(sceval, userCourseEnv, identity, incrementUserAttempts, Role.coach);
        } else {
            log.error("Result set already saved");
        }
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) HttpItemInput(org.olat.ims.qti.container.HttpItemInput) ItemInput(org.olat.ims.qti.container.ItemInput) ItemsInput(org.olat.ims.qti.container.ItemsInput) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) IQManager(org.olat.modules.iq.IQManager) ModuleConfiguration(org.olat.modules.ModuleConfiguration) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Navigator(org.olat.ims.qti.navigator.Navigator) MenuItemNavigator(org.olat.ims.qti.navigator.MenuItemNavigator) Info(org.olat.ims.qti.navigator.Info) WebApplicationException(javax.ws.rs.WebApplicationException) QTIResultSet(org.olat.ims.qti.QTIResultSet) MenuItemNavigator(org.olat.ims.qti.navigator.MenuItemNavigator) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl)

Example 4 with QTIResultSet

use of org.olat.ims.qti.QTIResultSet 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 5 with QTIResultSet

use of org.olat.ims.qti.QTIResultSet 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)

Aggregations

QTIResultSet (org.olat.ims.qti.QTIResultSet)22 RepositoryEntry (org.olat.repository.RepositoryEntry)14 Identity (org.olat.core.id.Identity)8 Date (java.util.Date)6 Test (org.junit.Test)6 QTIResult (org.olat.ims.qti.QTIResult)6 ArrayList (java.util.ArrayList)4 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)4 AssessmentContext (org.olat.ims.qti.container.AssessmentContext)4 HttpItemInput (org.olat.ims.qti.container.HttpItemInput)4 ItemContext (org.olat.ims.qti.container.ItemContext)4 ItemInput (org.olat.ims.qti.container.ItemInput)4 SectionContext (org.olat.ims.qti.container.SectionContext)4 QTIStatisticSearchParams (org.olat.ims.qti.statistics.QTIStatisticSearchParams)4 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)4 Calendar (java.util.Calendar)2 List (java.util.List)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Before (org.junit.Before)2 DB (org.olat.core.commons.persistence.DB)2