Search in sources :

Example 36 with ResolvedAssessmentItem

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);
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) File(java.io.File) URI(java.net.URI)

Example 37 with ResolvedAssessmentItem

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

Example 38 with ResolvedAssessmentItem

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

Example 39 with ResolvedAssessmentItem

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;
}
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 40 with ResolvedAssessmentItem

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

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