Search in sources :

Example 6 with EndAttemptInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction in project OpenOLAT by OpenOLAT.

the class MultipleChoiceAssessmentItemBuilderTest method readMultipleChoice_allAnswers_1110.

@Test
public void readMultipleChoice_allAnswers_1110() throws IOException, URISyntaxException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/multiple-choice-score-all-11-1-0.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder(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 ChoiceInteraction);
    Assert.assertTrue(interactions.get(1) instanceof EndAttemptInteraction);
    // choices
    SimpleChoice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("mc1959a495d449f9af65b38695d3aff1"));
    Assert.assertTrue(itemBuilder.isCorrect(correct1));
    SimpleChoice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("mca856e7adb54d3f9af06ecf9c00da69"));
    Assert.assertTrue(itemBuilder.isCorrect(correct2));
    SimpleChoice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("mcd39be64a6b4f20a2372cba44340e59"));
    Assert.assertFalse(itemBuilder.isCorrect(wrong1));
    SimpleChoice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("mc18648f96a84d479817cb5e81165c80"));
    Assert.assertFalse(itemBuilder.isCorrect(wrong2));
    // 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);
    // correct feedback
    ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
    Assert.assertNotNull(correctFeedback);
    Assert.assertNotNull(correctFeedback.getText());
    Assert.assertTrue(correctFeedback.getText().contains("All answers are correct"));
    // incorrect
    ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
    Assert.assertNotNull(incorrectFeedback);
    Assert.assertNotNull(incorrectFeedback.getText());
    Assert.assertTrue(incorrectFeedback.getText().contains("You missed something"));
    // hint
    ModalFeedbackBuilder hint = itemBuilder.getHint();
    Assert.assertNotNull(hint);
    Assert.assertNotNull(hint.getText());
    Assert.assertTrue(hint.getText().contains("This is the correct solution"));
    // per answer
    Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) URL(java.net.URL) Test(org.junit.Test)

Example 7 with EndAttemptInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction in project OpenOLAT by OpenOLAT.

the class AbstractQtiWorksController method processResponse.

protected void processResponse(UserRequest ureq, FormItem source) {
    Map<Identifier, ResponseInput> stringResponseMap = extractStringResponseData();
    Map<Identifier, ResponseInput> fileResponseMap;
    if (mainForm.isMultipartEnabled()) {
        fileResponseMap = extractFileResponseData();
    } else {
        fileResponseMap = Collections.emptyMap();
    }
    if (source instanceof FormLink) {
        FormLink button = (FormLink) source;
        String cmd = button.getCmd();
        if (cmd != null && cmd.startsWith("qtiworks_response_")) {
            String responseIdentifierString = cmd.substring("qtiworks_response_".length());
            String presentedFlag = "qtiworks_presented_".concat(responseIdentifierString);
            if (mainForm.getRequestParameterSet().contains(presentedFlag)) {
                Identifier responseIdentifier;
                try {
                    responseIdentifier = getResponseIdentifierFromUniqueId(responseIdentifierString);
                // Identifier.parseString(responseIdentifierString);
                } catch (final QtiParseException e) {
                    throw new RuntimeException("Bad response identifier encoded in parameter " + cmd, e);
                }
                String[] responseValues;
                if (button.getUserObject() instanceof EndAttemptInteraction) {
                    responseValues = new String[] { ((EndAttemptInteraction) button.getUserObject()).getTitle() };
                } else {
                    responseValues = new String[] { "submit" };
                }
                StringInput stringResponseData = new StringInput(responseValues);
                stringResponseMap.put(responseIdentifier, stringResponseData);
            }
        }
    }
    String candidateComment = extractComment();
    fireResponse(ureq, source, stringResponseMap, fileResponseMap, candidateComment);
}
Also used : StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) QtiParseException(uk.ac.ed.ph.jqtiplus.exception.QtiParseException)

Example 8 with EndAttemptInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction in project OpenOLAT by OpenOLAT.

the class QTI21AssessmentItemStatisticsController method initInteractionControllers.

