Search in sources :

Example 11 with FIBResponse

use of org.olat.ims.qti.editor.beecom.objects.FIBResponse 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)

Example 12 with FIBResponse

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

the class CSVToQuestionConverter method processChoice.

private void processChoice(String[] parts) {
    if (currentItem == null || parts.length < 2) {
        return;
    }
    try {
        Question question = currentItem.getItem().getQuestion();
        int type = question.getType();
        if (type == Question.TYPE_MC || type == Question.TYPE_SC) {
            float point = parseFloat(parts[0], 1.0f);
            String content = parts[1];
            ChoiceQuestion choice = (ChoiceQuestion) question;
            List<Response> choices = choice.getResponses();
            ChoiceResponse newChoice = new ChoiceResponse();
            newChoice.getContent().add(createMattext(content));
            newChoice.setCorrect(point > 0.0f);
            newChoice.setPoints(point);
            choices.add(newChoice);
        } else if (type == Question.TYPE_FIB) {
            String firstPart = parts[0].toLowerCase();
            FIBQuestion fib = (FIBQuestion) question;
            if ("text".equals(firstPart) || "texte".equals(firstPart)) {
                String text = parts[1];
                FIBResponse response = new FIBResponse();
                response.setType(FIBResponse.TYPE_CONTENT);
                Material mat = createMaterialWithText(text);
                response.setContent(mat);
                fib.getResponses().add(response);
            } else {
                float point = parseFloat(parts[0], 1.0f);
                String correctBlank = parts[1];
                FIBResponse response = new FIBResponse();
                response.setType(FIBResponse.TYPE_BLANK);
                response.setCorrectBlank(correctBlank);
                response.setPoints(point);
                if (parts.length > 2) {
                    String sizes = parts[2];
                    String[] sizeArr = sizes.split(",");
                    if (sizeArr.length >= 2) {
                        int size = Integer.parseInt(sizeArr[0]);
                        int maxLength = Integer.parseInt(sizeArr[1]);
                        response.setSize(size);
                        response.setMaxLength(maxLength);
                    }
                }
                fib.getResponses().add(response);
            }
        }
    } catch (NumberFormatException e) {
        log.warn("Cannot parse point for: " + parts[0] + " / " + parts[1], e);
    }
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Example 13 with FIBResponse

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

the class QTI12ItemStatisticsController method getQuestion.

private String getQuestion() {
    String question;
    if (item.getQuestion().getType() == Question.TYPE_FIB) {
        StringBuilder questionSb = new StringBuilder();
        List<Response> elements = item.getQuestion().getResponses();
        if (elements != null) {
            for (Response element : elements) {
                if (element instanceof FIBResponse) {
                    FIBResponse response = (FIBResponse) element;
                    if (FIBResponse.TYPE_CONTENT.equals(response.getType())) {
                        String content = response.getContent().renderAsHtml(mediaBaseURL);
                        questionSb.append(content);
                    } else if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
                        questionSb.append(" ___________________ ");
                    }
                }
            }
        }
        question = questionSb.toString();
    } else {
        question = item.getQuestion().getQuestion().renderAsHtml(mediaBaseURL);
    }
    return question;
}
Also used : 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)

Example 14 with FIBResponse

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

the class QTIEditHelper method createFIBItem.

/**
 * Creates a new FIB item
 * @param trans
 * @return New fib item.
 */
public static Item createFIBItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_FIB + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // conrols
    Control control = new Control();
    List<Control> controls = new ArrayList<Control>();
    controls.add(control);
    newItem.setItemcontrols(controls);
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");
    FIBQuestion fibquestion = new FIBQuestion();
    fibquestion.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    fibquestion.setSingleCorrect(true);
    fibquestion.setSingleCorrectScore(1);
    FIBResponse response = new FIBResponse();
    response.setType(FIBResponse.TYPE_CONTENT);
    Material mat = new Material();
    mat.add(new Mattext(trans.translate("editor.newtextelement")));
    response.setContent(mat);
    fibquestion.getResponses().add(response);
    newItem.setQuestion(fibquestion);
    return newItem;
}
Also used : FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Control(org.olat.ims.qti.editor.beecom.objects.Control) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) ArrayList(java.util.ArrayList) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Example 15 with FIBResponse

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

