use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertSingleChoice.
private AssessmentItemBuilder convertSingleChoice(Item item) {
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
itemBuilder.clearMapping();
itemBuilder.clearSimpleChoices();
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
convertOrientation(question, itemBuilder);
List<Response> responses = question.getResponses();
Map<String, Identifier> identToIdentifier = new HashMap<>();
for (Response response : responses) {
String responseText = response.getContent().renderAsHtmlForEditor();
responseText = blockedHtml(responseText);
SimpleChoice newChoice;
if (StringHelper.isHtml(responseText)) {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, "", itemBuilder.getQuestionType().getPrefix());
htmlBuilder.appendHtml(newChoice, responseText);
} else {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, responseText, itemBuilder.getQuestionType().getPrefix());
}
itemBuilder.addSimpleChoice(newChoice);
identToIdentifier.put(response.getIdent(), newChoice.getIdentifier());
if (response.isCorrect()) {
itemBuilder.setCorrectAnswer(newChoice.getIdentifier());
}
}
convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
double correctScore = question.getSingleCorrectScore();
if (correctScore >= 0.0d) {
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(correctScore);
}
return itemBuilder;
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertFIB.
private AssessmentItemBuilder convertFIB(Item item) {
FIBAssessmentItemBuilder itemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
itemBuilder.setQuestion("");
itemBuilder.clearTextEntries();
convertItemBasics(item, itemBuilder);
Question question = item.getQuestion();
boolean singleCorrect = question.isSingleCorrect();
if (singleCorrect) {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
} else {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
}
itemBuilder.getMinScoreBuilder().setScore(new Double(question.getMinValue()));
itemBuilder.getMaxScoreBuilder().setScore(new Double(question.getMaxValue()));
List<Response> responses = question.getResponses();
StringBuilder sb = new StringBuilder();
for (Response response : responses) {
if (response instanceof FIBResponse) {
FIBResponse gap = (FIBResponse) response;
if (FIBResponse.TYPE_BLANK.equals(gap.getType())) {
String responseId = itemBuilder.generateResponseIdentifier();
StringBuilder entryString = new StringBuilder();
entryString.append(" <textentryinteraction responseidentifier=\"").append(responseId).append("\"");
TextEntry entry = itemBuilder.createTextEntry(responseId);
entry.setCaseSensitive("Yes".equals(gap.getCaseSensitive()));
if (gap.getMaxLength() > 0) {
entry.setExpectedLength(gap.getMaxLength());
entryString.append(" expectedlength=\"").append(gap.getMaxLength()).append("\"");
} else if (gap.getSize() > 0) {
entry.setExpectedLength(gap.getSize());
entryString.append(" expectedlength=\"").append(gap.getSize()).append("\"");
}
parseAlternatives(gap.getCorrectBlank(), gap.getPoints(), entry);
entryString.append("></textentryinteraction>");
sb.append(entryString);
} else if (FIBResponse.TYPE_CONTENT.equals(gap.getType())) {
Material text = gap.getContent();
String htmltext = text.renderAsHtmlForEditor();
htmltext = blockedHtml(htmltext);
sb.append(htmltext);
}
}
}
String fib = "<div>" + sb.toString() + "</div>";
itemBuilder.setQuestion(fib);
return itemBuilder;
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project openolat by klemens.
the class CSVToQuestionConverterTest method importFillInBlanck.
@Test
public void importFillInBlanck() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_fib.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(Question.TYPE_FIB, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof FIBQuestion);
FIBQuestion question = (FIBQuestion) item.getQuestion();
List<Response> responses = question.getResponses();
Assert.assertNotNull(responses);
Assert.assertEquals(7, responses.size());
// check java type
for (Response response : responses) {
Assert.assertTrue(response instanceof FIBResponse);
}
// check type
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(0)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(1)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(2)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(3)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(4)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(5)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(6)).getType());
// check size
Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getSize());
Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getSize());
Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getSize());
// check max length
Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getMaxLength());
Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getMaxLength());
Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getMaxLength());
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project openolat by klemens.
the class QTI12MetadataController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
Question question = item.getQuestion();
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
if (question != null) {
layoutCont.contextPut("hasQuestion", Boolean.TRUE);
// settings
String shuffleStr = translate(question.isShuffle() ? "editor.true" : "editor.false");
uifactory.addStaticTextElement("form.imd.shuffle", shuffleStr, formLayout);
String duration = "";
if (item.getDuration() != null) {
duration = item.getDuration().getMin() + ":" + item.getDuration().getSec();
}
uifactory.addStaticTextElement("form.metadata.duration", duration, formLayout);
if (question instanceof ChoiceQuestion) {
ChoiceQuestion choice = (ChoiceQuestion) question;
if (item.getQuestion().getType() == Question.TYPE_SC) {
String score = Float.toString(question.getSingleCorrectScore());
uifactory.addStaticTextElement("score", score, formLayout);
} else if (item.getQuestion().getType() == Question.TYPE_MC) {
String minVal = Float.toString(choice.getMinValue());
String maxVal = Float.toString(choice.getMaxValue());
uifactory.addStaticTextElement("score.min", minVal, formLayout);
uifactory.addStaticTextElement("score.max", maxVal, formLayout);
}
}
// correct responses
List<Response> responses = question.getResponses();
if (question.getType() == Question.TYPE_MC || question.getType() == Question.TYPE_SC) {
setMCAndSCCorrectResponses(question, responses, layoutCont);
} else if (question.getType() == Question.TYPE_KPRIM) {
setKPrimCorrectResponses(responses, layoutCont);
}
}
// feedbacks
boolean hasFeedbacks = false;
Material masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
if (masteryMat != null) {
layoutCont.contextPut("item_feedback_mastery", masteryMat.renderAsText());
hasFeedbacks = true;
}
Material failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
if (failureMat != null) {
layoutCont.contextPut("item_feedback_fail", failureMat.renderAsText());
hasFeedbacks = true;
}
List<String> responsesFeedback = new ArrayList<>();
if (question != null && question.getType() <= Question.TYPE_MC) {
for (Object obj : question.getResponses()) {
ChoiceResponse response = (ChoiceResponse) obj;
Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
if (responseFeedbackMat != null) {
responsesFeedback.add(responseFeedbackMat.renderAsText());
}
}
hasFeedbacks |= responsesFeedback.size() > 0;
}
layoutCont.contextPut("responsesFeedback", responsesFeedback);
layoutCont.contextPut("hasFeedbacks", new Boolean(hasFeedbacks));
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project openolat by klemens.
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);
}
Aggregations