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();
}
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);
}
}
}
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();
}
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;
}
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;
}
Aggregations