Search in sources :

Example 16 with QTI21StatisticSearchParams

use of org.olat.ims.qti21.model.QTI21StatisticSearchParams in project openolat by klemens.

the class QTI21StatisticsManagerImpl method getKPrimStatistics.

// stringuifiedResponse: [a93247453265982 correct][b93247453265983 correct][c93247453265984 correct][d93247453265985 correct]
@Override
public List<KPrimStatistics> getKPrimStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
    List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
    List<SimpleMatchSet> matchSets = interaction.getSimpleMatchSets();
    List<KPrimStatistics> kprimPoints = new ArrayList<>();
    SimpleMatchSet fourMatchSet = matchSets.get(0);
    ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
    // readable responses
    Set<String> rightResponses = new HashSet<>();
    List<MapEntry> mapEntries = responseDeclaration.getMapping().getMapEntries();
    for (MapEntry mapEntry : mapEntries) {
        SingleValue mapKey = mapEntry.getMapKey();
        if (mapKey instanceof DirectedPairValue) {
            DirectedPairValue pairValue = (DirectedPairValue) mapKey;
            String source = pairValue.sourceValue().toString();
            String destination = pairValue.destValue().toString();
            rightResponses.add("[" + source + " " + destination + "]");
        }
    }
    for (SimpleAssociableChoice choice : fourMatchSet.getSimpleAssociableChoices()) {
        String choiceIdentifier = choice.getIdentifier().toString();
        String markerCorrect = "[" + choiceIdentifier + " correct]";
        String markerWrong = "[" + choiceIdentifier + " wrong]";
        boolean isCorrectRight = rightResponses.contains(markerCorrect);
        String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
        String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
        long numCorrect = 0;
        long numIncorrect = 0;
        long numUnanswered = 0;
        for (RawData rawData : rawDatas) {
            String response = rawData.getStringuifiedResponse();
            if (response.indexOf(rightFlag) >= 0) {
                numCorrect += rawData.getCount();
            } else if (response.indexOf(wrongFlag) >= 0) {
                numIncorrect += rawData.getCount();
            } else {
                numUnanswered += rawData.getCount();
            }
        }
        kprimPoints.add(new KPrimStatistics(choice.getIdentifier(), isCorrectRight, numCorrect, numIncorrect, numUnanswered));
    }
    return kprimPoints;
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ArrayList(java.util.ArrayList) KPrimStatistics(org.olat.ims.qti21.model.statistics.KPrimStatistics) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) HashSet(java.util.HashSet)

Example 17 with QTI21StatisticSearchParams

use of org.olat.ims.qti21.model.QTI21StatisticSearchParams in project openolat by klemens.

the class QTIArchiver method exportQTI21.

public MediaResource exportQTI21() {
    ICourse course = CourseFactory.loadCourse(courseOres);
    RepositoryEntry testRe = courseNode.getReferencedRepositoryEntry();
    RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    QTI21StatisticSearchParams searchParams = new QTI21StatisticSearchParams(testRe, courseEntry, courseNode.getIdent(), allUsers, anonymUsers);
    return new QTI21ArchiveFormat(locale, searchParams).exportCourseElement();
}
Also used : QTI21StatisticSearchParams(org.olat.ims.qti21.model.QTI21StatisticSearchParams) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) QTI21ArchiveFormat(org.olat.ims.qti21.manager.archive.QTI21ArchiveFormat)

Example 18 with QTI21StatisticSearchParams

use of org.olat.ims.qti21.model.QTI21StatisticSearchParams in project OpenOLAT by OpenOLAT.

the class QTI21StatisticsManagerImpl method getHottextInteractionStatistics.

@Override
public List<ChoiceStatistics> getHottextInteractionStatistics(String itemRefIdent, AssessmentItem assessmentItem, HottextInteraction hottextInteraction, QTI21StatisticSearchParams searchParams) {
    List<RawData> results = getRawDatas(itemRefIdent, hottextInteraction.getResponseIdentifier().toString(), searchParams);
    List<Hottext> hottexts = QueryUtils.search(Hottext.class, hottextInteraction);
    long[] counts = new long[hottexts.size()];
    for (int i = counts.length; i-- > 0; ) {
        counts[i] = 0l;
    }
    for (RawData result : results) {
        Long numOfAnswers = result.getCount();
        ;
        if (numOfAnswers != null && numOfAnswers.longValue() > 0) {
            String stringuifiedResponse = result.getStringuifiedResponse();
            for (int i = hottexts.size(); i-- > 0; ) {
                String identifier = hottexts.get(i).getIdentifier().toString();
                if (stringuifiedResponse.contains(identifier)) {
                    counts[i] += numOfAnswers.longValue();
                }
            }
        }
    }
    List<ChoiceStatistics> choicesStatistics = new ArrayList<>();
    for (int i = 0; i < hottexts.size(); i++) {
        choicesStatistics.add(new ChoiceStatistics(hottexts.get(i), counts[i]));
    }
    return choicesStatistics;
}
Also used : ChoiceStatistics(org.olat.ims.qti21.model.statistics.ChoiceStatistics) HotspotChoiceStatistics(org.olat.ims.qti21.model.statistics.HotspotChoiceStatistics) ArrayList(java.util.ArrayList) Hottext(uk.ac.ed.ph.jqtiplus.node.item.interaction.content.Hottext)

Example 19 with QTI21StatisticSearchParams

