Search in sources :

Example 21 with FIBResponse

use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project openolat by klemens.

the class QTIWordExport method renderItem.

public static void renderItem(Item item, OpenXMLDocument document, boolean withResponses, Translator translator) {
    Element el = DocumentFactory.getInstance().createElement("dummy");
    item.addToElement(el);
    Element itemEl = (Element) el.elements().get(0);
    org.olat.ims.qti.container.qtielements.Item foo = new org.olat.ims.qti.container.qtielements.Item(itemEl);
    RenderInstructions renderInstructions = new RenderInstructions();
    renderInstructions.put(RenderInstructions.KEY_STATICS_PATH, "/");
    renderInstructions.put(RenderInstructions.KEY_LOCALE, translator.getLocale());
    renderInstructions.put(RenderInstructions.KEY_RENDER_TITLE, Boolean.TRUE);
    if (item.getQuestion() != null) {
        Map<String, String> iinput = new HashMap<String, String>();
        String questionType = null;
        String questionScore = null;
        Question question = item.getQuestion();
        if (question instanceof ChoiceQuestion) {
            ChoiceQuestion choice = (ChoiceQuestion) question;
            if (question.getType() == Question.TYPE_SC) {
                questionType = translator.translate("item.type.sc");
                fetchPointsOfMultipleChoices(itemEl, choice, iinput);
            } else if (question.getType() == Question.TYPE_MC) {
                questionType = translator.translate("item.type.mc");
                fetchPointsOfMultipleChoices(itemEl, choice, iinput);
            } else if (question.getType() == Question.TYPE_KPRIM) {
                questionType = translator.translate("item.type.kprim");
                fetchPointsOfKPrim(itemEl, choice, iinput);
            }
        } else if (question instanceof FIBQuestion) {
            questionType = translator.translate("item.type.sc");
            for (Response response : question.getResponses()) {
                FIBResponse fibResponse = (FIBResponse) response;
                if ("BLANK".equals(fibResponse.getType())) {
                    iinput.put(fibResponse.getIdent(), fibResponse.getCorrectBlank());
                }
            }
        } else if (question instanceof EssayQuestion) {
            questionType = translator.translate("item.type.essay");
        }
        if (question != null && question.getMaxValue() > 0.0f) {
            questionScore = AssessmentHelper.getRoundedScore(question.getMaxValue());
            questionScore = translator.translate("item.score.long", new String[] { questionScore });
        }
        renderInstructions.put(RenderInstructions.KEY_RENDER_CORRECT_RESPONSES, new Boolean(withResponses));
        renderInstructions.put(RenderInstructions.KEY_CORRECT_RESPONSES_MAP, iinput);
        renderInstructions.put(RenderInstructions.KEY_QUESTION_TYPE, questionType);
        renderInstructions.put(RenderInstructions.KEY_QUESTION_SCORE, questionScore);
        renderInstructions.put(RenderInstructions.KEY_QUESTION_OO_TYPE, new Integer(question.getType()));
    }
    foo.renderOpenXML(document, renderInstructions);
}
Also used : EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) HashMap(java.util.HashMap) Element(org.dom4j.Element) RenderInstructions(org.olat.ims.qti.container.qtielements.RenderInstructions) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Item(org.olat.ims.qti.editor.beecom.objects.Item) EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Example 22 with FIBResponse

use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project openolat by klemens.

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

FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)22 Response (org.olat.ims.qti.editor.beecom.objects.Response)20 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)12 Material (org.olat.ims.qti.editor.beecom.objects.Material)10 Question (org.olat.ims.qti.editor.beecom.objects.Question)10 ArrayList (java.util.ArrayList)8 Item (org.olat.ims.qti.editor.beecom.objects.Item)8 HashMap (java.util.HashMap)6 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)6 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)6 File (java.io.File)4 URL (java.net.URL)4 List (java.util.List)4 Test (org.junit.Test)4 WindowControl (org.olat.core.gui.control.WindowControl)4 Translator (org.olat.core.gui.translator.Translator)4 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)4 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)4 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)4