Search in sources :

Example 1 with Response

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

the class SeriesFactory method getKPrim.

public Series getKPrim(Item item) {
    List<StatisticKPrimOption> statisticResponses = qtiStatisticsManager.getNumbersInKPrim(item, resourceResult.getSearchParams());
    String mediaBaseURL = resourceResult.getMediaBaseURL();
    boolean survey = QTIType.survey.equals(resourceResult.getType());
    int numOfParticipants = resourceResult.getQTIStatisticAssessment().getNumOfParticipants();
    int i = 0;
    BarSeries d1 = new BarSeries("bar_green", "green", translate("answer.correct"));
    BarSeries d2 = new BarSeries("bar_red", "red", translate("answer.false"));
    BarSeries d3 = new BarSeries("bar_grey", "grey", translate("answer.noanswer"));
    List<ResponseInfos> responseInfos = new ArrayList<>();
    for (StatisticKPrimOption statisticResponse : statisticResponses) {
        Response response = statisticResponse.getResponse();
        boolean correct = response.isCorrect();
        double right = statisticResponse.getNumOfCorrect();
        double wrong = statisticResponse.getNumOfIncorrect();
        double notanswered = numOfParticipants - right - wrong;
        String label = Integer.toString(++i);
        d1.add(right, label);
        d2.add(wrong, label);
        d3.add(notanswered, label);
        String text = response.getContent().renderAsHtml(mediaBaseURL);
        responseInfos.add(new ResponseInfos(label, text, null, correct, survey, true));
    }
    List<BarSeries> serieList = new ArrayList<>(3);
    serieList.add(d1);
    serieList.add(d2);
    serieList.add(d3);
    Series series = new Series(serieList, responseInfos, numOfParticipants, !survey);
    series.setChartType(survey ? BAR_ANSWERED : BAR_CORRECT_WRONG_NOT);
    series.setItemCss(getCssClass(item));
    return series;
}
Also used : ArrayList(java.util.ArrayList) BarSeries(org.olat.core.gui.components.chart.BarSeries) Response(org.olat.ims.qti.editor.beecom.objects.Response) BarSeries(org.olat.core.gui.components.chart.BarSeries) StatisticKPrimOption(org.olat.ims.qti.statistics.model.StatisticKPrimOption)

Example 2 with Response

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

the class SeriesFactory method getSingleChoice.

public Series getSingleChoice(Item item) {
    List<StatisticChoiceOption> statisticResponses = qtiStatisticsManager.getNumOfAnswersPerSingleChoiceAnswerOption(item, resourceResult.getSearchParams());
    String mediaBaseURL = resourceResult.getMediaBaseURL();
    boolean survey = QTIType.survey.equals(resourceResult.getType());
    int numOfParticipants = resourceResult.getQTIStatisticAssessment().getNumOfParticipants();
    int i = 0;
    long numOfResults = 0;
    BarSeries d1 = new BarSeries();
    List<ResponseInfos> responseInfos = new ArrayList<>();
    for (StatisticChoiceOption statisticResponse : statisticResponses) {
        Response response = statisticResponse.getResponse();
        double ans_count = statisticResponse.getCount();
        numOfResults += statisticResponse.getCount();
        Float points;
        String cssColor;
        if (survey) {
            points = null;
            cssColor = "bar_default";
        } else {
            points = response.getPoints();
            cssColor = response.isCorrect() ? "bar_green" : "bar_red";
        }
        String label = Integer.toString(++i);
        d1.add(ans_count, label, cssColor);
        String text = response.getContent().renderAsHtml(mediaBaseURL);
        responseInfos.add(new ResponseInfos(label, text, points, response.isCorrect(), survey, false));
    }
    if (numOfResults != numOfParticipants) {
        long notAnswered = numOfParticipants - numOfResults;
        if (notAnswered > 0) {
            String label = Integer.toString(++i);
            String text = translate("user.not.answer");
            responseInfos.add(new ResponseInfos(label, text, null, false, survey, false));
            d1.add(notAnswered, label, "bar_grey");
        }
    }
    List<BarSeries> serieList = Collections.singletonList(d1);
    Series series = new Series(serieList, responseInfos, numOfParticipants, false);
    series.setChartType(BAR_CORRECT);
    series.setItemCss(getCssClass(item));
    return series;
}
Also used : StatisticChoiceOption(org.olat.ims.qti.statistics.model.StatisticChoiceOption) ArrayList(java.util.ArrayList) BarSeries(org.olat.core.gui.components.chart.BarSeries) Response(org.olat.ims.qti.editor.beecom.objects.Response) BarSeries(org.olat.core.gui.components.chart.BarSeries)

