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());
}
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);
}
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;
}
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);
}
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);
}
Aggregations