Search in sources :

Example 11 with AssessmentContext

use of org.olat.ims.qti.container.AssessmentContext in project OpenOLAT by OpenOLAT.

the class MenuSectionNavigator method goToSection.

/**
 * @see org.olat.qti.process.Navigator#goToSection(int)
 */
public void goToSection(int sectionPos) {
    clearInfo();
    AssessmentContext ac = getAssessmentContext();
    SectionContext sc = ac.getSectionContext(sectionPos);
    // check if section still open
    if (!ac.isOpen()) {
        getInfo().setError(QTIConstants.ERROR_ASSESSMENT_OUTOFTIME);
        getInfo().setRenderItems(false);
    } else if (!sc.isOpen()) {
        getInfo().setError(QTIConstants.ERROR_SECTION_OUTOFTIME);
        getInfo().setRenderItems(false);
    } else {
        getInfo().setStatus(QTIConstants.ASSESSMENT_RUNNING);
        // show section info (title and description)
        getInfo().setMessage(QTIConstants.MESSAGE_SECTION_INFODEMANDED);
        getInfo().setRenderItems(true);
        ac.setCurrentSectionContextPos(sectionPos);
        sc = ac.getCurrentSectionContext();
        startSection(sc);
    }
    getAssessmentInstance().persist();
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) AssessmentContext(org.olat.ims.qti.container.AssessmentContext)

Example 12 with AssessmentContext

use of org.olat.ims.qti.container.AssessmentContext 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 13 with AssessmentContext

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

the class QTI12PullTestsToolController method retrieveTest.

private void retrieveTest(Identity assessedIdentity, ICourse course) {
    ModuleConfiguration modConfig = courseNode.getModuleConfiguration();
    String resourcePathInfo = courseEnv.getCourseResourceableId() + File.separator + courseNode.getIdent();
    AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(assessedIdentity, "", modConfig, false, courseEnv.getCourseResourceableId(), courseNode.getIdent(), resourcePathInfo, null);
    // close the test
    ai.stop();
    // persist the results
    iqm.persistResults(ai);
    // reporting
    Document docResReporting = iqm.getResultsReporting(ai, assessedIdentity, I18nModule.getDefaultLocale());
    FilePersister.createResultsReporting(docResReporting, assessedIdentity, ai.getFormattedType(), ai.getAssessID());
    // olat results
    AssessmentContext ac = ai.getAssessmentContext();
    Float score = new Float(ac.getScore());
    Boolean passed = new Boolean(ac.isPassed());
    ScoreEvaluation sceval = new ScoreEvaluation(score, passed, Boolean.FALSE, new Long(ai.getAssessID()));
    UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
    courseNode.updateUserScoreEvaluation(sceval, userCourseEnv, assessedIdentity, true, Role.coach);
    // cleanup
    ai.cleanUp();
}
Also used : AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ModuleConfiguration(org.olat.modules.ModuleConfiguration) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) Document(org.dom4j.Document)

Example 14 with AssessmentContext

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

the class DefaultNavigator method submitOneItem.

/**
 * @param curitsinp
 * @return the status of the operation like success or error
 */
