Search in sources :

Example 56 with ResolvedAssessmentItem

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;
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) File(java.io.File) URI(java.net.URI)

Example 57 with ResolvedAssessmentItem

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;
}
Also used : ItemSessionControllerSettings(uk.ac.ed.ph.jqtiplus.running.ItemSessionControllerSettings) ItemProcessingMap(uk.ac.ed.ph.jqtiplus.state.ItemProcessingMap) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ItemProcessingInitializer(uk.ac.ed.ph.jqtiplus.running.ItemProcessingInitializer) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) SimpleJqtiFacade(uk.ac.ed.ph.jqtiplus.SimpleJqtiFacade) Date(java.util.Date)

Example 58 with ResolvedAssessmentItem

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AssessmentItemStatistic(org.olat.ims.qti21.model.statistics.AssessmentItemStatistic) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)

Example 59 with ResolvedAssessmentItem

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);
        }
    }
}
Also used : SectionPart(uk.ac.ed.ph.jqtiplus.node.test.SectionPart) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)

Example 60 with ResolvedAssessmentItem

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());
    }
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ForeignElement(uk.ac.ed.ph.jqtiplus.node.ForeignElement) AssessmentRenderFunctions.getOutcomeValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getOutcomeValue) AssessmentRenderFunctions.extractRecordFieldValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.extractRecordFieldValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) AssessmentRenderFunctions.getHtmlAttributeValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getHtmlAttributeValue) AssessmentRenderFunctions.renderOrderedCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderOrderedCardinalityValue) AssessmentRenderFunctions.isMultipleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMultipleCardinalityValue) AssessmentRenderFunctions.renderSingleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderSingleCardinalityValue) AssessmentRenderFunctions.renderMultipleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderMultipleCardinalityValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) AssessmentRenderFunctions.getTemplateValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getTemplateValue) AssessmentRenderFunctions.renderRecordCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderRecordCardinalityValue) AssessmentRenderFunctions.getResponseValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getResponseValue) AssessmentRenderFunctions.isNullValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isNullValue) AssessmentRenderFunctions.isSingleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isSingleCardinalityValue) AssessmentRenderFunctions.isRecordCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isRecordCardinalityValue) AssessmentRenderFunctions.isOrderedCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isOrderedCardinalityValue) AssessmentRenderFunctions.isMathsContentValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMathsContentValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun)

Aggregations

ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)106 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)76 File (java.io.File)38 URI (java.net.URI)32 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)26 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)26 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)26 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)26 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)22 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)22 IOException (java.io.IOException)20 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)20 URISyntaxException (java.net.URISyntaxException)16 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)16 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)14 ArrayList (java.util.ArrayList)12 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)12 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)12 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)12 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)12