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