Example 3 with Response

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

the class QTI12MetadataController method setKPrimCorrectResponses.

private void setKPrimCorrectResponses(List<Response> responses, FormLayoutContainer layoutCont) {
    List<ResponseAndPoints> responsesPoints = new ArrayList<>();
    if (responses != null && responses.size() > 0) {
        for (Response response : responses) {
            String responseSummary = getResponseSummary(response);
            if (responseSummary != null) {
                boolean correct = response.isCorrect();
                String points = Float.toString(response.getPoints());
                ResponseAndPoints responseInfos = new ResponseAndPoints(Formatter.formatLatexFormulas(responseSummary), points, correct);
                responsesPoints.add(responseInfos);
            }
        }
    }
    layoutCont.contextPut("kprimResponsesAndPoints", responsesPoints);
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) ArrayList(java.util.ArrayList)

Example 4 with Response

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

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 5 with Response

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

the class ItemNode method createChangeMessage.

public String createChangeMessage(Memento mem) {
    String retVal = null;
    if (mem instanceof QtiNodeMemento) {
        QtiNodeMemento qnm = (QtiNodeMemento) mem;
        Map<String, Object> qtiState = qnm.getQtiState();
        // 
        String oldTitle = (String) qtiState.get("TITLE");
        String newTitle = item.getTitle();
        String titleChange = null;
        // 
        String oldObjectives = (String) qtiState.get("OBJECTIVES");
        String newObjectives = item.getObjectives();
        String objectChange = null;
        // 
        Question question = item.getQuestion();
        boolean isFIB = question.getType() == Question.TYPE_FIB;
        boolean isESSAY = question.getType() == Question.TYPE_ESSAY;
        String oldHinttext = (String) qtiState.get("QUESTION.HINTTEXT");
        String newHinttext = question.getHintText();
        String hinttextChange = null;
        // 
        String oldQuestion = (String) qtiState.get("QUESTION.MATERIAL.ASTEXT");
        String newQuestion = question.getQuestion().renderAsText();
        String questionChange = null;
        // feedback
        String feedbackChanges = "";
        String oldFeedbackMastery = (String) qtiState.get("FEEDBACK.MASTERY");
        String newFeedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
        String oldFeedbackFail = (String) qtiState.get("FEEDBACK.FAIL");
        String newFeedbackFail = QTIEditHelper.getFeedbackFailText(item);
        Control control = QTIEditHelper.getControl(item);
        Boolean oldHasFeedback = (Boolean) qtiState.get("FEEDBACK.ENABLED");
        Boolean newHasFeedback = control != null ? new Boolean(control.getFeedback() == 1) : null;
        // 
        List asTexts = (List) qtiState.get("QUESTION.RESPONSES.ASTEXT");
        List feedbacks = (List) qtiState.get("QUESTION.RESPONSES.FEEDBACK");
        String oldResp = null;
        String newResp = null;
        String oldFeedback = null;
        String newFeedback = null;
        String responsesChanges = "";
        List<Response> responses = question.getResponses();
        int i = 0;
        boolean nothingToDo = false;
        for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
            nothingToDo = false;
            Response resp = iter.next();
            if (isFIB) {
                if (FIBResponse.TYPE_BLANK.equals(((FIBResponse) resp).getType())) {
                    newResp = formatFIBResponseAsText((FIBResponse) resp);
                } else {
                    // skip
                    nothingToDo = true;
                }
            } else if (isESSAY) {
                newResp = formatESSAYResponseAsText((EssayResponse) resp);
            } else {
                newResp = resp.getContent().renderAsText();
            }
            // if NOT nothingToDO
            if (!nothingToDo) {
                oldResp = (String) asTexts.get(i);
                if ((oldResp != null && !oldResp.equals(newResp)) || (newResp != null && !newResp.equals(oldResp))) {
                    if (isFIB) {
                        responsesChanges += "\nBlank changed:";
                        responsesChanges += "\nold blank: \n\t" + formatVariable(oldResp) + "\n\nnew blank: \n\t" + formatVariable(newResp);
                    } else {
                        responsesChanges += "\nResponse changed:";
                        responsesChanges += "\nold response: \n\t" + formatVariable(oldResp) + "\n\nnew response: \n\t" + formatVariable(newResp);
                    }
                }
                // feedback to response changed?
                newFeedback = QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent());
                oldFeedback = (String) feedbacks.get(i);
                if ((oldFeedback != null && !oldFeedback.equals(newFeedback)) || (newFeedback != null && !newFeedback.equals(oldFeedback))) {
                    feedbackChanges += "\nFeedback changed:";
                    feedbackChanges += "\nold feedback: \n\t" + formatVariable(oldFeedback) + "\n\nnew feedback: \n\t" + formatVariable(newFeedback);
                }
                i++;
            }
        }
        // 
        retVal = "\n---+++ Item changes [" + oldTitle + "]:";
        if ((oldTitle != null && !oldTitle.equals(newTitle)) || (newTitle != null && !newTitle.equals(oldTitle))) {
            titleChange = "\n\nold title: \n\t" + formatVariable(oldTitle) + "\n\nnew title: \n\t" + formatVariable(newTitle);
        }
        if ((oldObjectives != null && !oldObjectives.equals(newObjectives)) || (newObjectives != null && !newObjectives.equals(oldObjectives))) {
            objectChange = "\n\nold objectives: \n\t" + formatVariable(oldObjectives) + "\n\nnew objectives: \n\t" + formatVariable(newObjectives);
        }
        if (titleChange != null || objectChange != null) {
            retVal += "\nMetadata changed:";
            if (titleChange != null)
                retVal += titleChange;
            if (objectChange != null)
                retVal += objectChange;
        }
        // 
        if ((oldHinttext != null && !oldHinttext.equals(newHinttext)) || (newHinttext != null && !newHinttext.equals(oldHinttext))) {
            hinttextChange = "\n---+++ old hinttext: \n\t" + formatVariable(oldHinttext) + "\n\nnew hinttext: \n\t" + formatVariable(newHinttext);
            retVal += hinttextChange;
        }
        if ((oldQuestion != null && !oldQuestion.equals(newQuestion)) || (newQuestion != null && !newQuestion.equals(oldQuestion))) {
            questionChange = "\n---+++ old question: \n\t" + formatVariable(oldQuestion) + "\n\nnew question: \n\t" + formatVariable(newQuestion);
            retVal += questionChange;
        }
        if (!responsesChanges.equals("")) {
            retVal += responsesChanges;
        }
        if ((oldFeedbackMastery != null && !oldFeedbackMastery.equals(newFeedbackMastery)) || (newFeedbackMastery != null && !newFeedbackMastery.equals(oldFeedbackMastery))) {
            String tmp = "\n---+++ old master feedback: \n\t" + formatVariable(oldFeedbackMastery) + "\n\nnew master feedback: \n\t" + formatVariable(newFeedbackMastery);
            feedbackChanges = tmp + feedbackChanges;
        }
        if ((oldFeedbackFail != null && !oldFeedbackFail.equals(newFeedbackFail)) || (newFeedbackFail != null && !newFeedbackFail.equals(oldFeedbackFail))) {
            String tmp = "\n---+++ old fail feedback: \n\t" + formatVariable(oldFeedbackFail) + "\n\nnew fail feedback: \n\t" + formatVariable(newFeedbackFail);
            feedbackChanges = tmp + feedbackChanges;
        }
        if ((oldHasFeedback != null && newHasFeedback != null && oldHasFeedback != newHasFeedback)) {
            String oldF = oldHasFeedback.booleanValue() ? "enabled" : "disabled";
            String newF = newHasFeedback.booleanValue() ? "enabled" : "disabled";
            feedbackChanges = "\n---+++ feedback was : \n\t" + oldF + "\n\n feedback is now: \n\t" + newF + feedbackChanges;
        }
        if (!feedbackChanges.equals("")) {
            retVal += feedbackChanges;
        }
        return retVal;
    }
    return "undefined";
}
Also used : FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Control(org.olat.ims.qti.editor.beecom.objects.Control) WindowControl(org.olat.core.gui.control.WindowControl) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) Question(org.olat.ims.qti.editor.beecom.objects.Question) ArrayList(java.util.ArrayList) List(java.util.List)

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