use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class EssayAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.essay, title);
// define the response
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
ResponseDeclaration responseDeclaration = createExtendedTextResponseDeclaration(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
// outcomes
appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
appendExtendedTextInteraction(itemBody, responseDeclarationId);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class AlienItemAnalyzer method checkFeedback.
private void checkFeedback(Report report) {
if (item.getModalFeedbacks() != null && item.getModalFeedbacks().size() > 0) {
Set<Identifier> outcomeIdentifiers = new HashSet<>();
List<ModalFeedback> feedbacks = item.getModalFeedbacks();
for (ModalFeedback feedback : feedbacks) {
if (feedback.getOutcomeIdentifier() != null) {
outcomeIdentifiers.add(feedback.getOutcomeIdentifier());
}
}
if (outcomeIdentifiers.size() == 1) {
if (outcomeIdentifiers.iterator().next().equals(QTI21Constants.FEEDBACKMODAL_IDENTIFIER)) {
checkFeedbackModalResponseProcessing(report);
} else {
report.addWarning(ReportWarningEnum.alienFeedbacks);
}
} else {
// Onyx and OpenOLAT only use one outcome identifier for the feedbacks
// Taotesting use several different identifiers. And we don't
// understand feedbacks without outcome identifiers
report.addWarning(ReportWarningEnum.alienFeedbacks);
}
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class SingleChoiceAssessmentItemBuilderTest method createSingleAssessmentItem_allCorrectAnswers.
@Test
public void createSingleAssessmentItem_allCorrectAnswers() throws IOException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "Single choice", qtiSerializer);
itemBuilder.setQuestion("<p>Hello</p>");
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
SimpleChoice choice1 = AssessmentItemFactory.createSimpleChoice(interaction, "One", "sc");
SimpleChoice choice2 = AssessmentItemFactory.createSimpleChoice(interaction, "Two", "sc");
SimpleChoice choice3 = AssessmentItemFactory.createSimpleChoice(interaction, "Three", "sc");
List<SimpleChoice> choiceList = new ArrayList<>();
choiceList.add(choice1);
choiceList.add(choice2);
choiceList.add(choice3);
itemBuilder.setSimpleChoices(choiceList);
itemBuilder.setCorrectAnswer(choice2.getIdentifier());
itemBuilder.setMaxScore(3.0d);
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
itemBuilder.build();
File itemFile = new File(WebappHelper.getTmpDir(), "scAssessmentItem" + UUID.randomUUID() + ".xml");
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(itemBuilder.getAssessmentItem(), out);
} catch (Exception e) {
log.error("", e);
}
{
// correct answers
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData(choice2.getIdentifier().toString()));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(3.0d), score);
}
{
// wrong answer
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData(choice3.getIdentifier().toString()));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(0.0d), score);
}
FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class QTI21ServiceImpl method getAssessmentResponses.
@Override
public Map<Identifier, AssessmentResponse> getAssessmentResponses(AssessmentItemSession assessmentItemSession) {
List<AssessmentResponse> responses = testResponseDao.getResponses(assessmentItemSession);
Map<Identifier, AssessmentResponse> responseMap = new HashMap<>();
for (AssessmentResponse response : responses) {
responseMap.put(Identifier.assumedLegal(response.getResponseIdentifier()), response);
}
return responseMap;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class QTI21ServiceImpl method recordOutcomeVariable.
private void recordOutcomeVariable(AssessmentTestSession candidateSession, OutcomeVariable outcomeVariable, Map<Identifier, String> outcomes) {
Identifier identifier = outcomeVariable.getIdentifier();
Value computedValue = outcomeVariable.getComputedValue();
if (QtiConstants.VARIABLE_DURATION_IDENTIFIER.equals(identifier)) {
log.audit(candidateSession.getKey() + " :: " + outcomeVariable.getIdentifier() + " - " + stringifyQtiValue(computedValue));
} else if (QTI21Constants.SCORE_IDENTIFIER.equals(identifier)) {
if (computedValue instanceof NumberValue) {
double score = ((NumberValue) computedValue).doubleValue();
candidateSession.setScore(new BigDecimal(score));
}
} else if (QTI21Constants.PASS_IDENTIFIER.equals(identifier)) {
if (computedValue instanceof BooleanValue) {
boolean pass = ((BooleanValue) computedValue).booleanValue();
candidateSession.setPassed(pass);
}
}
try {
outcomes.put(identifier, stringifyQtiValue(computedValue));
} catch (Exception e) {
log.error("", e);
}
}
Aggregations