use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class QTI21QPoolServiceProvider method copyItem.
@Override
public void copyItem(QuestionItemFull original, QuestionItemFull copy) {
VFSContainer originalDir = qpoolFileStorage.getContainer(original.getDirectory());
VFSContainer copyDir = qpoolFileStorage.getContainer(copy.getDirectory());
VFSManager.copyContent(originalDir, copyDir);
File file = qpoolService.getRootFile(copy);
File resourceDirectory = qpoolService.getRootDirectory(copy);
URI assessmentItemUri = file.toURI();
File itemFile = qpoolService.getRootFile(copy);
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
assessmentItem.setTitle(copy.getTitle());
qtiService.persistAssessmentObject(itemFile, assessmentItem);
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class QTI21QPoolServiceProvider method exportToQTIEditor.
/**
* Export to QTI editor an item from the pool. The ident of the item
* is always regenerated as an UUID.
* @param qitem
* @param editorContainer
* @return
*/
public AssessmentItem exportToQTIEditor(QuestionItemFull qitem, Locale locale, File editorContainer) throws IOException {
QTI21ExportProcessor processor = new QTI21ExportProcessor(qtiService, qpoolFileStorage, locale);
ResolvedAssessmentItem resolvedAssessmentItem = processor.exportToQTIEditor(qitem, editorContainer);
if (resolvedAssessmentItem != null) {
AssessmentItem assessmentItem = resolvedAssessmentItem.getItemLookup().extractAssumingSuccessful();
assessmentItem.setIdentifier(QTI21QuestionType.generateNewIdentifier(assessmentItem.getIdentifier()));
return assessmentItem;
}
return null;
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class OLATUpgrade_12_3_0 method getTitleQTI21.
private String getTitleQTI21(QuestionItemImpl item) {
try {
File resourceDirectory = qpoolService.getRootDirectory(item);
File resourceFile = qpoolService.getRootFile(item);
URI assessmentItemUri = resourceFile.toURI();
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
return resolvedAssessmentItem.getRootNodeLookup().getRootNodeHolder().getRootNode().getTitle();
} catch (NullPointerException e) {
log.warn("Cannot read files from dir: " + item.getDirectory());
}
return null;
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class QTI21StatisticsManagerImpl method getStatisticPerItem.
@Override
public List<AssessmentItemStatistic> getStatisticPerItem(ResolvedAssessmentTest resolvedAssessmentTest, QTI21StatisticSearchParams searchParams, double numOfParticipants) {
StringBuilder sb = new StringBuilder();
sb.append("select isession.assessmentItemIdentifier, isession.score, isession.manualScore, count(*) from qtiassessmentitemsession isession").append(" inner join isession.assessmentTestSession asession");
decorateRSet(sb, searchParams, true);
sb.append(" and isession.duration > 0").append(" group by isession.assessmentItemIdentifier, isession.score, isession.manualScore");
TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
decorateRSetQuery(query, searchParams);
List<Object[]> results = query.getResultList();
if (results.isEmpty()) {
return new ArrayList<>();
}
Map<String, AssessmentItemRef> itemMap = new HashMap<>();
List<AssessmentItemRef> itemRefs = new ArrayList<>(resolvedAssessmentTest.getAssessmentItemRefs());
for (AssessmentItemRef itemRef : itemRefs) {
itemMap.put(itemRef.getIdentifier().toString(), itemRef);
}
Map<String, AssessmentItemHelper> identifierToHelpers = new HashMap<>();
for (Object[] result : results) {
int pos = 0;
String identifier = PersistenceHelper.extractString(result, pos++);
BigDecimal score = (BigDecimal) result[pos++];
BigDecimal manualScore = (BigDecimal) result[pos++];
Long count = PersistenceHelper.extractLong(result, pos++);
if (score == null || identifier == null || count == null) {
continue;
}
AssessmentItemHelper helper = identifierToHelpers.get(identifier);
if (helper == null) {
AssessmentItemRef itemRef = itemMap.get(identifier);
if (itemRef == null) {
continue;
}
ResolvedAssessmentItem item = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
if (item == null) {
continue;
}
helper = new AssessmentItemHelper(item.getRootNodeLookup().extractIfSuccessful());
identifierToHelpers.put(identifier, helper);
}
helper.addCount(count);
if (manualScore != null) {
helper.addTotalScore(count, manualScore);
} else {
helper.addTotalScore(count, score);
}
if (helper.getMaxScore() != null) {
double maxValue = helper.getMaxScore().doubleValue();
if (Math.abs(score.doubleValue() - maxValue) < 0.0001) {
helper.addCorrectAnswers(count);
}
}
}
List<AssessmentItemStatistic> statistics = new ArrayList<>(identifierToHelpers.size());
for (AssessmentItemRef itemRef : itemRefs) {
AssessmentItemHelper helper = identifierToHelpers.get(itemRef.getIdentifier().toString());
if (helper != null) {
long numOfAnswersItem = helper.count;
long numOfCorrectAnswers = helper.countCorrectAnswers;
double average = (helper.totalScore / helper.count);
double averageParticipants = (helper.totalScore / numOfParticipants);
statistics.add(new AssessmentItemStatistic(helper.getAssessmentItem(), average, averageParticipants, numOfAnswersItem, numOfCorrectAnswers));
} else {
ResolvedAssessmentItem item = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
if (item != null) {
statistics.add(new AssessmentItemStatistic(item.getRootNodeLookup().extractIfSuccessful(), 0.0d, 0.0d, 0l, 0l));
}
}
}
return statistics;
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class QTI21ArchiveFormat method collectElementInfos.
private void collectElementInfos(AssessmentSection section) {
numOfSections++;
SectionInfos sectionInfos = new SectionInfos(section);
elementInfos.add(sectionInfos);
List<SectionPart> parts = section.getChildAbstractParts();
for (SectionPart part : parts) {
if (part instanceof AssessmentItemRef) {
AssessmentItemRef itemRef = (AssessmentItemRef) part;
ResolvedAssessmentItem resolvedItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
AssessmentItem item = resolvedItem.getRootNodeLookup().extractIfSuccessful();
if (item != null) {
ItemInfos itemInfo = new ItemInfos(itemRef, item, item.getItemBody().findInteractions());
elementInfos.add(itemInfo);
sectionInfos.getItemInfos().add(itemInfo);
}
} else if (part instanceof AssessmentSection) {
collectElementInfos((AssessmentSection) part);
}
}
}
Aggregations