use of org.olat.ims.qti.export.helper.QTIItemObject in project openolat by klemens.
the class QTIExportManager method selectAndExportResults.
public boolean selectAndExportResults(QTIExportFormatter qef, Long courseResId, String shortTitle, String olatResourceDetail, RepositoryEntry testRe, ZipOutputStream exportStream, Locale locale, String fileNameSuffix) throws IOException {
boolean resultsFoundAndExported = false;
QTIResultManager qrm = QTIResultManager.getInstance();
List<QTIResult> results = qrm.selectResults(courseResId, olatResourceDetail, testRe.getKey(), null, qef.getType());
if (results.size() > 0) {
List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(testRe);
qef.setQTIItemObjectList(qtiItemObjectList);
if (results.size() > 0) {
createContentOfExportFile(results, qtiItemObjectList, qef);
String targetFileName = getFilename(shortTitle, fileNameSuffix);
exportStream.putNextEntry(new ZipEntry(targetFileName));
IOUtils.write(qef.getReport(), exportStream);
exportStream.closeEntry();
resultsFoundAndExported = true;
}
} else {
String targetFileName = getFilename(shortTitle, fileNameSuffix);
exportStream.putNextEntry(new ZipEntry(targetFileName));
Translator translator = Util.createPackageTranslator(QTIExportFormatter.class, locale);
IOUtils.write(translator.translate("archive.noresults.short"), exportStream);
exportStream.closeEntry();
resultsFoundAndExported = true;
}
return resultsFoundAndExported;
}
use of org.olat.ims.qti.export.helper.QTIItemObject in project OpenOLAT by OpenOLAT.
the class QTIStatisticsManagerLargeTest method testItemStatistics_multipleChoice_1.
@Test
public void testItemStatistics_multipleChoice_1() {
QTIItemObject itemObject = itemObjects.get(1);
double maxValue = Double.parseDouble(itemObject.getItemMaxValue());
QTIStatisticSearchParams searchParams = new QTIStatisticSearchParams(olatResource, olatResourceDetail);
StatisticsItem stats = qtim.getItemStatistics(itemObject.getItemIdent(), maxValue, searchParams);
double difficulty = rightAnswersQ2 / (double) numberOfParticipants;
Assert.assertEquals(difficulty, stats.getDifficulty(), 0.1);
Assert.assertEquals(scoreQ2, stats.getAverageScore(), 0.1);
Assert.assertEquals(wrongAnswersQ2, stats.getNumOfIncorrectAnswers());
Assert.assertEquals(numberOfParticipants - wrongAnswersQ2, stats.getNumOfCorrectAnswers());
}
use of org.olat.ims.qti.export.helper.QTIItemObject in project OpenOLAT by OpenOLAT.
the class QTIStatisticsResource method getQTIItemConfigs.
/**
* Copy of QTIArchiveWizardController.getQTIItemConfigs but with all options set
* to true except for the time column.
*
* @param itemList
* @return
*/
private static final Map<Class<?>, QTIExportItemFormatConfig> getQTIItemConfigs(List<QTIItemObject> itemList) {
Map<Class<?>, QTIExportItemFormatConfig> itConfigs = new HashMap<>();
for (Iterator<QTIItemObject> iter = itemList.iterator(); iter.hasNext(); ) {
QTIItemObject item = iter.next();
if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_SCQ)) {
if (itConfigs.get(QTIExportSCQItemFormatConfig.class) == null) {
QTIExportSCQItemFormatConfig confSCQ = new QTIExportSCQItemFormatConfig(true, true, true, false);
itConfigs.put(QTIExportSCQItemFormatConfig.class, confSCQ);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_MCQ)) {
if (itConfigs.get(QTIExportMCQItemFormatConfig.class) == null) {
QTIExportMCQItemFormatConfig confMCQ = new QTIExportMCQItemFormatConfig(true, true, true, false);
itConfigs.put(QTIExportMCQItemFormatConfig.class, confMCQ);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_KPRIM)) {
if (itConfigs.get(QTIExportKPRIMItemFormatConfig.class) == null) {
QTIExportKPRIMItemFormatConfig confKPRIM = new QTIExportKPRIMItemFormatConfig(true, true, true, false);
itConfigs.put(QTIExportKPRIMItemFormatConfig.class, confKPRIM);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_ESSAY)) {
if (itConfigs.get(QTIExportEssayItemFormatConfig.class) == null) {
QTIExportEssayItemFormatConfig confEssay = new QTIExportEssayItemFormatConfig(true, false);
itConfigs.put(QTIExportEssayItemFormatConfig.class, confEssay);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_FIB)) {
if (itConfigs.get(QTIExportFIBItemFormatConfig.class) == null) {
QTIExportFIBItemFormatConfig confFIB = new QTIExportFIBItemFormatConfig(true, true, false);
itConfigs.put(QTIExportFIBItemFormatConfig.class, confFIB);
}
} else // if cannot find the type via the ItemParser, look for the QTIItemObject type
if (item.getItemType().equals(QTIItemObject.TYPE.A)) {
QTIExportEssayItemFormatConfig confEssay = new QTIExportEssayItemFormatConfig(true, false);
itConfigs.put(QTIExportEssayItemFormatConfig.class, confEssay);
} else if (item.getItemType().equals(QTIItemObject.TYPE.R)) {
QTIExportSCQItemFormatConfig confSCQ = new QTIExportSCQItemFormatConfig(true, true, true, false);
itConfigs.put(QTIExportSCQItemFormatConfig.class, confSCQ);
} else if (item.getItemType().equals(QTIItemObject.TYPE.C)) {
QTIExportMCQItemFormatConfig confMCQ = new QTIExportMCQItemFormatConfig(true, true, true, false);
itConfigs.put(QTIExportMCQItemFormatConfig.class, confMCQ);
} else if (item.getItemType().equals(QTIItemObject.TYPE.B)) {
QTIExportFIBItemFormatConfig confFIB = new QTIExportFIBItemFormatConfig(true, true, false);
itConfigs.put(QTIExportFIBItemFormatConfig.class, confFIB);
} else {
throw new OLATRuntimeException(null, "Can not resolve QTIItem type", null);
}
}
return itConfigs;
}
use of org.olat.ims.qti.export.helper.QTIItemObject in project OpenOLAT by OpenOLAT.
the class QTIStatisticsResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding(encoding);
} catch (Exception e) {
log.error("", e);
}
CourseNode courseNode = resourceResult.getTestCourseNode();
String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
hres.setHeader("Content-Description", urlEncodedLabel);
try {
// fields separated by
String sep = "\\t";
// fields embedded by
String emb = "\"";
// carriage return
String car = "\\r\\n";
sep = QTIArchiver.convert2CtrlChars(sep);
car = QTIArchiver.convert2CtrlChars(car);
int exportType = 1;
QTIExportFormatter formatter;
if (QTIType.test.equals(resourceResult.getType())) {
exportType = 1;
formatter = new QTIExportFormatterCSVType1(locale, sep, emb, car, true);
} else if (QTIType.survey.equals(resourceResult.getType())) {
exportType = 2;
formatter = new QTIExportFormatterCSVType3(locale, null, sep, emb, car, true);
} else {
return;
}
Long qtiRepoEntryKey = resourceResult.getQTIRepositoryEntry().getKey();
List<QTIItemObject> itemList = new QTIObjectTreeBuilder().getQTIItemObjectList(resourceResult.getResolver());
formatter.setMapWithExportItemConfigs(getQTIItemConfigs(itemList));
QTIResultManager qrm = QTIResultManager.getInstance();
QTIStatisticSearchParams params = resourceResult.getSearchParams();
List<Group> limitToGroups = params.isMayViewAllUsersAssessments() ? null : params.getLimitToGroups();
List<QTIResult> results = qrm.selectResults(resourceResult.getCourseOres().getResourceableId(), courseNode.getIdent(), qtiRepoEntryKey, limitToGroups, exportType);
QTIExportManager.getInstance().exportResults(formatter, results, itemList, hres.getOutputStream());
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.ims.qti.export.helper.QTIItemObject in project OpenOLAT by OpenOLAT.
the class IQEditReplaceWizard method getQTIItemConfigs.
private Map<Class<?>, QTIExportItemFormatConfig> getQTIItemConfigs(List<QTIItemObject> qtiItemObjectList) {
Map<Class<?>, QTIExportItemFormatConfig> itConfigs = new HashMap<>();
for (Iterator<QTIItemObject> iter = qtiItemObjectList.iterator(); iter.hasNext(); ) {
QTIItemObject item = iter.next();
if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_SCQ)) {
if (itConfigs.get(QTIExportSCQItemFormatConfig.class) == null) {
QTIExportSCQItemFormatConfig confSCQ = new QTIExportSCQItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportSCQItemFormatConfig.class, confSCQ);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_MCQ)) {
if (itConfigs.get(QTIExportMCQItemFormatConfig.class) == null) {
QTIExportMCQItemFormatConfig confMCQ = new QTIExportMCQItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportMCQItemFormatConfig.class, confMCQ);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_KPRIM)) {
if (itConfigs.get(QTIExportKPRIMItemFormatConfig.class) == null) {
QTIExportKPRIMItemFormatConfig confKPRIM = new QTIExportKPRIMItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportKPRIMItemFormatConfig.class, confKPRIM);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_ESSAY)) {
if (itConfigs.get(QTIExportEssayItemFormatConfig.class) == null) {
QTIExportEssayItemFormatConfig confEssay = new QTIExportEssayItemFormatConfig(true, false);
itConfigs.put(QTIExportEssayItemFormatConfig.class, confEssay);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_FIB)) {
if (itConfigs.get(QTIExportFIBItemFormatConfig.class) == null) {
QTIExportFIBItemFormatConfig confFIB = new QTIExportFIBItemFormatConfig(true, false, false);
itConfigs.put(QTIExportFIBItemFormatConfig.class, confFIB);
}
} else if (item.getItemType().equals(QTIItemObject.TYPE.A)) {
QTIExportEssayItemFormatConfig confEssay = new QTIExportEssayItemFormatConfig(true, false);
itConfigs.put(QTIExportEssayItemFormatConfig.class, confEssay);
} else if (item.getItemType().equals(QTIItemObject.TYPE.R)) {
QTIExportSCQItemFormatConfig confSCQ = new QTIExportSCQItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportSCQItemFormatConfig.class, confSCQ);
} else if (item.getItemType().equals(QTIItemObject.TYPE.C)) {
QTIExportMCQItemFormatConfig confMCQ = new QTIExportMCQItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportMCQItemFormatConfig.class, confMCQ);
} else if (item.getItemType().equals(QTIItemObject.TYPE.B)) {
QTIExportFIBItemFormatConfig confFIB = new QTIExportFIBItemFormatConfig(true, false, false);
itConfigs.put(QTIExportFIBItemFormatConfig.class, confFIB);
} else {
throw new OLATRuntimeException(null, "Can not resolve QTIItem type", null);
}
}
return itConfigs;
}
Aggregations