private List<String> initInteractionControllers(UserRequest ureq, StatisticsItem itemStats) {
    List<Interaction> interactions = item.getItemBody().findInteractions();
    List<String> interactionIds = new ArrayList<>(interactions.size());
    int counter = 0;
    List<TextEntryInteraction> textEntryInteractions = new ArrayList<>();
    for (Interaction interaction : interactions) {
        if (interaction instanceof TextEntryInteraction) {
            textEntryInteractions.add((TextEntryInteraction) interaction);
        } else if (interaction instanceof EndAttemptInteraction) {
            continue;
        } else {
            Component cmp = interactionControllerFactory(ureq, interaction, itemStats);
            String componentId = "interaction" + counter++;
            mainVC.put(componentId, cmp);
            interactionIds.add(componentId);
        }
    }
    if (textEntryInteractions.size() > 0) {
        Controller interactionCtrl = new TextEntryInteractionsStatisticsController(ureq, getWindowControl(), itemRef, item, textEntryInteractions, resourceResult);
        listenTo(interactionCtrl);
        String componentId = "interaction" + counter++;
        mainVC.put(componentId, interactionCtrl.getInitialComponent());
        interactionIds.add(componentId);
    }
    return interactionIds;
}
Also used : TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) TextEntryInteractionsStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.TextEntryInteractionsStatisticsController) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) ArrayList(java.util.ArrayList) StatisticsComponent(org.olat.core.gui.components.chart.StatisticsComponent) Component(org.olat.core.gui.components.Component) TextEntryInteractionsStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.TextEntryInteractionsStatisticsController) HotspotInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.HotspotInteractionStatisticsController) MatchStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.MatchStatisticsController) UserFilterController(org.olat.modules.assessment.ui.UserFilterController) SimpleChoiceInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.SimpleChoiceInteractionStatisticsController) KPrimStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.KPrimStatisticsController) HottextInteractionStatisticsController(org.olat.ims.qti21.ui.statistics.interactions.HottextInteractionStatisticsController) Controller(org.olat.core.gui.control.Controller) BasicController(org.olat.core.gui.control.controller.BasicController) UnsupportedInteractionController(org.olat.ims.qti21.ui.statistics.interactions.UnsupportedInteractionController)

Example 9 with EndAttemptInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction in project OpenOLAT by OpenOLAT.

the class AssessmentItemBuilder method buildHint.

/**
 * @param outcomeDeclarations
 * @param responseRules
 */
