Search in sources :

Example 1 with StatisticSurveyItemResponse

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

the class QTIStatisticsManagerImpl method getStatisticAnswerOptions.

@Override
public List<StatisticSurveyItem> getStatisticAnswerOptions(QTIStatisticSearchParams searchParams, List<Item> items) {
    StringBuilder sb = new StringBuilder();
    sb.append("select res.itemIdent, res.answer, count(res.key) from qtistatsresult res ").append(" inner join res.resultSet rset");
    decorateRSet(sb, searchParams).append(" and res.duration > 0").append(" group by res.itemIdent, res.answer").append(" order by res.itemIdent");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
    decorateRSetQuery(query, searchParams);
    List<Object[]> results = query.getResultList();
    if (results.isEmpty()) {
        return Collections.emptyList();
    }
    Map<String, Item> identToItemMap = new HashMap<>();
    for (Item item : items) {
        identToItemMap.put(item.getIdent(), item);
    }
    StatisticSurveyItem currentItem = null;
    Map<Item, StatisticSurveyItem> itemToStatisticsMap = new HashMap<>();
    for (Object[] result : results) {
        String itemIdent = (String) result[0];
        String answer = (String) result[1];
        Long numOfAnswers = (Long) result[2];
        Item item = identToItemMap.get(itemIdent);
        if (currentItem == null || !currentItem.getItem().getIdent().equals(itemIdent)) {
            currentItem = new StatisticSurveyItem(item);
            itemToStatisticsMap.put(item, currentItem);
        }
        Response response = findResponses(item, answer);
        currentItem.getResponses().add(new StatisticSurveyItemResponse(response, answer, numOfAnswers));
    }
    List<StatisticSurveyItem> reorderList = new ArrayList<>();
    for (Item item : items) {
        StatisticSurveyItem statsItem = itemToStatisticsMap.get(item);
        if (statsItem != null) {
            reorderList.add(statsItem);
        }
    }
    return reorderList;
}
Also used : StatisticSurveyItem(org.olat.ims.qti.statistics.model.StatisticSurveyItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatisticSurveyItemResponse(org.olat.ims.qti.statistics.model.StatisticSurveyItemResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) 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) StatisticSurveyItemResponse(org.olat.ims.qti.statistics.model.StatisticSurveyItemResponse)

Example 2 with StatisticSurveyItemResponse

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

the class QTIStatisticsManagerImpl method getStatisticAnswerOptions.

@Override
public List<StatisticSurveyItem> getStatisticAnswerOptions(QTIStatisticSearchParams searchParams, List<Item> items) {
    StringBuilder sb = new StringBuilder();
    sb.append("select res.itemIdent, res.answer, count(res.key) from qtistatsresult res ").append(" inner join res.resultSet rset");
    decorateRSet(sb, searchParams).append(" and res.duration > 0").append(" group by res.itemIdent, res.answer").append(" order by res.itemIdent");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
    decorateRSetQuery(query, searchParams);
    List<Object[]> results = query.getResultList();
    if (results.isEmpty()) {
        return Collections.emptyList();
    }
    Map<String, Item> identToItemMap = new HashMap<>();
    for (Item item : items) {
        identToItemMap.put(item.getIdent(), item);
    }
    StatisticSurveyItem currentItem = null;
    Map<Item, StatisticSurveyItem> itemToStatisticsMap = new HashMap<>();
    for (Object[] result : results) {
        String itemIdent = (String) result[0];
        String answer = (String) result[1];
        Long numOfAnswers = (Long) result[2];
        Item item = identToItemMap.get(itemIdent);
        if (currentItem == null || !currentItem.getItem().getIdent().equals(itemIdent)) {
            currentItem = new StatisticSurveyItem(item);
            itemToStatisticsMap.put(item, currentItem);
        }
        Response response = findResponses(item, answer);
        currentItem.getResponses().add(new StatisticSurveyItemResponse(response, answer, numOfAnswers));
    }
    List<StatisticSurveyItem> reorderList = new ArrayList<>();
    for (Item item : items) {
        StatisticSurveyItem statsItem = itemToStatisticsMap.get(item);
        if (statsItem != null) {
            reorderList.add(statsItem);
        }
    }
    return reorderList;
}
Also used : StatisticSurveyItem(org.olat.ims.qti.statistics.model.StatisticSurveyItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatisticSurveyItemResponse(org.olat.ims.qti.statistics.model.StatisticSurveyItemResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) 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) StatisticSurveyItemResponse(org.olat.ims.qti.statistics.model.StatisticSurveyItemResponse)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)2 Item (org.olat.ims.qti.editor.beecom.objects.Item)2 Response (org.olat.ims.qti.editor.beecom.objects.Response)2 StatisticItem (org.olat.ims.qti.statistics.model.StatisticItem)2 StatisticSurveyItem (org.olat.ims.qti.statistics.model.StatisticSurveyItem)2 StatisticSurveyItemResponse (org.olat.ims.qti.statistics.model.StatisticSurveyItemResponse)2 StatisticsItem (org.olat.ims.qti.statistics.model.StatisticsItem)2