Search in sources :

Example 11 with ItemInput

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

the class QTI_varequal method eval.

/**
 * var equals
 * qti ims 1.2.1
 * <!ELEMENT varequal (#PCDATA)>
 *	<!ATTLIST varequal  %I_Case; %I_RespIdent; %I_Index; >
 * mit I_Case = case  (Yes | No )  'No'
 * e.g. <varequal respident = "LID01">A</varequal>
 */
public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
    ItemInput iinp = userContext.getItemInput();
    // user has given no answer
    if (iinp.isEmpty())
        return false;
    String respident = boolElement.attributeValue("respident");
    String yescase = boolElement.attributeValue("case");
    // make it compatible with faulty QTI documentation
    boolean caseimp = (yescase == null) ? true : yescase.equals("Yes");
    // the answer is tested against content of elem.
    String shouldVal = boolElement.getText();
    boolean ok = (caseimp ? iinp.contains(respident, shouldVal) : iinp.containsIgnoreCase(respident, shouldVal));
    return ok;
}
Also used : ItemInput(org.olat.ims.qti.container.ItemInput)

Example 12 with ItemInput

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

the class QTI_vargt method eval.

/**
 * var greater than or equal qti ims 1.2.1 <!ELEMENT vargte (#PCDATA)>
 * <!ATTLIST vargte %I_RespIdent; %I_Index; > e.g. <vargte respident =
 * "NUM01">3.141 </vargte>
 * @param boolElement
 * @param userContext
 * @param ect
 * @return
 */
public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
    ItemInput iinp = userContext.getItemInput();
    // user has given no answer
    if (iinp.isEmpty())
        return false;
    String respident = boolElement.attributeValue("respident");
    // the answer is tested against
    String shouldVal = boolElement.getText();
    // content of elem.
    String isVal = iinp.getSingle(respident);
    // the isVal and shouldVal must be numeric
    // we use Float so we are on the safe side, even if comparison was only
    // Integer
    shouldVal = shouldVal.trim();
    isVal = isVal.trim();
    float fs = Float.parseFloat(shouldVal);
    float fi;
    try {
        fi = Float.parseFloat(isVal);
    } catch (NumberFormatException e) {
        // try to replace , -> .
        isVal = isVal.replace(',', '.');
        try {
            fi = Float.parseFloat(isVal);
        } catch (NumberFormatException e1) {
            // we try all what we can to understand the input value -> false
            return false;
        }
    }
    boolean ok = (fi > fs);
    return ok;
}
Also used : ItemInput(org.olat.ims.qti.container.ItemInput)

Example 13 with ItemInput

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

the class QTI_vargte method eval.

/**
 * var greater than or equal
 * qti ims 1.2.1
 * <!ELEMENT vargte (#PCDATA)>
 * <!ATTLIST vargte  %I_RespIdent;
 *                   %I_Index; >
 * e.g. <vargte respident = "NUM01">3.141</vargte>
 */
public boolean eval(Element boolElement, ItemContext userContext, EvalContext ect) {
    ItemInput iinp = userContext.getItemInput();
    // user has given no answer
    if (iinp.isEmpty())
        return false;
    String respident = boolElement.attributeValue("respident");
    // the answer is tested against content of elem.
    String shouldVal = boolElement.getText();
    String isVal = iinp.getSingle(respident);
    // the isVal and shouldVal must be numeric
    // we use Float so we are on the safe side, even if comparison was only Integer
    shouldVal = shouldVal.trim();
    isVal = isVal.trim();
    float fs = Float.parseFloat(shouldVal);
    float fi;
    try {
        fi = Float.parseFloat(isVal);
    } catch (NumberFormatException e) {
        // try to replace , -> .
        isVal = isVal.replace(',', '.');
        try {
            fi = Float.parseFloat(isVal);
        } catch (NumberFormatException e1) {
            // we try all what we can to understand the input value -> false
            return false;
        }
    }
    boolean ok = (fi >= fs);
    return ok;
}
Also used : ItemInput(org.olat.ims.qti.container.ItemInput)

Example 14 with ItemInput

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

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

ItemInput (org.olat.ims.qti.container.ItemInput)24 AssessmentContext (org.olat.ims.qti.container.AssessmentContext)10 ItemContext (org.olat.ims.qti.container.ItemContext)10 SectionContext (org.olat.ims.qti.container.SectionContext)10 HttpItemInput (org.olat.ims.qti.container.HttpItemInput)6 Date (java.util.Date)4 HashMap (java.util.HashMap)4 List (java.util.List)4 QTIResultSet (org.olat.ims.qti.QTIResultSet)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Document (org.dom4j.Document)2 DocumentFactory (org.dom4j.DocumentFactory)2 Element (org.dom4j.Element)2 XPath (org.dom4j.XPath)2 Translator (org.olat.core.gui.translator.Translator)2 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)2