protected void buildHint(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
    if (hint == null)
        return;
    // response declaration -> identifier=HINTREQUEST -> for the end attempt interaction
    ResponseDeclaration hintResponseDeclaration = AssessmentItemFactory.createHintRequestResponseDeclaration(assessmentItem);
    assessmentItem.getResponseDeclarations().add(hintResponseDeclaration);
    // outcome declaration -> identifier=HINTFEEDBACKMODAL -> for processing and feedback
    OutcomeDeclaration modalOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForHint(assessmentItem);
    outcomeDeclarations.add(modalOutcomeDeclaration);
    // the body
    P paragraph = new P(assessmentItem.getItemBody());
    assessmentItem.getItemBody().getBlocks().add(paragraph);
    EndAttemptInteraction endAttemptInteraction = new EndAttemptInteraction(paragraph);
    endAttemptInteraction.setResponseIdentifier(QTI21Constants.HINT_REQUEST_IDENTIFIER);
    endAttemptInteraction.setTitle(hint.getTitle());
    paragraph.getInlines().add(endAttemptInteraction);
    // the feedback
    ModalFeedback emptyModalFeedback = AssessmentItemFactory.createModalFeedback(assessmentItem, QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER, QTI21Constants.HINT_IDENTIFIER, hint.getTitle(), hint.getText());
    assessmentItem.getModalFeedbacks().add(emptyModalFeedback);
    // the response processing
    ResponseCondition rule = new ResponseCondition(assessmentItem.getResponseProcessing());
    responseRules.add(0, rule);
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    /*
		<responseIf>
			<variable identifier="HINTREQUEST"/>
			<setOutcomeValue identifier="FEEDBACK">
				<baseValue baseType="identifier">HINT</baseValue>
			</setOutcomeValue>
  		</responseIf>
		*/
    Variable variable = new Variable(responseIf);
    variable.setIdentifier(QTI21Constants.HINT_REQUEST_CLX_IDENTIFIER);
    responseIf.getExpressions().add(variable);
    SetOutcomeValue hintVar = new SetOutcomeValue(responseIf);
    hintVar.setIdentifier(QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER);
    BaseValue hintVal = new BaseValue(hintVar);
    hintVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
    hintVal.setSingleValue(new IdentifierValue(QTI21Constants.HINT));
    hintVar.setExpression(hintVal);
    responseIf.getResponseRules().add(hintVar);
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 10 with EndAttemptInteraction

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction in project openolat by klemens.

the class AssessmentItemBuilder method buildHint.

/**
 * @param outcomeDeclarations
 * @param responseRules
 */
protected void buildHint(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
    if (hint == null)
        return;
    // response declaration -> identifier=HINTREQUEST -> for the end attempt interaction
    ResponseDeclaration hintResponseDeclaration = AssessmentItemFactory.createHintRequestResponseDeclaration(assessmentItem);
    assessmentItem.getResponseDeclarations().add(hintResponseDeclaration);
    // outcome declaration -> identifier=HINTFEEDBACKMODAL -> for processing and feedback
    OutcomeDeclaration modalOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForHint(assessmentItem);
    outcomeDeclarations.add(modalOutcomeDeclaration);
    // the body
    P paragraph = new P(assessmentItem.getItemBody());
    assessmentItem.getItemBody().getBlocks().add(paragraph);
    EndAttemptInteraction endAttemptInteraction = new EndAttemptInteraction(paragraph);
    endAttemptInteraction.setResponseIdentifier(QTI21Constants.HINT_REQUEST_IDENTIFIER);
    endAttemptInteraction.setTitle(hint.getTitle());
    paragraph.getInlines().add(endAttemptInteraction);
    // the feedback
    ModalFeedback emptyModalFeedback = AssessmentItemFactory.createModalFeedback(assessmentItem, QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER, QTI21Constants.HINT_IDENTIFIER, hint.getTitle(), hint.getText());
    assessmentItem.getModalFeedbacks().add(emptyModalFeedback);
    // the response processing
    ResponseCondition rule = new ResponseCondition(assessmentItem.getResponseProcessing());
    responseRules.add(0, rule);
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    /*
		<responseIf>
			<variable identifier="HINTREQUEST"/>
			<setOutcomeValue identifier="FEEDBACK">
				<baseValue baseType="identifier">HINT</baseValue>
			</setOutcomeValue>
  		</responseIf>
		*/
    Variable variable = new Variable(responseIf);
    variable.setIdentifier(QTI21Constants.HINT_REQUEST_CLX_IDENTIFIER);
    responseIf.getExpressions().add(variable);
    SetOutcomeValue hintVar = new SetOutcomeValue(responseIf);
    hintVar.setIdentifier(QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER);
    BaseValue hintVal = new BaseValue(hintVar);
    hintVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
    hintVal.setSingleValue(new IdentifierValue(QTI21Constants.HINT));
    hintVar.setExpression(hintVal);
    responseIf.getResponseRules().add(hintVar);
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Aggregations

EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)12 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)8 URL (java.net.URL)6 Test (org.junit.Test)6 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)6 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)6 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)6 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)6 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)4 HottextInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction)4 SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)4 ArrayList (java.util.ArrayList)2 Component (org.olat.core.gui.components.Component)2 StatisticsComponent (org.olat.core.gui.components.chart.StatisticsComponent)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 HottextAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder)2 StringInput (org.olat.ims.qti21.ui.ResponseInput.StringInput)2