use of uk.ac.ed.ph.jqtiplus.value.FloatValue in project openolat by klemens.
the class AssessmentItemBuilder method extractMaxScore.
private void extractMaxScore() {
OutcomeDeclaration outcomeDeclaration = assessmentItem.getOutcomeDeclaration(MAXSCORE_IDENTIFIER);
if (outcomeDeclaration != null) {
DefaultValue defaultValue = outcomeDeclaration.getDefaultValue();
if (defaultValue != null) {
Value maxScoreValue = defaultValue.evaluate();
if (maxScoreValue instanceof FloatValue) {
Double maxScore = new Double(((FloatValue) maxScoreValue).doubleValue());
maxScoreBuilder = new ScoreBuilder(maxScore, outcomeDeclaration);
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.value.FloatValue in project openolat by klemens.
the class AssessmentItemFactory method createOutcomeDeclarationForMinScore.
public static OutcomeDeclaration createOutcomeDeclarationForMinScore(AssessmentItem assessmentItem, double minScore) {
OutcomeDeclaration maxScoreOutcomeDeclaration = new OutcomeDeclaration(assessmentItem);
maxScoreOutcomeDeclaration.setIdentifier(QTI21Constants.MINSCORE_IDENTIFIER);
maxScoreOutcomeDeclaration.setCardinality(Cardinality.SINGLE);
maxScoreOutcomeDeclaration.setBaseType(BaseType.FLOAT);
List<View> views = new ArrayList<>();
views.add(View.TEST_CONSTRUCTOR);
maxScoreOutcomeDeclaration.setViews(views);
DefaultValue maxScoreDefaultVal = new DefaultValue(maxScoreOutcomeDeclaration);
maxScoreOutcomeDeclaration.setDefaultValue(maxScoreDefaultVal);
FieldValue maxScoreDefaultFieldVal = new FieldValue(maxScoreDefaultVal, new FloatValue(minScore));
maxScoreDefaultVal.getFieldValues().add(maxScoreDefaultFieldVal);
return maxScoreOutcomeDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.value.FloatValue in project openolat by klemens.
the class AssessmentItemFactory method appendVariableBaseValue.
/*
<variable identifier="SCORE" />
<baseValue baseType="float">4</baseValue>
*/
/**
* @param var
* @param value
* @param responseIdentifier
* @param parentExpression
* @param reverse if true, reverse the order, first baseValue and then variable
*/
private static void appendVariableBaseValue(ModalFeedbackCondition.Variable var, String value, Identifier responseIdentifier, Expression parentExpression, boolean reverse) {
Variable variable = new Variable(parentExpression);
BaseValue bValue = new BaseValue(parentExpression);
if (reverse) {
parentExpression.getExpressions().add(bValue);
parentExpression.getExpressions().add(variable);
} else {
parentExpression.getExpressions().add(variable);
parentExpression.getExpressions().add(bValue);
}
switch(var) {
case score:
bValue.setBaseTypeAttrValue(BaseType.FLOAT);
bValue.setSingleValue(new FloatValue(Double.parseDouble(value)));
variable.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
break;
case attempts:
bValue.setBaseTypeAttrValue(BaseType.INTEGER);
bValue.setSingleValue(new IntegerValue(Integer.parseInt(value)));
variable.setIdentifier(QTI21Constants.NUM_ATTEMPTS_CLX_IDENTIFIER);
break;
case response:
bValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
bValue.setSingleValue(new IdentifierValue(Identifier.parseString(value)));
variable.setIdentifier(ComplexReferenceIdentifier.parseString(responseIdentifier.toString()));
break;
}
}
use of uk.ac.ed.ph.jqtiplus.value.FloatValue in project openolat by klemens.
the class AssessmentItemFactory method createOutcomeDeclarationForMaxScore.
public static OutcomeDeclaration createOutcomeDeclarationForMaxScore(AssessmentItem assessmentItem, double maxScore) {
OutcomeDeclaration maxScoreOutcomeDeclaration = new OutcomeDeclaration(assessmentItem);
maxScoreOutcomeDeclaration.setIdentifier(QTI21Constants.MAXSCORE_IDENTIFIER);
maxScoreOutcomeDeclaration.setCardinality(Cardinality.SINGLE);
maxScoreOutcomeDeclaration.setBaseType(BaseType.FLOAT);
DefaultValue maxScoreDefaultVal = new DefaultValue(maxScoreOutcomeDeclaration);
maxScoreOutcomeDeclaration.setDefaultValue(maxScoreDefaultVal);
FieldValue maxScoreDefaultFieldVal = new FieldValue(maxScoreDefaultVal, new FloatValue(maxScore));
maxScoreDefaultVal.getFieldValues().add(maxScoreDefaultFieldVal);
return maxScoreOutcomeDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.value.FloatValue 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());
}
Aggregations