public int submitOneItem(ItemsInput curitsinp) {
    if (info.getStatus() != QTIConstants.ASSESSMENT_RUNNING)
        throw new RuntimeException("assessment is NOT running yet or anymore");
    int cnt = curitsinp.getItemCount();
    if (cnt == 0)
        throw new RuntimeException("program bug: not even one iteminput in the answer");
    if (cnt > 1)
        throw new RuntimeException("may only submit 1 item");
    ItemInput itemInput = curitsinp.getItemInputIterator().next();
    String ident = itemInput.getIdent();
    AssessmentContext ac = getAssessmentContext();
    SectionContext sc = ac.getCurrentSectionContext();
    ItemContext it = sc.getCurrentItemContext();
    ItemContext ict = sc.getItemContext(ident);
    if (ict == null)
        throw new RuntimeException("submitted item id (" + ident + ")not found in xml");
    if (ict != it)
        throw new RuntimeException("answering to a non-current item");
    if (!ac.isOpen()) {
        // assessment must also be open (=on time)
        return QTIConstants.ERROR_ASSESSMENT_OUTOFTIME;
    }
    if (!sc.onTime()) {
        // section of the current item must also be open (=on time)
        return QTIConstants.ERROR_SUBMITTEDSECTION_OUTOFTIME;
    }
    if (!ict.isOnTime()) {
        // current item must be on time
        return QTIConstants.ERROR_SUBMITTEDITEM_OUTOFTIME;
    }
    if (!ict.isUnderMaxAttempts()) {
        // current item must be below maxattempts
        return QTIConstants.ERROR_SUBMITTEDITEM_TOOMANYATTEMPTS;
    }
    int subres = ict.addItemInput(itemInput);
    // to have an up-to-date score
    ict.eval();
    return subres;
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) ItemInput(org.olat.ims.qti.container.ItemInput)

Example 15 with AssessmentContext

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

the class DefaultNavigator method submitMultipleItems.

public int submitMultipleItems(ItemsInput curitsinp) {
    // = submit a whole section at once
    if (info.getStatus() != QTIConstants.ASSESSMENT_RUNNING)
        throw new RuntimeException("assessment is NOT running yet or anymore");
    int cnt = curitsinp.getItemCount();
    if (cnt == 0)
        throw new RuntimeException("bug: not even one iteminput in the answer");
    AssessmentContext ac = getAssessmentContext();
    SectionContext sc = ac.getCurrentSectionContext();
    if (!ac.isOpen())
        return QTIConstants.ERROR_ASSESSMENT_OUTOFTIME;
    if (!sc.isOpen())
        return QTIConstants.ERROR_SUBMITTEDSECTION_OUTOFTIME;
    int sectionResult = QTIConstants.SECTION_SUBMITTED;
    for (Iterator<ItemInput> it_inp = curitsinp.getItemInputIterator(); it_inp.hasNext(); ) {
        ItemInput itemInput = it_inp.next();
        String ident = itemInput.getIdent();
        ItemContext ict = sc.getItemContext(ident);
        if (ict == null)
            throw new RuntimeException("submitted item id (" + ident + ") not found in section sectioncontext " + sc.getIdent());
        int subres = ict.addItemInput(itemInput);
        // to be up-to-date with the scores
        ict.eval();
        if (subres != QTIConstants.ITEM_SUBMITTED) {
            // item had a timelimit or maxattempts, which is nonsense if displaymode = sectionPage
            // throw new RuntimeException("section "+sc.getIdent()+" was submitted, but item "+ict.getIdent()+"  could not be submitted, because it had a timelimit or maxattempts, which is nonsense if displaymode = sectionPage");
            sectionResult = QTIConstants.ERROR_SECTION_PART_OUTOFTIME;
        }
    }
    return sectionResult;
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) ItemInput(org.olat.ims.qti.container.ItemInput)

Aggregations

AssessmentContext (org.olat.ims.qti.container.AssessmentContext)44 SectionContext (org.olat.ims.qti.container.SectionContext)28 ItemContext (org.olat.ims.qti.container.ItemContext)20 AssessmentInstance (org.olat.ims.qti.process.AssessmentInstance)12 ItemInput (org.olat.ims.qti.container.ItemInput)10 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)8 Output (org.olat.ims.qti.container.Output)8 Document (org.dom4j.Document)6 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)6 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)6 Hint (org.olat.ims.qti.container.qtielements.Hint)6 ModuleConfiguration (org.olat.modules.ModuleConfiguration)6 Date (java.util.Date)4 List (java.util.List)4 StringOutput (org.olat.core.gui.render.StringOutput)4 QTIResultSet (org.olat.ims.qti.QTIResultSet)4 HttpItemInput (org.olat.ims.qti.container.HttpItemInput)4 Info (org.olat.ims.qti.navigator.Info)4 Resolver (org.olat.ims.qti.process.Resolver)4 Navigator (org.olat.ims.qti.navigator.Navigator)3