use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class RunningItemHelper method run.
public static ItemSessionController run(URI inputUri, Map<Identifier, ResponseData> responseMap, ResourceLocator inputResourceLocator) {
SimpleJqtiFacade simpleJqtiFacade = new SimpleJqtiFacade();
ResolvedAssessmentItem resolvedAssessmentItem = simpleJqtiFacade.loadAndResolveAssessmentItem(inputResourceLocator, inputUri);
ItemProcessingMap itemProcessingMap = new ItemProcessingInitializer(resolvedAssessmentItem, false).initialize();
ItemSessionState itemSessionState = new ItemSessionState();
ItemSessionControllerSettings itemSessionControllerSettings = new ItemSessionControllerSettings();
ItemSessionController itemSessionController = simpleJqtiFacade.createItemSessionController(itemSessionControllerSettings, itemProcessingMap, itemSessionState);
itemSessionController.initialize(new Date());
itemSessionController.performTemplateProcessing(new Date());
itemSessionController.enterItem(new Date());
itemSessionController.bindResponses(new Date(), responseMap);
itemSessionController.commitResponses(new Date());
itemSessionController.performResponseProcessing(new Date());
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
assessmentItem.getItemBody().willShowFeedback(itemSessionController);
itemSessionController.endItem(new Date());
itemSessionController.exitItem(new Date());
return itemSessionController;
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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);
}
}
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project OpenOLAT by OpenOLAT.
the class AssessmentObjectComponentRenderer method renderMath.
protected void renderMath(AssessmentRenderer renderer, StringOutput out, AssessmentObjectComponent component, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, QtiNode mathElement) {
if (mathElement instanceof ForeignElement) {
ForeignElement fElement = (ForeignElement) mathElement;
boolean mi = fElement.getQtiClassName().equals("mi");
boolean ci = fElement.getQtiClassName().equals("ci");
if (ci || mi) {
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
String text = contentAsString(fElement);
Identifier identifier = Identifier.assumedLegal(text);
Value templateValue = getTemplateValue(itemSessionState, text);
Value outcomeValue = getOutcomeValue(itemSessionState, text);
Value responseValue = getResponseValue(assessmentItem, itemSessionState, identifier, renderer.isSolutionMode());
if (templateValue != null && isTemplateDeclarationAMathVariable(assessmentItem, text)) {
if (ci) {
substituteCi(out, templateValue);
} else if (mi) {
substituteMi(out, templateValue);
}
} else if (outcomeValue != null) {
if (ci) {
substituteCi(out, outcomeValue);
} else if (mi) {
substituteMi(out, outcomeValue);
}
} else if (responseValue != null) {
if (ci) {
substituteCi(out, responseValue);
} else if (mi) {
substituteMi(out, responseValue);
}
} else {
renderStartHtmlTag(out, component, resolvedAssessmentItem, fElement, null);
fElement.getChildren().forEach((child) -> renderMath(renderer, out, component, resolvedAssessmentItem, itemSessionState, child));
renderEndTag(out, fElement);
}
} else {
renderStartHtmlTag(out, component, resolvedAssessmentItem, fElement, null);
fElement.getChildren().forEach((child) -> renderMath(renderer, out, component, resolvedAssessmentItem, itemSessionState, child));
renderEndTag(out, fElement);
}
} else if (mathElement instanceof TextRun) {
out.append(((TextRun) mathElement).getTextContent());
}
}
Aggregations