Search in sources :

Example 31 with Response

use of org.olat.ims.qti.editor.beecom.objects.Response 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 32 with Response

use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.

the class QTIStatisticsManagerImpl method getNumOfRightAnsweredMultipleChoice.

/**
 * calculates the percentage of participants that answered a answer option
 * correctly.<br>
 * Number at index 0 = answer option 1, Number at index 1 = answer option 2,
 * etc.
 *
 * @param item
 * @param numberOfParticipants
 * @param olatResource
 * @param olatResourceDetail
 * @return
 */
@Override
public List<StatisticChoiceOption> getNumOfRightAnsweredMultipleChoice(Item item, QTIStatisticSearchParams searchParams) {
    List<StatisticAnswerOption> answerToNumberList = getStatisticAnswerOptionsOfItem(item.getIdent(), searchParams);
    List<Response> responses = item.getQuestion().getResponses();
    List<StatisticChoiceOption> percentageRightAnswered = new ArrayList<StatisticChoiceOption>();
    for (Response response : responses) {
        String answerIdent = response.getIdent();
        long num = 0;
        for (StatisticAnswerOption answerToNumber : answerToNumberList) {
            String answer = answerToNumber.getAnswer();
            if (answer.indexOf(answerIdent) >= 0) {
                num += answerToNumber.getCount();
            }
        }
        percentageRightAnswered.add(new StatisticChoiceOption(response, num));
    }
    return percentageRightAnswered;
}
Also used : 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) StatisticAnswerOption(org.olat.ims.qti.statistics.model.StatisticAnswerOption) StatisticChoiceOption(org.olat.ims.qti.statistics.model.StatisticChoiceOption) ArrayList(java.util.ArrayList)

Example 33 with Response

use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.

the class QTIStatisticsManagerImpl method getNumOfAnswersPerSingleChoiceAnswerOption.

/**
 * calculates how many participants selected answer option 1 and/or option 2
 * and/or option 3...
 *
 * @param aQuestion
 * @param olatResource
 * @param olatResourceDetail
 * @return
 */
@Override
public List<StatisticChoiceOption> getNumOfAnswersPerSingleChoiceAnswerOption(Item item, QTIStatisticSearchParams searchParams) {
    List<StatisticAnswerOption> answerToNumberList = getStatisticAnswerOptionsOfItem(item.getIdent(), searchParams);
    List<Response> answerOptions = item.getQuestion().getResponses();
    List<StatisticChoiceOption> numOfAnswersPerOption = new ArrayList<>();
    for (int i = 0; i < answerOptions.size(); i++) {
        Response response = answerOptions.get(i);
        String responseIdent = response.getIdent();
        long num = 0;
        for (StatisticAnswerOption answerToNumber : answerToNumberList) {
            String answer = answerToNumber.getAnswer();
            if (answer.indexOf(responseIdent) >= 0) {
                num += answerToNumber.getCount();
            }
        }
        numOfAnswersPerOption.add(new StatisticChoiceOption(response, num));
    }
    return numOfAnswersPerOption;
}
Also used : 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) StatisticAnswerOption(org.olat.ims.qti.statistics.model.StatisticAnswerOption) StatisticChoiceOption(org.olat.ims.qti.statistics.model.StatisticChoiceOption) ArrayList(java.util.ArrayList)

Example 34 with Response

use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.

the class QTIStatisticsManagerImpl method getNumbersInKPrim.

@Override
public List<StatisticKPrimOption> getNumbersInKPrim(Item item, QTIStatisticSearchParams searchParams) {
    List<StatisticAnswerOption> rawDatas = getStatisticAnswerOptionsOfItem(item.getIdent(), searchParams);
    List<Response> responses = item.getQuestion().getResponses();
    List<StatisticKPrimOption> kprimPoints = new ArrayList<>();
    for (Response response : responses) {
        String answerIdent = response.getIdent();
        boolean isCorrect = response.isCorrect();
        String rightFlag = answerIdent + ":" + (isCorrect ? "correct" : "wrong");
        String wrongFlag = answerIdent + ":" + (isCorrect ? "wrong" : "correct");
        long numCorrect = 0;
        long numIncorrect = 0;
        long numUnanswered = 0;
        for (StatisticAnswerOption rawData : rawDatas) {
            String answer = rawData.getAnswer();
            if (answer.indexOf(rightFlag) >= 0) {
                numCorrect += rawData.getCount();
            } else if (answer.indexOf(wrongFlag) >= 0) {
                numIncorrect += rawData.getCount();
            } else {
                numUnanswered += rawData.getCount();
            }
        }
        kprimPoints.add(new StatisticKPrimOption(response, numCorrect, numIncorrect, numUnanswered));
    }
    return kprimPoints;
}
Also used : 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) StatisticAnswerOption(org.olat.ims.qti.statistics.model.StatisticAnswerOption) StatisticKPrimOption(org.olat.ims.qti.statistics.model.StatisticKPrimOption) ArrayList(java.util.ArrayList)

