use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project openolat by klemens.
the class CSVToQuestionConverterTest method importMultipleChoice.
@Test
public void importMultipleChoice() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_mc.txt");
Assert.assertNotNull(importTxtUrl);
File importTxt = new File(importTxtUrl.toURI());
String input = FileUtils.readFileToString(importTxt, "UTF-8");
Translator translator = new KeyTranslator(Locale.ENGLISH);
ImportOptions options = new ImportOptions();
options.setShuffle(true);
CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
converter.parse(input);
List<ItemAndMetadata> items = converter.getItems();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
ItemAndMetadata importedItem = items.get(0);
Item item = importedItem.getItem();
Assert.assertNotNull(item);
Assert.assertEquals("Fussball: Austragungsort", item.getTitle());
Assert.assertEquals("Die Fussball WM wird alle vier Jahre von einem anderen Land ausgerichtet.", item.getObjectives());
Assert.assertEquals(Question.TYPE_MC, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof ChoiceQuestion);
Material questionMat = item.getQuestion().getQuestion();
Assert.assertNotNull(questionMat);
Assert.assertNotNull(questionMat.getElements());
Assert.assertEquals(1, questionMat.getElements().size());
QTIObject questionMatEl = questionMat.getElements().get(0);
Assert.assertTrue(questionMatEl instanceof Mattext);
String text = ((Mattext) questionMatEl).getContent();
Assert.assertEquals("In welchen L\u00E4ndern wurde zwischen dem Jahr 2000 und 2015 eine Fussball Weltmeisterschaft ausgetragen?", text);
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
Assert.assertNotNull(question.getResponses());
Assert.assertEquals(7, question.getResponses().size());
List<Response> responses = question.getResponses();
Assert.assertEquals(1.0f, responses.get(0).getPoints(), 0.0001);
Assert.assertEquals(1.0f, responses.get(1).getPoints(), 0.0001);
Assert.assertEquals(1.0f, responses.get(2).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(3).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(4).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(5).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(6).getPoints(), 0.0001);
// after it will be set to true for all of them
Assert.assertTrue(responses.get(0).isCorrect());
Assert.assertTrue(responses.get(1).isCorrect());
Assert.assertTrue(responses.get(2).isCorrect());
Assert.assertFalse(responses.get(3).isCorrect());
Assert.assertFalse(responses.get(4).isCorrect());
Assert.assertFalse(responses.get(5).isCorrect());
Assert.assertFalse(responses.get(6).isCorrect());
String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
Assert.assertEquals("Bravo! Die Antwort ich absolut korrekt.", feedbackMastery);
String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
Assert.assertEquals("Leider falsch. Probieren Sie es noch einmal.", feedbackFail);
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project openolat by klemens.
the class QTIEditHelper method createMCItem.
/**
* Creates a new Multiple Choice item.
* @param trans
* @return New Multiple Choice item.
*/
public static Item createMCItem(Translator trans) {
// create item
Item newItem = new Item();
newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_MC + ":" + 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);
// pepare question
ChoiceQuestion question = new ChoiceQuestion();
question.setLable(trans.translate("editor.newquestion"));
question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
question.setType(Question.TYPE_MC);
question.setSingleCorrect(true);
question.setSingleCorrectScore(1);
ChoiceResponse newChoice = new ChoiceResponse();
newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice.setCorrect(true);
newChoice.setPoints(1);
question.getResponses().add(newChoice);
newItem.setQuestion(question);
QTIEditHelper.setFeedbackMastery(newItem, "");
QTIEditHelper.setFeedbackFail(newItem, "");
return newItem;
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project openolat by klemens.
the class ItemMetadataFormController method initForm.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
* org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("fieldset.legend.metadata");
int t = item.getQuestion().getType();
if (!isSurvey && t == Question.TYPE_ESSAY) {
setFormWarning("warning.essay.test");
}
if (isSurvey) {
setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf_frage");
} else {
setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf_frage");
}
// Title
title = uifactory.addTextElement("title", "form.imd.title", -1, item.getTitle(), formLayout);
title.setMandatory(true);
title.setNotEmptyCheck("form.imd.error.empty.title");
// Question Type
String typeName = getType();
uifactory.addStaticTextElement("type", "form.imd.type", typeName, formLayout);
// Description
desc = uifactory.addRichTextElementForStringData("desc", "form.imd.descr", item.getObjectives(), 8, -1, true, null, null, formLayout, ureq.getUserSession(), getWindowControl());
desc.getEditorConfiguration().setFigCaption(false);
RichTextConfiguration richTextConfig = desc.getEditorConfiguration();
// set upload dir to the media dir
richTextConfig.setFileBrowserUploadRelPath("media");
// Layout/Alignment
Question q = item.getQuestion();
// alignment of KPRIM is only horizontal
if (q instanceof ChoiceQuestion && item.getQuestion().getType() != Question.TYPE_KPRIM) {
String[] layoutKeys = new String[] { "h", "v" };
String[] layoutValues = new String[] { translate("form.imd.layout.horizontal"), translate("form.imd.layout.vertical") };
// layout = uifactory.addDropdownSingleselect("form.imd.layout", formLayout, layoutKeys, layoutValues, null);
layout = uifactory.addRadiosHorizontal("layout", "form.imd.layout", formLayout, layoutKeys, layoutValues);
layout.select(((ChoiceQuestion) q).getFlowLabelClass().equals(ChoiceQuestion.BLOCK) ? "h" : "v", true);
}
if (!isSurvey) {
String[] yesnoKeys = new String[] { "y", "n" };
String[] yesnoValues = new String[] { translate("yes"), translate("no") };
// Attempts
limitAttempts = uifactory.addRadiosHorizontal("form.imd.limittries", formLayout, yesnoKeys, yesnoValues);
limitAttempts.setEnabled(!isRestrictedEditMode);
// Radios/Checkboxes need onclick because of IE bug OLAT-5753
limitAttempts.addActionListener(FormEvent.ONCLICK);
attempts = uifactory.addIntegerElement("form.imd.tries", 0, formLayout);
attempts.setEnabled(!isRestrictedEditMode);
attempts.setDisplaySize(3);
if (item.getMaxattempts() > 0) {
limitAttempts.select("y", true);
attempts.setIntValue(item.getMaxattempts());
} else {
limitAttempts.select("n", true);
attempts.setVisible(false);
}
// Time Limit
limitTime = uifactory.addRadiosHorizontal("form.imd.limittime", formLayout, yesnoKeys, yesnoValues);
// Radios/Checkboxes need onclick because of IE bug OLAT-5753
limitTime.addActionListener(FormEvent.ONCLICK);
limitTime.setEnabled(!isRestrictedEditMode);
timeMin = uifactory.addIntegerElement("form.imd.time.min", 0, formLayout);
timeMin.setEnabled(!isRestrictedEditMode);
timeMin.setDisplaySize(3);
timeSec = uifactory.addIntegerElement("form.imd.time.sek", 0, formLayout);
timeSec.setEnabled(!isRestrictedEditMode);
timeSec.setDisplaySize(3);
if (item.getDuration() != null && item.getDuration().isSet()) {
limitTime.select("y", true);
timeMin.setIntValue(item.getDuration().getMin());
timeSec.setIntValue(item.getDuration().getSec());
} else {
limitTime.select("n", true);
timeMin.setVisible(false);
timeSec.setVisible(false);
}
// Shuffle Answers
shuffle = uifactory.addRadiosHorizontal("shuffle", "form.imd.shuffle", formLayout, yesnoKeys, yesnoValues);
shuffle.setEnabled(!isRestrictedEditMode);
shuffle.setVisible(t != Question.TYPE_ESSAY && t != Question.TYPE_FIB);
if (item.getQuestion().isShuffle()) {
shuffle.select("y", true);
} else {
shuffle.select("n", true);
}
// Hints
Control itemControl = item.getItemcontrols().get(0);
showHints = uifactory.addRadiosHorizontal("showHints", "form.imd.solutionhints.show", formLayout, yesnoKeys, yesnoValues);
showHints.setEnabled(!isRestrictedEditMode);
// Radios/Checkboxes need onclick because of IE bug OLAT-5753
showHints.addActionListener(FormEvent.ONCLICK);
showHints.setVisible(t != Question.TYPE_ESSAY);
hint = uifactory.addRichTextElementForStringData("hint", "form.imd.solutionhints", item.getQuestion().getHintText(), 8, -1, true, qti.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
hint.setEnabled(!isRestrictedEditMode);
hint.getEditorConfiguration().setFigCaption(false);
// set upload dir to the media dir
hint.getEditorConfiguration().setFileBrowserUploadRelPath("media");
if (itemControl.isHint()) {
showHints.select("y", true);
} else {
showHints.select("n", true);
hint.setVisible(false);
}
// Solution
showSolution = uifactory.addRadiosHorizontal("showSolution", "form.imd.correctsolution.show", formLayout, yesnoKeys, yesnoValues);
showSolution.setEnabled(!isRestrictedEditMode);
// Radios/Checkboxes need onclick because of IE bug OLAT-5753
showSolution.addActionListener(FormEvent.ONCLICK);
boolean essay = (q.getType() == Question.TYPE_ESSAY);
String solLabel = essay ? "form.imd.correctsolution.word" : "form.imd.correctsolution";
solution = uifactory.addRichTextElementForStringData("solution", solLabel, item.getQuestion().getSolutionText(), 8, -1, true, qti.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
solution.setEnabled(!isRestrictedEditMode);
solution.getEditorConfiguration().setFigCaption(false);
// set upload dir to the media dir
solution.getEditorConfiguration().setFileBrowserUploadRelPath("media");
if (itemControl.isSolution()) {
showSolution.select("y", true);
} else {
showSolution.select("n", true);
showSolution.setVisible(!essay);
// solution always visible for essay
solution.setVisible(essay);
}
}
// Submit Button
uifactory.addFormSubmitButton("submit", formLayout);
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project OpenOLAT by OpenOLAT.
the class CSVToQuestionConverterTest method importMultipleChoice.
@Test
public void importMultipleChoice() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_mc.txt");
Assert.assertNotNull(importTxtUrl);
File importTxt = new File(importTxtUrl.toURI());
String input = FileUtils.readFileToString(importTxt, "UTF-8");
Translator translator = new KeyTranslator(Locale.ENGLISH);
ImportOptions options = new ImportOptions();
options.setShuffle(true);
CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
converter.parse(input);
List<ItemAndMetadata> items = converter.getItems();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
ItemAndMetadata importedItem = items.get(0);
Item item = importedItem.getItem();
Assert.assertNotNull(item);
Assert.assertEquals("Fussball: Austragungsort", item.getTitle());
Assert.assertEquals("Die Fussball WM wird alle vier Jahre von einem anderen Land ausgerichtet.", item.getObjectives());
Assert.assertEquals(Question.TYPE_MC, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof ChoiceQuestion);
Material questionMat = item.getQuestion().getQuestion();
Assert.assertNotNull(questionMat);
Assert.assertNotNull(questionMat.getElements());
Assert.assertEquals(1, questionMat.getElements().size());
QTIObject questionMatEl = questionMat.getElements().get(0);
Assert.assertTrue(questionMatEl instanceof Mattext);
String text = ((Mattext) questionMatEl).getContent();
Assert.assertEquals("In welchen L\u00E4ndern wurde zwischen dem Jahr 2000 und 2015 eine Fussball Weltmeisterschaft ausgetragen?", text);
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
Assert.assertNotNull(question.getResponses());
Assert.assertEquals(7, question.getResponses().size());
List<Response> responses = question.getResponses();
Assert.assertEquals(1.0f, responses.get(0).getPoints(), 0.0001);
Assert.assertEquals(1.0f, responses.get(1).getPoints(), 0.0001);
Assert.assertEquals(1.0f, responses.get(2).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(3).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(4).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(5).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(6).getPoints(), 0.0001);
// after it will be set to true for all of them
Assert.assertTrue(responses.get(0).isCorrect());
Assert.assertTrue(responses.get(1).isCorrect());
Assert.assertTrue(responses.get(2).isCorrect());
Assert.assertFalse(responses.get(3).isCorrect());
Assert.assertFalse(responses.get(4).isCorrect());
Assert.assertFalse(responses.get(5).isCorrect());
Assert.assertFalse(responses.get(6).isCorrect());
String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
Assert.assertEquals("Bravo! Die Antwort ich absolut korrekt.", feedbackMastery);
String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
Assert.assertEquals("Leider falsch. Probieren Sie es noch einmal.", feedbackFail);
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion 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);
}
}
Aggregations