use of org.olat.ims.qti21.model.QTI21StatisticSearchParams in project OpenOLAT by OpenOLAT.

the class QTI21StatisticsManagerImpl method getAssessmentStatistics.

@Override
public StatisticAssessment getAssessmentStatistics(QTI21StatisticSearchParams searchParams) {
    StringBuilder sb = new StringBuilder();
    sb.append("select asession.score, asession.manualScore, asession.passed, asession.duration from qtiassessmenttestsession asession ");
    decorateRSet(sb, searchParams, true);
    sb.append(" order by asession.key asc");
    TypedQuery<Object[]> rawDataQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
    decorateRSetQuery(rawDataQuery, searchParams);
    List<Object[]> rawDatas = rawDataQuery.getResultList();
    int numOfPassed = 0;
    int numOfFailed = 0;
    double totalDuration = 0.0;
    double maxScore = 0.0;
    double minScore = Double.MAX_VALUE;
    double[] scores = new double[rawDatas.size()];
    double[] durationSeconds = new double[rawDatas.size()];
    double minDuration = Double.MAX_VALUE;
    double maxDuration = 0d;
    int dataPos = 0;
    boolean hasScore = false;
    for (Object[] rawData : rawDatas) {
        int pos = 0;
        BigDecimal score = (BigDecimal) rawData[pos++];
        BigDecimal manualScore = (BigDecimal) rawData[pos++];
        if (score == null) {
            score = manualScore;
        } else if (manualScore != null) {
            score = score.add(manualScore);
        }
        if (score != null) {
            double scored = score.doubleValue();
            scores[dataPos] = scored;
            maxScore = Math.max(maxScore, scored);
            minScore = Math.min(minScore, scored);
            hasScore = true;
        }
        Boolean passed = (Boolean) rawData[pos++];
        if (passed != null) {
            if (passed.booleanValue()) {
                numOfPassed++;
            } else {
                numOfFailed++;
            }
        }
        Long duration = (Long) rawData[pos++];
        if (duration != null) {
            double durationd = duration.doubleValue();
            double durationSecond = Math.round(durationd / 1000d);
            durationSeconds[dataPos] = durationSecond;
            totalDuration += durationd;
            minDuration = Math.min(minDuration, durationSecond);
            maxDuration = Math.max(maxDuration, durationSecond);
        }
        dataPos++;
    }
    if (rawDatas.size() == 0) {
        minScore = 0;
    }
    Statistics statisticsHelper = new Statistics(scores);
    int numOfParticipants = rawDatas.size();
    StatisticAssessment stats = new StatisticAssessment();
    stats.setNumOfParticipants(numOfParticipants);
    stats.setNumOfPassed(numOfPassed);
    stats.setNumOfFailed(numOfFailed);
    long averageDuration = Math.round(totalDuration / numOfParticipants);
    stats.setAverageDuration(averageDuration);
    stats.setAverage(statisticsHelper.getMean());
    if (hasScore) {
        double range = maxScore - minScore;
        stats.setRange(range);
        stats.setMaxScore(maxScore);
        stats.setMinScore(minScore);
    }
    stats.setStandardDeviation(statisticsHelper.getStdDev());
    stats.setMedian(statisticsHelper.median());
    stats.setMode(statisticsHelper.mode());
    stats.setScores(scores);
    stats.setDurations(durationSeconds);
    return stats;
}
Also used : MatchStatistics(org.olat.ims.qti21.model.statistics.MatchStatistics) ChoiceStatistics(org.olat.ims.qti21.model.statistics.ChoiceStatistics) TextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.TextEntryInteractionStatistics) NumericalInputInteractionStatistics(org.olat.ims.qti21.model.statistics.NumericalInputInteractionStatistics) KPrimStatistics(org.olat.ims.qti21.model.statistics.KPrimStatistics) Statistics(org.olat.ims.qti.statistics.manager.Statistics) AbstractTextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.AbstractTextEntryInteractionStatistics) HotspotChoiceStatistics(org.olat.ims.qti21.model.statistics.HotspotChoiceStatistics) StatisticAssessment(org.olat.ims.qti.statistics.model.StatisticAssessment) BigDecimal(java.math.BigDecimal)

Example 20 with QTI21StatisticSearchParams

use of org.olat.ims.qti21.model.QTI21StatisticSearchParams 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)

Aggregations

QTI21StatisticSearchParams (org.olat.ims.qti21.model.QTI21StatisticSearchParams)16 ArrayList (java.util.ArrayList)14 QTI21ArchiveFormat (org.olat.ims.qti21.manager.archive.QTI21ArchiveFormat)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 HashMap (java.util.HashMap)10 HotspotChoiceStatistics (org.olat.ims.qti21.model.statistics.HotspotChoiceStatistics)8 IOException (java.io.IOException)6 ChoiceStatistics (org.olat.ims.qti21.model.statistics.ChoiceStatistics)6 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)5 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 List (java.util.List)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 ICourse (org.olat.course.ICourse)4 QTIExportFormatterCSVType1 (org.olat.ims.qti.export.QTIExportFormatterCSVType1)4 QTIExportItemFormatDelegate (org.olat.ims.qti.export.QTIExportItemFormatDelegate)4 QTIExportManager (org.olat.ims.qti.export.QTIExportManager)4 KPrimStatistics (org.olat.ims.qti21.model.statistics.KPrimStatistics)4 MatchStatistics (org.olat.ims.qti21.model.statistics.MatchStatistics)4 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)4