the class FIBItemController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source == main) {
        // olat::: as: improve easy fix since almost all operations change the main vc.
        main.setDirty(true);
        String cmd = event.getCommand();
        String sPosid = ureq.getParameter("posid");
        int posid = 0;
        if (sPosid != null)
            posid = Integer.parseInt(sPosid);
        if (cmd.equals("up")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid > 0 && posid < item.getQuestion().getResponses().size()) {
                Response obj = elements.remove(posid);
                elements.add(posid - 1, obj);
            } else {
                logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
            }
        } else if (cmd.equals("down")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid >= 0 && posid < elements.size() - 1) {
                Response obj = elements.remove(posid);
                elements.add(posid + 1, obj);
            } else {
                logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
            }
        } else if (cmd.equals("editq")) {
            editQuestion = item.getQuestion().getQuestion();
            displayMaterialFormController(ureq, editQuestion, restrictedEdit);
        } else if (cmd.equals("editr")) {
            List<Response> elements = item.getQuestion().getResponses();
            if (posid >= 0 && posid < elements.size()) {
                editResponse = elements.get(posid);
                Material responseMat = elements.get(posid).getContent();
                displayMaterialFormController(ureq, responseMat, restrictedEdit);
            } else {
                logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
            }
        } else if (cmd.equals("addtext")) {
            FIBQuestion fib = (FIBQuestion) item.getQuestion();
            FIBResponse response = new FIBResponse();
            response.setType(FIBResponse.TYPE_CONTENT);
            Material mat = new Material();
            mat.add(new Mattext(translate("newtextelement")));
            response.setContent(mat);
            fib.getResponses().add(response);
        } else if (cmd.equals("addblank")) {
            FIBQuestion fib = (FIBQuestion) item.getQuestion();
            FIBResponse response = new FIBResponse();
            response.setType(FIBResponse.TYPE_BLANK);
            response.setCorrectBlank("");
            // default value
            response.setPoints(1f);
            fib.getResponses().add(response);
        } else if (cmd.equals("del")) {
            delYesNoCtrl = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), null, translate("confirm.delete.element"));
            listenTo(delYesNoCtrl);
            delYesNoCtrl.setUserObject(new Integer(posid));
            delYesNoCtrl.activate();
        } else if (cmd.equals("sfib")) {
            // submit fib
            FIBQuestion question = (FIBQuestion) item.getQuestion();
            // Survey specific variables
            if (surveyMode) {
                List<Response> responses = question.getResponses();
                for (int i = 0; i < responses.size(); i++) {
                    FIBResponse response = (FIBResponse) responses.get(i);
                    if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
                        // Set size of input field
                        String size = ureq.getParameter("size_q" + i);
                        if (size != null)
                            response.setSizeFromString(size);
                        String maxLength = ureq.getParameter("maxl_q" + i);
                        if (maxLength != null)
                            response.setMaxLengthFromString(maxLength);
                    }
                }
            } else {
                // set min/max values before single_correct !!
                if (!restrictedEdit) {
                    // only in full edit mode the following fields are available:
                    // min_value, max_value, valuation_method
                    question.setMinValue(ureq.getParameter("min_value"));
                    question.setMaxValue(ureq.getParameter("max_value"));
                    question.setSingleCorrect("single".equals(ureq.getParameter("valuation_method")));
                    if (question.isSingleCorrect()) {
                        question.setSingleCorrectScore(ureq.getParameter("single_score"));
                    } else {
                        question.setSingleCorrectScore(0.0f);
                    }
                }
                NodeBeforeChangeEvent nce = new NodeBeforeChangeEvent();
                nce.setItemIdent(item.getIdent());
                List<Response> responses = question.getResponses();
                for (int i = 0; i < responses.size(); i++) {
                    FIBResponse response = (FIBResponse) responses.get(i);
                    nce.setResponseIdent(response.getIdent());
                    fireEvent(ureq, nce);
                    response.setPoints(ureq.getParameter("points_q" + i));
                    if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
                        response.setCorrectBlank(ureq.getParameter("content_q" + i));
                        // Set case sensitiveness
                        String caseSensitive = ureq.getParameter("case_q" + i);
                        if (caseSensitive == null)
                            caseSensitive = "No";
                        response.setCaseSensitive(caseSensitive);
                        // Set size of input field
                        String size = ureq.getParameter("size_q" + i);
                        if (size != null)
                            response.setSizeFromString(size);
                        String maxLength = ureq.getParameter("maxl_q" + i);
                        if (maxLength != null)
                            response.setMaxLengthFromString(maxLength);
                        // find longest correct blank in all synonyms of
                        // correct answers, fix max lenght if a longer value
                        // is found
                        String[] allCorrect = response.getCorrectBlank().split(";");
                        int longestCorrect = 0;
                        for (int j = 0; j < allCorrect.length; j++) {
                            String singleCorrect = allCorrect[j];
                            if (singleCorrect.length() > longestCorrect) {
                                longestCorrect = singleCorrect.length();
                            }
                        }
                        if (longestCorrect > response.getMaxLength())
                            response.setMaxLength(longestCorrect);
                    }
                }
            }
        }
        qtiPackage.serializeQTIDocument();
    }
}
Also used : 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) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) List(java.util.List) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

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