Search in sources :

Example 1 with StatisticItem

use of org.olat.ims.qti.statistics.model.StatisticItem in project OpenOLAT by OpenOLAT.

the class QTIStatisticsManagerImpl method getStatisticPerItem.

@Override
public List<StatisticItem> getStatisticPerItem(List<Item> items, QTIStatisticSearchParams searchParams, double numOfParticipants) {
    StringBuilder sb = new StringBuilder();
    sb.append("select res.itemIdent, res.score, count(res.key) from qtistatsresult res ").append(" inner join res.resultSet rset");
    decorateRSet(sb, searchParams);
    sb.append(" group by res.itemIdent, res.score");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
    decorateRSetQuery(query, searchParams);
    List<Object[]> results = query.getResultList();
    Map<String, StatisticItemHelper> itemToHelpers = new HashMap<>();
    for (Object[] result : results) {
        String itemIdent = (String) result[0];
        Float score = (Float) result[1];
        Long count = (Long) result[2];
        if (count == null || score == null || itemIdent == null)
            continue;
        StatisticItemHelper helper = itemToHelpers.get(itemIdent);
        if (helper == null) {
            helper = new StatisticItemHelper();
            itemToHelpers.put(itemIdent, helper);
        }
        helper.count += count.longValue();
        helper.totalScore += (count.longValue() * score.doubleValue());
        for (Item item : items) {
            if (item.getIdent().equals(itemIdent)) {
                double maxValue = item.getQuestion().getMaxValue();
                if (Math.abs(score.doubleValue() - maxValue) < 0.0001) {
                    helper.countCorrectAnswers += count.longValue();
                }
            }
        }
    }
    List<StatisticItem> averages = new ArrayList<>();
    for (Item item : items) {
        StatisticItemHelper helper = itemToHelpers.get(item.getIdent());
        if (helper == null) {
            averages.add(new StatisticItem(item, -1.0, -1.0, -1, -1));
        } else {
            long numOfAnswersItem = helper.count;
            long numOfCorrectAnswers = helper.countCorrectAnswers;
            double average = (helper.totalScore / helper.count);
            double averageParticipants = (helper.totalScore / numOfParticipants);
            averages.add(new StatisticItem(item, average, averageParticipants, numOfAnswersItem, numOfCorrectAnswers));
        }
    }
    return averages;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatisticSurveyItem(org.olat.ims.qti.statistics.model.StatisticSurveyItem) StatisticsItem(org.olat.ims.qti.statistics.model.StatisticsItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) StatisticItem(org.olat.ims.qti.statistics.model.StatisticItem) StatisticItem(org.olat.ims.qti.statistics.model.StatisticItem)

Example 2 with StatisticItem

use of org.olat.ims.qti.statistics.model.StatisticItem in project OpenOLAT by OpenOLAT.

the class QTI12AssessmentStatisticsController method initScoreStatisticPerItem.

private void initScoreStatisticPerItem(List<Item> items, double numOfParticipants) {
    BarSeries d1 = new BarSeries();
    BarSeries d2 = new BarSeries();
    List<StatisticItem> statisticItems = qtiStatisticsManager.getStatisticPerItem(items, resourceResult.getSearchParams(), numOfParticipants);
    int i = 0;
    List<ItemInfos> itemInfos = new ArrayList<>(items.size());
    for (StatisticItem statisticItem : statisticItems) {
        Item item = statisticItem.getItem();
        String label = Integer.toString(++i);
        String text = item.getTitle();
        d1.add(statisticItem.getAverageScore(), label);
        double numOfRightAnswers = statisticItem.getNumOfCorrectAnswers();
        double res = numOfRightAnswers;
        d2.add(res, 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 : StatisticSurveyItem(org.olat.ims.qti.statistics.model.StatisticSurveyItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) StatisticItem(org.olat.ims.qti.statistics.model.StatisticItem) StatisticItem(org.olat.ims.qti.statistics.model.StatisticItem) Stringuified(org.olat.core.gui.components.chart.BarSeries.Stringuified) ArrayList(java.util.ArrayList) BarSeries(org.olat.core.gui.components.chart.BarSeries) StatisticFormatter.getModeString(org.olat.ims.qti.statistics.ui.StatisticFormatter.getModeString) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 3 with StatisticItem

use of org.olat.ims.qti.statistics.model.StatisticItem in project openolat by klemens.

the class QTIStatisticsManagerImpl method getStatisticPerItem.

@Override
public List<StatisticItem> getStatisticPerItem(List<Item> items, QTIStatisticSearchParams searchParams, double numOfParticipants) {
    StringBuilder sb = new StringBuilder();
    sb.append("select res.itemIdent, res.score, count(res.key) from qtistatsresult res ").append(" inner join res.resultSet rset");
    decorateRSet(sb, searchParams);
    sb.append(" group by res.itemIdent, res.score");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
    decorateRSetQuery(query, searchParams);
    List<Object[]> results = query.getResultList();
    Map<String, StatisticItemHelper> itemToHelpers = new HashMap<>();
    for (Object[] result : results) {
        String itemIdent = (String) result[0];
        Float score = (Float) result[1];
        Long count = (Long) result[2];
        if (count == null || score == null || itemIdent == null)
            continue;
        StatisticItemHelper helper = itemToHelpers.get(itemIdent);
        if (helper == null) {
            helper = new StatisticItemHelper();
            itemToHelpers.put(itemIdent, helper);
        }
        helper.count += count.longValue();
        helper.totalScore += (count.longValue() * score.doubleValue());
        for (Item item : items) {
            if (item.getIdent().equals(itemIdent)) {
                double maxValue = item.getQuestion().getMaxValue();
                if (Math.abs(score.doubleValue() - maxValue) < 0.0001) {
                    helper.countCorrectAnswers += count.longValue();
                }
            }
        }
    }
    List<StatisticItem> averages = new ArrayList<>();
    for (Item item : items) {
        StatisticItemHelper helper = itemToHelpers.get(item.getIdent());
        if (helper == null) {
            averages.add(new StatisticItem(item, -1.0, -1.0, -1, -1));
        } else {
            long numOfAnswersItem = helper.count;
            long numOfCorrectAnswers = helper.countCorrectAnswers;
            double average = (helper.totalScore / helper.count);
            double averageParticipants = (helper.totalScore / numOfParticipants);
            averages.add(new StatisticItem(item, average, averageParticipants, numOfAnswersItem, numOfCorrectAnswers));
        }
    }
    return averages;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatisticSurveyItem(org.olat.ims.qti.statistics.model.StatisticSurveyItem) StatisticsItem(org.olat.ims.qti.statistics.model.StatisticsItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) StatisticItem(org.olat.ims.qti.statistics.model.StatisticItem) StatisticItem(org.olat.ims.qti.statistics.model.StatisticItem)

Example 4 with StatisticItem

use of org.olat.ims.qti.statistics.model.StatisticItem in project openolat by klemens.

the class QTI12AssessmentStatisticsController method initScoreStatisticPerItem.

private void initScoreStatisticPerItem(List<Item> items, double numOfParticipants) {
    BarSeries d1 = new BarSeries();
    BarSeries d2 = new BarSeries();
    List<StatisticItem> statisticItems = qtiStatisticsManager.getStatisticPerItem(items, resourceResult.getSearchParams(), numOfParticipants);
    int i = 0;
    List<ItemInfos> itemInfos = new ArrayList<>(items.size());
    for (StatisticItem statisticItem : statisticItems) {
        Item item = statisticItem.getItem();
        String label = Integer.toString(++i);
        String text = item.getTitle();
        d1.add(statisticItem.getAverageScore(), label);
        double numOfRightAnswers = statisticItem.getNumOfCorrectAnswers();
        double res = numOfRightAnswers;
        d2.add(res, 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 : StatisticSurveyItem(org.olat.ims.qti.statistics.model.StatisticSurveyItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) StatisticItem(org.olat.ims.qti.statistics.model.StatisticItem) StatisticItem(org.olat.ims.qti.statistics.model.StatisticItem) Stringuified(org.olat.core.gui.components.chart.BarSeries.Stringuified) ArrayList(java.util.ArrayList) BarSeries(org.olat.core.gui.components.chart.BarSeries) StatisticFormatter.getModeString(org.olat.ims.qti.statistics.ui.StatisticFormatter.getModeString) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Aggregations

ArrayList (java.util.ArrayList)4 Item (org.olat.ims.qti.editor.beecom.objects.Item)4 StatisticItem (org.olat.ims.qti.statistics.model.StatisticItem)4 StatisticSurveyItem (org.olat.ims.qti.statistics.model.StatisticSurveyItem)4 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 StatisticsItem (org.olat.ims.qti.statistics.model.StatisticsItem)2 StatisticFormatter.getModeString (org.olat.ims.qti.statistics.ui.StatisticFormatter.getModeString)2