Example 35 with Response

use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.

the class QTIStatisticsManagerImpl method getStatisticAnswerOptionsFIB.

@Override
public List<StatisticFIBOption> getStatisticAnswerOptionsFIB(Item item, QTIStatisticSearchParams searchParams) {
    List<StatisticFIBOption> options = new ArrayList<>();
    Map<String, StatisticFIBOption> optionMap = new HashMap<>();
    boolean groupBy = true;
    List<Response> responses = item.getQuestion().getResponses();
    for (Response response : responses) {
        if (response instanceof FIBResponse) {
            FIBResponse fibResponse = (FIBResponse) response;
            if (FIBResponse.TYPE_BLANK.equals(fibResponse.getType())) {
                String ident = fibResponse.getIdent();
                String[] correctFIBs = fibResponse.getCorrectBlank().split(";");
                if (correctFIBs == null || correctFIBs.length == 0) {
                    continue;
                }
                StatisticFIBOption option = new StatisticFIBOption();
                option.setCorrectBlank(correctFIBs[0]);
                option.setAlternatives(Arrays.asList(correctFIBs));
                boolean caseSensitive = "Yes".equals(fibResponse.getCaseSensitive());
                groupBy &= !caseSensitive;
                option.setCaseSensitive(caseSensitive);
                option.setPoints(fibResponse.getPoints());
                options.add(option);
                optionMap.put(ident, option);
            }
        }
    }
    List<StatisticAnswerOption> answerOptions = getStatisticAnswerOptionsOfItem(item.getIdent(), searchParams, groupBy);
    for (StatisticAnswerOption answerOption : answerOptions) {
        long count = answerOption.getCount();
        String concatenedAnswer = answerOption.getAnswer();
        Map<String, String> parsedAnswerMap = QTIResultManager.parseResponseStrAnswers(concatenedAnswer);
        for (Map.Entry<String, String> parsedAnswerEntry : parsedAnswerMap.entrySet()) {
            String ident = parsedAnswerEntry.getKey();
            StatisticFIBOption option = optionMap.get(ident);
            if (option == null) {
                continue;
            }
            String text = parsedAnswerEntry.getValue();
            boolean correct;
            if (option.isCaseSensitive()) {
                correct = option.getAlternatives().contains(text);
            } else {
                correct = false;
                for (String alt : option.getAlternatives()) {
                    if (alt.equalsIgnoreCase(text)) {
                        correct = true;
                    }
                }
            }
            if (correct) {
                option.setNumOfCorrect(option.getNumOfCorrect() + count);
            } else {
                option.setNumOfIncorrect(option.getNumOfIncorrect() + count);
                option.getWrongAnswers().add(text);
            }
        }
    }
    return options;
}
Also used : 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) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) StatisticAnswerOption(org.olat.ims.qti.statistics.model.StatisticAnswerOption) StatisticFIBOption(org.olat.ims.qti.statistics.model.StatisticFIBOption) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Response (org.olat.ims.qti.editor.beecom.objects.Response)60 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)44 ArrayList (java.util.ArrayList)32 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)26 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)22 Question (org.olat.ims.qti.editor.beecom.objects.Question)22 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)20 Material (org.olat.ims.qti.editor.beecom.objects.Material)20 HashMap (java.util.HashMap)14 Item (org.olat.ims.qti.editor.beecom.objects.Item)14 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)12 List (java.util.List)10 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)10 StatisticSurveyItemResponse (org.olat.ims.qti.statistics.model.StatisticSurveyItemResponse)10 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)8 StatisticAnswerOption (org.olat.ims.qti.statistics.model.StatisticAnswerOption)8 StatisticChoiceOption (org.olat.ims.qti.statistics.model.StatisticChoiceOption)8 File (java.io.File)6 URL (java.net.URL)6 Test (org.junit.Test)6