use of org.olat.ims.qti.container.ItemInput in project OpenOLAT by OpenOLAT.
the class QTI_varlt 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;
}
use of org.olat.ims.qti.container.ItemInput in project OpenOLAT by OpenOLAT.
the class QTI_varlte 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;
}
use of org.olat.ims.qti.container.ItemInput in project OpenOLAT by OpenOLAT.
the class Response_label method render.
/**
* @see org.olat.ims.qti.container.qtielements.QTIElement#render(StringBuilder,
* RenderInstructions)
*/
@Override
public void render(StringBuilder buffer, RenderInstructions ri) {
ItemInput iinput = (ItemInput) ri.get(RenderInstructions.KEY_ITEM_INPUT);
String responseIdent = (String) ri.get(RenderInstructions.KEY_RESPONSE_IDENT);
// find parent render_xxx element
String renderClass = (String) ri.get(RenderInstructions.KEY_RENDER_CLASS);
if (renderClass == null) {
// we don't know what to do
} else if (renderClass.equals("choice")) {
renderChoice(buffer, ri, iinput);
} else if (renderClass.equals("kprim")) {
buffer.append("<tr><td class='o_qti_item_kprim_input'><input id=\"QTI_").append(ri.get(RenderInstructions.KEY_ITEM_IDENT)).append(getQTIIdent()).append("\" type=\"radio\" class=\"radio\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" value=\"" + getQTIIdent() + ":correct");
if (iinput != null && !iinput.isEmpty()) {
List<String> responses = iinput.getAsList(responseIdent);
if (responses != null && responses.contains(getQTIIdent() + ":correct"))
buffer.append("\" checked=\"checked");
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
buffer.append("</td><td class='o_qti_item_kprim_input'><input id=\"QTI_").append(ri.get(RenderInstructions.KEY_ITEM_IDENT)).append(getQTIIdent()).append("\" type=\"radio\" class=\"radio\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" value=\"" + getQTIIdent() + ":wrong");
if (iinput != null && !iinput.isEmpty()) {
List<String> responses = iinput.getAsList(responseIdent);
if (responses != null && responses.contains(getQTIIdent() + ":wrong"))
buffer.append("\" checked=\"checked");
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
buffer.append("</td><td>");
super.render(buffer, ri);
buffer.append("</td></tr>");
ri.put(RenderInstructions.KEY_FLOW_LABEL, new Integer(RenderInstructions.RENDER_FLOW_BLOCK));
addBr(ri, buffer);
} else if (renderClass.equals("fib")) {
Integer rows = (Integer) ri.get(RenderInstructions.KEY_FIB_ROWS);
Integer columns = (Integer) ri.get(RenderInstructions.KEY_FIB_COLUMNS);
Integer maxlength = (Integer) ri.get(RenderInstructions.KEY_FIB_MAXLENGTH);
if (rows == null || columns == null || maxlength == null)
throw new AssertException("Rows and/or columns attribute not specified for render_fib.");
if (rows.intValue() > 1) {
// render as textarea
buffer.append("<textarea id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" class='form-control' rows=\"").append(rows).append("\" cols=\"").append(columns).append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\">");
if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
buffer.append(iinput.getSingle(getQTIIdent()));
}
buffer.append("</textarea>");
} else {
// render as input string
buffer.append("<span> </span><input id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" type=\"text\" size=\"").append(columns).append("\" maxlength=\"").append(maxlength);
if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
buffer.append("\" value=\"").append(StringHelper.escapeHtml(iinput.getSingle(getQTIIdent())));
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" /><span> </span>");
}
addBr(ri, buffer);
}
}
use of org.olat.ims.qti.container.ItemInput 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);
}
}
}
use of org.olat.ims.qti.container.ItemInput in project openolat by klemens.
the class Response_label method render.
/**
* @see org.olat.ims.qti.container.qtielements.QTIElement#render(StringBuilder,
* RenderInstructions)
*/
@Override
public void render(StringBuilder buffer, RenderInstructions ri) {
ItemInput iinput = (ItemInput) ri.get(RenderInstructions.KEY_ITEM_INPUT);
String responseIdent = (String) ri.get(RenderInstructions.KEY_RESPONSE_IDENT);
// find parent render_xxx element
String renderClass = (String) ri.get(RenderInstructions.KEY_RENDER_CLASS);
if (renderClass == null) {
// we don't know what to do
} else if (renderClass.equals("choice")) {
renderChoice(buffer, ri, iinput);
} else if (renderClass.equals("kprim")) {
buffer.append("<tr><td class='o_qti_item_kprim_input'><input id=\"QTI_").append(ri.get(RenderInstructions.KEY_ITEM_IDENT)).append(getQTIIdent()).append("\" type=\"radio\" class=\"radio\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" value=\"" + getQTIIdent() + ":correct");
if (iinput != null && !iinput.isEmpty()) {
List<String> responses = iinput.getAsList(responseIdent);
if (responses != null && responses.contains(getQTIIdent() + ":correct"))
buffer.append("\" checked=\"checked");
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
buffer.append("</td><td class='o_qti_item_kprim_input'><input id=\"QTI_").append(ri.get(RenderInstructions.KEY_ITEM_IDENT)).append(getQTIIdent()).append("\" type=\"radio\" class=\"radio\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" value=\"" + getQTIIdent() + ":wrong");
if (iinput != null && !iinput.isEmpty()) {
List<String> responses = iinput.getAsList(responseIdent);
if (responses != null && responses.contains(getQTIIdent() + ":wrong"))
buffer.append("\" checked=\"checked");
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
buffer.append("</td><td>");
super.render(buffer, ri);
buffer.append("</td></tr>");
ri.put(RenderInstructions.KEY_FLOW_LABEL, new Integer(RenderInstructions.RENDER_FLOW_BLOCK));
addBr(ri, buffer);
} else if (renderClass.equals("fib")) {
Integer rows = (Integer) ri.get(RenderInstructions.KEY_FIB_ROWS);
Integer columns = (Integer) ri.get(RenderInstructions.KEY_FIB_COLUMNS);
Integer maxlength = (Integer) ri.get(RenderInstructions.KEY_FIB_MAXLENGTH);
if (rows == null || columns == null || maxlength == null)
throw new AssertException("Rows and/or columns attribute not specified for render_fib.");
if (rows.intValue() > 1) {
// render as textarea
buffer.append("<textarea id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" class='form-control' rows=\"").append(rows).append("\" cols=\"").append(columns).append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\">");
if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
buffer.append(iinput.getSingle(getQTIIdent()));
}
buffer.append("</textarea>");
} else {
// render as input string
buffer.append("<span> </span><input id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" type=\"text\" size=\"").append(columns).append("\" maxlength=\"").append(maxlength);
if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
buffer.append("\" value=\"").append(StringHelper.escapeHtml(iinput.getSingle(getQTIIdent())));
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" /><span> </span>");
}
addBr(ri, buffer);
}
}
Aggregations