int sectioncnt = ac.getSectionContextCount();
for (int i = 0; i < sectioncnt; i++) {
SectionContext sc = ac.getSectionContext(i);
int itemcnt = sc.getItemContextCount();
for (int j = 0; j < itemcnt; j++) {
ItemContext it = sc.getItemContext(j);
Element el_item = it.getEl_item();
extension_result.add(el_item);
}
}
// add ims cp id for any media references
addStaticsPath(extension_result, ai);
// add assessment_result
// Add User information
Element context = result.addElement("context");
User user = identity.getUser();
String name = user.getProperty(UserConstants.LASTNAME, locale) + " " + user.getProperty(UserConstants.FIRSTNAME, locale) + " (" + identity.getName() + ")";
String instId = user.getProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, locale);
String instName = user.getProperty(UserConstants.INSTITUTIONALNAME, locale);
if (instId == null) instId = "N/A";
context.addElement("name").addText(name);
String institution;
if (instName == null) institution = "N/A";
else institution = instName;
if (institution == null) institution = "N/A";
// Add institutional identifier (e.g. Matrikelnummer)
Element generic_identifier = context.addElement("generic_identifier");
generic_identifier.addElement("type_label").addText(institution);
generic_identifier.addElement("identifier_string").addText(instId);
// Add start and stop date formatted as datetime
Element beginDate = context.addElement("date");
beginDate.addElement("type_label").addText("Start");
beginDate.addElement("datetime").addText(Formatter.formatDatetime(new Date(ac.getTimeOfStart())));
Element stopDate = context.addElement("date");
stopDate.addElement("type_label").addText("Stop");
stopDate.addElement("datetime").addText(Formatter.formatDatetime(new Date(ac.getTimeOfStop())));
Element ares = result.addElement("assessment_result");
ares.addAttribute("ident_ref", ac.getIdent());
if (ac.getTitle() != null) {
ares.addAttribute("asi_title", ac.getTitle());
}
// process assessment score
Element a_score = ares.addElement("outcomes").addElement("score");
a_score.addAttribute("varname", "SCORE");
String strVal = StringHelper.formatFloat(ac.getScore(), 2);
a_score.addElement("score_value").addText(strVal);
strVal = ac.getMaxScore() == -1.0f ? "N/A" : StringHelper.formatFloat(ac.getMaxScore(), 2);
a_score.addElement("score_max").addText(strVal);
strVal = ac.getCutvalue() == -1.0f ? "N/A" : StringHelper.formatFloat(ac.getCutvalue(), 2);
a_score.addElement("score_cut").addText(strVal);
addElementText(ares, "duration", QTIHelper.getISODuration(ac.getDuration()));
addElementText(ares, "num_sections", "" + ac.getSectionContextCount());
addElementText(ares, "num_sections_presented", "0");
addElementText(ares, "num_items", "" + ac.getItemContextCount());
addElementText(ares, "num_items_presented", "" + ac.getItemsPresentedCount());
addElementText(ares, "num_items_attempted", "" + ac.getItemsAttemptedCount());
// add section_result
int secnt = ac.getSectionContextCount();
for (int i = 0; i < secnt; i++) {
SectionContext secc = ac.getSectionContext(i);
Element secres = ares.addElement("section_result");
secres.addAttribute("ident_ref", secc.getIdent());
if (secc.getTitle() != null) {
secres.addAttribute("asi_title", secc.getTitle());
}
addElementText(secres, "duration", QTIHelper.getISODuration(secc.getDuration()));
addElementText(secres, "num_items", "" + secc.getItemContextCount());
addElementText(secres, "num_items_presented", "" + secc.getItemsPresentedCount());
addElementText(secres, "num_items_attempted", "" + secc.getItemsAttemptedCount());
// process section score
Element sec_score = secres.addElement("outcomes").addElement("score");
sec_score.addAttribute("varname", "SCORE");
strVal = secc.getScore() == -1.0f ? "N/A" : "" + StringHelper.formatFloat(secc.getScore(), 2);
sec_score.addElement("score_value").addText(strVal);
strVal = secc.getMaxScore() == -1.0f ? "N/A" : "" + StringHelper.formatFloat(secc.getMaxScore(), 2);
sec_score.addElement("score_max").addText(strVal);
strVal = secc.getCutValue() == -1 ? "N/A" : "" + secc.getCutValue();
sec_score.addElement("score_cut").addText(strVal);
// iterate over all items in this section context
List itemsc = secc.getSectionItemContexts();
for (Iterator it_it = itemsc.iterator(); it_it.hasNext();) {
ItemContext itemc = (ItemContext) it_it.next();
Element itres = secres.addElement("item_result");
itres.addAttribute("ident_ref", itemc.getIdent());
itres.addAttribute("asi_title", itemc.getEl_item().attributeValue("title"));
Element it_duration = itres.addElement("duration");
it_duration.addText(QTIHelper.getISODuration(itemc.getTimeSpent()));
// process item score
DecimalVariable scoreVar = (DecimalVariable) (itemc.getVariables().getSCOREVariable());
Element it_score = itres.addElement("outcomes").addElement("score");
it_score.addAttribute("varname", "SCORE");
it_score.addElement("score_value").addText(StringHelper.formatFloat(scoreVar.getTruncatedValue(), 2));
strVal = scoreVar.hasMinValue() ? "" + scoreVar.getMinValue() : "0.0";
it_score.addElement("score_min").addText(strVal);
strVal = scoreVar.hasMaxValue() ? "" + scoreVar.getMaxValue() : "N/A";
it_score.addElement("score_max").addText(strVal);
strVal = scoreVar.hasCutValue() ? "" + scoreVar.getCutValue() : "N/A";
it_score.addElement("score_cut").addText(strVal);
Element el_item = itemc.getEl_item();
Map res_responsehash = new HashMap(3);
// iterate over all responses of this item
List resps = el_item.selectNodes(".//response_lid|.//response_xy|.//response_str|.//response_num|.//response_grp");
for (Iterator it_resp = resps.iterator(); it_resp.hasNext();) {
Element resp = (Element) it_resp.next();
String ident = resp.attributeValue("ident");
String rcardinality = resp.attributeValue("rcardinality");
String rtiming = resp.attributeValue("rtiming");
// add new response
Element res_response = itres.addElement("response");
res_response.addAttribute("ident_ref", ident);
res_responsehash.put(ident, res_response); // enable lookup of
// @identref of <response>
// (needed with <varequal>
// elements
// add new response_form
//<response_lid ident="MR01" rcardinality="Multiple" rtiming="No">
Element res_responseform = res_response.addElement("response_form");
res_responseform.addAttribute("cardinality", rcardinality);
res_responseform.addAttribute("timing", rtiming);
String respName = resp.getName();
String type = respName.substring(respName.indexOf("_") + 1);
res_responseform.addAttribute("response_type", type);
// add user answer
ItemInput itemInp = itemc.getItemInput();
Translator trans = Util.createPackageTranslator(QTIModule.class, locale);
if (itemInp == null) { // user did not answer this question at all
res_response.addElement("response_value").addText(trans.translate("ResBuilder.NoAnswer"));
} else {
List userAnswer = itemInp.getAsList(ident);