use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project OpenOLAT by OpenOLAT.
the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem.
@Test
public void readHottextAssessmentItem() throws URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-per-answer-11-4-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
// hot texts
Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htf9250a96f24bc8873c9cc54dfbaaaa"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_3"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_2"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
Choice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_4"));
Assert.assertFalse(itemBuilder.isCorrect(wrong2));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(3.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// per answer
Assert.assertEquals(ScoreEvaluation.perAnswer, itemBuilder.getScoreEvaluationMode());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project OpenOLAT by OpenOLAT.
the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem_allCorrectAnswers.
@Test
public void readHottextAssessmentItem_allCorrectAnswers() throws URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-score-all-11-4-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(2, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
Assert.assertTrue(interactions.get(1) instanceof EndAttemptInteraction);
// hot texts
Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htebdb40344641dba115e3c8c6ce3926"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("ht103ce53892dea97613005a5ce76be31e"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("hte11a51c3e3d86a5f7293da19a1a8700e"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(2.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// per answer
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
// correct feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertNotNull(correctFeedback.getText());
Assert.assertTrue(correctFeedback.getText().contains("You check the right answers"));
// incorrect
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertNotNull(incorrectFeedback.getText());
Assert.assertTrue(incorrectFeedback.getText().contains("Some of your anwsers are not the correct one."));
// correct solution feedback
ModalFeedbackBuilder correctSolutionFeedback = itemBuilder.getCorrectSolutionFeedback();
Assert.assertNotNull(correctSolutionFeedback);
Assert.assertNotNull(correctSolutionFeedback.getText());
Assert.assertTrue(correctSolutionFeedback.getText().contains("A little hint towards the correct solution"));
// hint
ModalFeedbackBuilder hint = itemBuilder.getHint();
Assert.assertNotNull(hint);
Assert.assertNotNull(hint.getText());
Assert.assertTrue(hint.getText().contains("This is an endAttemptInteraction"));
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project OpenOLAT by OpenOLAT.
the class ChoiceScoreController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormContextHelp(contextHelpUrl);
super.initForm(formLayout, listener, ureq);
ScoreBuilder minScore = itemBuilder.getMinScoreBuilder();
String minValue = minScore == null ? "" : (minScore.getScore() == null ? "" : minScore.getScore().toString());
minScoreEl = uifactory.addTextElement("min.score", "min.score", 8, minValue, formLayout);
minScoreEl.setElementCssClass("o_sel_assessment_item_min_score");
minScoreEl.setEnabled(!restrictedEdit && !readOnly);
ScoreBuilder maxScore = itemBuilder.getMaxScoreBuilder();
String maxValue = maxScore == null ? "" : (maxScore.getScore() == null ? "" : maxScore.getScore().toString());
maxScoreEl = uifactory.addTextElement("max.score", "max.score", 8, maxValue, formLayout);
maxScoreEl.setElementCssClass("o_sel_assessment_item_max_score");
maxScoreEl.setEnabled(!restrictedEdit && !readOnly);
String[] choiceKeys = new String[0];
String[] choiceValues = new String[0];
maxChoicesEl = uifactory.addDropdownSingleselect("max.choices", formLayout, choiceKeys, choiceValues, null);
maxChoicesEl.setEnabled(!restrictedEdit && !readOnly);
minChoicesEl = uifactory.addDropdownSingleselect("min.choices", formLayout, choiceKeys, choiceValues, null);
minChoicesEl.setEnabled(!restrictedEdit && !readOnly);
updateMinMaxChoices();
String[] modeValues = new String[] { translate("form.score.assessment.all.correct"), translate("form.score.assessment.per.answer") };
assessmentModeEl = uifactory.addRadiosHorizontal("assessment.mode", "form.score.assessment.mode", formLayout, modeKeys, modeValues);
assessmentModeEl.setEnabled(!restrictedEdit && !readOnly);
assessmentModeEl.addActionListener(FormEvent.ONCHANGE);
if (itemBuilder.getScoreEvaluationMode() == ScoreEvaluation.perAnswer) {
assessmentModeEl.select(ScoreEvaluation.perAnswer.name(), true);
} else {
assessmentModeEl.select(ScoreEvaluation.allCorrectAnswers.name(), true);
}
String scorePage = velocity_root + "/choices_score.html";
scoreCont = FormLayoutContainer.createCustomFormLayout("scores", getTranslator(), scorePage);
formLayout.add(scoreCont);
scoreCont.setLabel(null, null);
for (Choice choice : itemBuilder.getChoices()) {
ChoiceWrapper wrapper = createChoiceWrapper(choice);
wrappers.add(wrapper);
}
scoreCont.contextPut("choices", wrappers);
scoreCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
scoreCont.setVisible(assessmentModeEl.isSelected(1));
// Submit Button
FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsContainer.setRootForm(mainForm);
buttonsContainer.setVisible(!readOnly);
formLayout.add(buttonsContainer);
uifactory.addFormSubmitButton("submit", buttonsContainer);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project OpenOLAT by OpenOLAT.
the class AssessmentObjectVelocityRenderDecorator method getVisibleOrderedChoices.
/*
<xsl:function name="qw:get-visible-ordered-choices" as="element()*">
<xsl:param name="interaction" as="element()"/>
<xsl:param name="choices" as="element()*"/>
<xsl:variable name="orderedChoices" as="element()*">
<xsl:choose>
<xsl:when test="$interaction/@shuffle='true'">
<xsl:for-each select="qw:get-shuffled-choice-order($interaction)">
<xsl:sequence select="$choices[@identifier=current()]"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$choices"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:sequence select="qw:filter-visible($orderedChoices)"/>
</xsl:function>
*/
public List<InlineChoice> getVisibleOrderedChoices(InlineChoiceInteraction interaction) {
List<InlineChoice> choices;
if (interaction.getShuffle()) {
// <xsl:variable name="shuffledChoiceOrders" select="$itemSessionState/qw:shuffledInteractionChoiceOrder"
// as="element(qw:shuffledInteractionChoiceOrder)*"/>
// <xsl:variable name="choiceSequence" as="xs:string?"
// select="$shuffledChoiceOrders[@responseIdentifier=$interaction/@responseIdentifier]/@choiceSequence"/>
List<Identifier> choiceOrders = itemSessionState.getShuffledInteractionChoiceOrder(interaction.getResponseIdentifier());
choices = new ArrayList<>();
for (Identifier choiceOrder : choiceOrders) {
choices.add(interaction.getInlineChoice(choiceOrder));
}
} else {
choices = interaction.getInlineChoices();
}
return choices.stream().filter((choice) -> isVisible(choice, itemSessionState)).collect(Collectors.toList());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project openolat by klemens.
the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem_allCorrectAnswers.
@Test
public void readHottextAssessmentItem_allCorrectAnswers() throws URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-score-all-11-4-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(2, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
Assert.assertTrue(interactions.get(1) instanceof EndAttemptInteraction);
// hot texts
Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htebdb40344641dba115e3c8c6ce3926"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("ht103ce53892dea97613005a5ce76be31e"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("hte11a51c3e3d86a5f7293da19a1a8700e"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(2.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// per answer
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
// correct feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertNotNull(correctFeedback.getText());
Assert.assertTrue(correctFeedback.getText().contains("You check the right answers"));
// incorrect
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertNotNull(incorrectFeedback.getText());
Assert.assertTrue(incorrectFeedback.getText().contains("Some of your anwsers are not the correct one."));
// correct solution feedback
ModalFeedbackBuilder correctSolutionFeedback = itemBuilder.getCorrectSolutionFeedback();
Assert.assertNotNull(correctSolutionFeedback);
Assert.assertNotNull(correctSolutionFeedback.getText());
Assert.assertTrue(correctSolutionFeedback.getText().contains("A little hint towards the correct solution"));
// hint
ModalFeedbackBuilder hint = itemBuilder.getHint();
Assert.assertNotNull(hint);
Assert.assertNotNull(hint.getText());
Assert.assertTrue(hint.getText().contains("This is an endAttemptInteraction"));
}
Aggregations