Search in sources :

Example 1 with AssessmentItemStatistic

use of org.olat.ims.qti21.model.statistics.AssessmentItemStatistic 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 2 with AssessmentItemStatistic

use of org.olat.ims.qti21.model.statistics.AssessmentItemStatistic 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 3 with AssessmentItemStatistic

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

the class QTI21AssessmentTestStatisticsController method initScoreStatisticPerItem.

/**
 * The 2 graphs with the score per questions and right answers per questions.
 *
 * @param numOfParticipants The number of participants
 */
private void initScoreStatisticPerItem(double numOfParticipants) {
    BarSeries d1 = new BarSeries();
    BarSeries d2 = new BarSeries();
    List<AssessmentItemStatistic> statisticItems = qtiStatisticsManager.getStatisticPerItem(resourceResult.getResolvedAssessmentTest(), resourceResult.getSearchParams(), numOfParticipants);
    int i = 0;
    List<ItemInfos> itemInfos = new ArrayList<>(statisticItems.size());
    for (AssessmentItemStatistic statisticItem : statisticItems) {
        AssessmentItem item = statisticItem.getAssessmentItem();
        String label = Integer.toString(++i);
        String text = item.getTitle();
        d1.add(statisticItem.getAverageScore(), label);
        d2.add(statisticItem.getNumOfCorrectAnswers(), label);
        itemInfos.add(new ItemInfos(label, text));
    }
    mainVC.contextPut("itemInfoList", itemInfos);
    VelocityContainer averageScorePeritemVC = createVelocityContainer("hbar_average_score_per_item");
    Stringuified data1 = BarSeries.getDatasAndColors(Collections.singletonList(d1), "bar_default");
    averageScorePeritemVC.contextPut("datas", data1);
    mainVC.put("averageScorePerItemChart", averageScorePeritemVC);
    VelocityContainer percentRightAnswersPerItemVC = createVelocityContainer("hbar_right_answer_per_item");
    Stringuified data2 = BarSeries.getDatasAndColors(Collections.singletonList(d2), "bar_green");
    percentRightAnswersPerItemVC.contextPut("datas", data2);
    percentRightAnswersPerItemVC.contextPut("numOfParticipants", Long.toString(Math.round(numOfParticipants)));
    mainVC.put("percentRightAnswersPerItemChart", percentRightAnswersPerItemVC);
}
Also used : Stringuified(org.olat.core.gui.components.chart.BarSeries.Stringuified) ArrayList(java.util.ArrayList) BarSeries(org.olat.core.gui.components.chart.BarSeries) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ItemInfos(org.olat.ims.qti.statistics.ui.QTI12AssessmentStatisticsController.ItemInfos) StatisticFormatter.getModeString(org.olat.ims.qti.statistics.ui.StatisticFormatter.getModeString) AssessmentItemStatistic(org.olat.ims.qti21.model.statistics.AssessmentItemStatistic) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 4 with AssessmentItemStatistic

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

the class QTI21AssessmentTestStatisticsController method initScoreStatisticPerItem.

/**
 * The 2 graphs with the score per questions and right answers per questions.
 *
 * @param numOfParticipants The number of participants
 */
private void initScoreStatisticPerItem(double numOfParticipants) {
    BarSeries d1 = new BarSeries();
    BarSeries d2 = new BarSeries();
    List<AssessmentItemStatistic> statisticItems = qtiStatisticsManager.getStatisticPerItem(resourceResult.getResolvedAssessmentTest(), resourceResult.getSearchParams(), numOfParticipants);
    int i = 0;
    List<ItemInfos> itemInfos = new ArrayList<>(statisticItems.size());
    for (AssessmentItemStatistic statisticItem : statisticItems) {
        AssessmentItem item = statisticItem.getAssessmentItem();
        String label = Integer.toString(++i);
        String text = item.getTitle();
        d1.add(statisticItem.getAverageScore(), label);
        d2.add(statisticItem.getNumOfCorrectAnswers(), label);
        itemInfos.add(new ItemInfos(label, text));
    }
    mainVC.contextPut("itemInfoList", itemInfos);
    VelocityContainer averageScorePeritemVC = createVelocityContainer("hbar_average_score_per_item");
    Stringuified data1 = BarSeries.getDatasAndColors(Collections.singletonList(d1), "bar_default");
    averageScorePeritemVC.contextPut("datas", data1);
    mainVC.put("averageScorePerItemChart", averageScorePeritemVC);
    VelocityContainer percentRightAnswersPerItemVC = createVelocityContainer("hbar_right_answer_per_item");
    Stringuified data2 = BarSeries.getDatasAndColors(Collections.singletonList(d2), "bar_green");
    percentRightAnswersPerItemVC.contextPut("datas", data2);
    percentRightAnswersPerItemVC.contextPut("numOfParticipants", Long.toString(Math.round(numOfParticipants)));
    mainVC.put("percentRightAnswersPerItemChart", percentRightAnswersPerItemVC);
}
Also used : Stringuified(org.olat.core.gui.components.chart.BarSeries.Stringuified) ArrayList(java.util.ArrayList) BarSeries(org.olat.core.gui.components.chart.BarSeries) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ItemInfos(org.olat.ims.qti.statistics.ui.QTI12AssessmentStatisticsController.ItemInfos) StatisticFormatter.getModeString(org.olat.ims.qti.statistics.ui.StatisticFormatter.getModeString) AssessmentItemStatistic(org.olat.ims.qti21.model.statistics.AssessmentItemStatistic) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Aggregations

ArrayList (java.util.ArrayList)4 AssessmentItemStatistic (org.olat.ims.qti21.model.statistics.AssessmentItemStatistic)4 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2 BarSeries (org.olat.core.gui.components.chart.BarSeries)2 Stringuified (org.olat.core.gui.components.chart.BarSeries.Stringuified)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 ItemInfos (org.olat.ims.qti.statistics.ui.QTI12AssessmentStatisticsController.ItemInfos)2 StatisticFormatter.getModeString (org.olat.ims.qti.statistics.ui.StatisticFormatter.getModeString)2 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)2 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)2 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)2