use of org.olat.ims.qti.editor.beecom.objects.Response in project openolat by klemens.
the class ChoiceItemController 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 == null) {
// ignore null cmd
} else if (cmd.equals("up")) {
if (posid > 0) {
List<Response> elements = item.getQuestion().getResponses();
Response obj = elements.remove(posid);
elements.add(posid - 1, obj);
}
} else if (cmd.equals("down")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid < elements.size() - 1) {
Response obj = elements.remove(posid);
elements.add(posid + 1, obj);
}
} else if (cmd.equals("editq")) {
editQuestion = item.getQuestion().getQuestion();
displayMaterialFormController(ureq, editQuestion, restrictedEdit, translate("fieldset.legend.question"));
} else if (cmd.equals("editr")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid >= 0 && posid < elements.size()) {
editResponse = elements.get(posid);
Material responseMat = editResponse.getContent();
displayMaterialFormController(ureq, responseMat, restrictedEdit, translate("fieldset.legend.answers"));
}
} else if (cmd.equals("addchoice")) {
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
List<Response> choices = question.getResponses();
ChoiceResponse newChoice = new ChoiceResponse();
newChoice.getContent().add(new Mattext(translate("newresponsetext")));
newChoice.setCorrect(false);
// default value is negative to make sure
newChoice.setPoints(-1f);
// people understand the meaning of this value
choices.add(newChoice);
} 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("ssc")) {
// submit sc
if (!restrictedEdit) {
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
List<Response> q_choices = question.getResponses();
String correctChoice = ureq.getParameter("correctChoice");
for (int i = 0; i < q_choices.size(); i++) {
ChoiceResponse choice = (ChoiceResponse) q_choices.get(i);
if (correctChoice != null && correctChoice.equals("value_q" + i)) {
choice.setCorrect(true);
} else {
choice.setCorrect(false);
}
choice.setPoints(ureq.getParameter("points_q" + i));
}
String score = ureq.getParameter("single_score");
float sc;
try {
sc = Float.parseFloat(score);
if (sc <= 0.0001f) {
getWindowControl().setWarning(translate("editor.info.mc.zero.points"));
}
} catch (Exception e) {
getWindowControl().setWarning(translate("editor.info.mc.zero.points"));
sc = 1.0f;
}
question.setSingleCorrectScore(sc);
}
} else if (cmd.equals("smc")) {
// submit mc
if (!restrictedEdit) {
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
List<Response> choices = question.getResponses();
boolean hasZeroPointChoice = false;
for (int i = 0; i < choices.size(); i++) {
ChoiceResponse choice = (ChoiceResponse) choices.get(i);
if (ureq.getParameter("value_q" + i) != null && ureq.getParameter("value_q" + i).equalsIgnoreCase("true")) {
choice.setCorrect(true);
} else {
choice.setCorrect(false);
}
choice.setPoints(ureq.getParameter("points_q" + i));
if (choice.getPoints() == 0)
hasZeroPointChoice = true;
}
if (hasZeroPointChoice && !question.isSingleCorrect()) {
getWindowControl().setInfo(translate("editor.info.mc.zero.points"));
}
// set min/max before single_correct score
// will be corrected by single_correct score afterwards
question.setMinValue(ureq.getParameter("min_value"));
question.setMaxValue(ureq.getParameter("max_value"));
question.setSingleCorrect(ureq.getParameter("valuation_method").equals("single"));
if (question.isSingleCorrect()) {
question.setSingleCorrectScore(ureq.getParameter("single_score"));
} else {
question.setSingleCorrectScore(0);
}
}
} else if (cmd.equals("skprim")) {
// submit kprim
if (!restrictedEdit) {
float maxValue = 0;
try {
maxValue = Float.parseFloat(ureq.getParameter("max_value"));
} catch (NumberFormatException e) {
// invalid input, set maxValue 0
}
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
List<Response> q_choices = question.getResponses();
for (int i = 0; i < q_choices.size(); i++) {
String correctChoice = ureq.getParameter("correctChoice_q" + i);
ChoiceResponse choice = (ChoiceResponse) q_choices.get(i);
choice.setPoints(maxValue / 4);
if ("correct".equals(correctChoice)) {
choice.setCorrect(true);
} else {
choice.setCorrect(false);
}
}
question.setMaxValue(maxValue);
}
}
qtiPackage.serializeQTIDocument();
}
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project openolat by klemens.
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);
}
}
use of org.olat.ims.qti.editor.beecom.objects.Response 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);
}
use of org.olat.ims.qti.editor.beecom.objects.Response 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;
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project openolat by klemens.
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;
}
Aggregations