use of uk.ac.ed.ph.jqtiplus.node.expression.Expression in project OpenOLAT by OpenOLAT.
the class TestFeedbackBuilder method findFeedbackMatch.
private boolean findFeedbackMatch(Match match, boolean pass, ComplexReferenceIdentifier id) {
Expression firstExpression = match.getExpressions().get(0);
Expression secondExpression = match.getExpressions().get(1);
if (findBaseValue(firstExpression, pass) && findVariable(secondExpression, id)) {
return true;
}
if (findBaseValue(secondExpression, pass) && findVariable(firstExpression, id)) {
return true;
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.node.expression.Expression in project OpenOLAT by OpenOLAT.
the class AssessmentItemChecker method checkSetCorrectResponse.
/**
* responseDeclaration -> float
*
* templateVraiable -> integer
*
* setCorrectResponse
* -> variable -> integer doesn't match float -> issue
* @param item
* @return
*/
private static boolean checkSetCorrectResponse(AssessmentItem item) {
boolean allOk = true;
List<SetCorrectResponse> setCorrectResponses = QueryUtils.search(SetCorrectResponse.class, item);
for (SetCorrectResponse setCorrectResponse : setCorrectResponses) {
Identifier responseIdentifier = setCorrectResponse.getIdentifier();
ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
BaseType baseType = responseDeclaration.getBaseType();
Expression expression = setCorrectResponse.getExpression();
if (expression instanceof Variable) {
Variable variable = (Variable) expression;
ComplexReferenceIdentifier cpxVariableIdentifier = variable.getIdentifier();
Identifier variableIdentifier = Identifier.assumedLegal(cpxVariableIdentifier.toString());
TemplateDeclaration templateDeclaration = item.getTemplateDeclaration(variableIdentifier);
if (templateDeclaration != null && !templateDeclaration.hasBaseType(baseType)) {
templateDeclaration.setBaseType(baseType);
allOk &= false;
}
}
}
return allOk;
}
use of uk.ac.ed.ph.jqtiplus.node.expression.Expression in project openolat by klemens.
the class FIBAssessmentItemBuilder method extractNumericalEntrySettings.
public static void extractNumericalEntrySettings(AssessmentItem item, NumericalEntry numericalEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
Double solution = null;
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse != null && correctResponse.getFieldValues().size() > 0) {
List<FieldValue> fValues = correctResponse.getFieldValues();
SingleValue sValue = fValues.get(0).getSingleValue();
if (sValue instanceof FloatValue) {
solution = ((FloatValue) sValue).doubleValue();
numericalEntry.setSolution(solution);
}
}
// search the equal
List<ResponseRule> responseRules = item.getResponseProcessing().getResponseRules();
a_a: for (ResponseRule responseRule : responseRules) {
if (responseRule instanceof ResponseCondition) {
ResponseCondition condition = (ResponseCondition) responseRule;
ResponseIf responseIf = condition.getResponseIf();
if (responseIf != null && responseIf.getExpressions().size() > 0) {
// first is an and/equal/
Expression potentialEqualOrAnd = responseIf.getExpressions().get(0);
if (potentialEqualOrAnd instanceof And) {
And and = (And) potentialEqualOrAnd;
for (Expression potentialEqual : and.getExpressions()) {
if (potentialEqual instanceof Equal && potentialEqual.getExpressions().size() == 2 && extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqual)) {
break a_a;
}
}
} else if (potentialEqualOrAnd instanceof Equal) {
if (extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqualOrAnd)) {
// find to score as outcome value
if (responseIf.getResponseRules() != null && responseIf.getResponseRules().size() == 1 && responseIf.getResponseRules().get(0) instanceof SetOutcomeValue) {
SetOutcomeValue outcomeValue = (SetOutcomeValue) responseIf.getResponseRules().get(0);
if (outcomeValue.getExpressions() != null && outcomeValue.getExpressions().size() == 1 && outcomeValue.getExpressions().get(0) instanceof BaseValue) {
BaseValue bValue = (BaseValue) outcomeValue.getExpressions().get(0);
SingleValue sValue = bValue.getSingleValue();
if (sValue instanceof FloatValue) {
FloatValue fValue = (FloatValue) sValue;
numericalEntry.setScore(fValue.doubleValue());
mappedScore.add(fValue.doubleValue());
countAlternatives.incrementAndGet();
}
}
}
break a_a;
}
}
}
}
}
// toleranceMode cannot be empty
if (numericalEntry.getToleranceMode() == null) {
numericalEntry.setToleranceMode(ToleranceMode.EXACT);
}
}
use of uk.ac.ed.ph.jqtiplus.node.expression.Expression in project openolat by klemens.
the class AssessmentItemFactory method matchAdditionalFeedback.
/**
* the additional feedback have only responseIf
*
* @param item
* @param feedback
* @return
*/
public static boolean matchAdditionalFeedback(AssessmentItem item, ModalFeedback feedback) {
List<ResponseRule> responseRules = item.getResponseProcessing().getResponseRules();
for (ResponseRule responseRule : responseRules) {
if (responseRule instanceof ResponseCondition) {
ResponseCondition responseCondition = (ResponseCondition) responseRule;
if (responseCondition.getResponseIf() == null || responseCondition.getResponseElse() != null || (responseCondition.getResponseElseIfs() != null && responseCondition.getResponseElseIfs().size() > 0)) {
continue;
}
ResponseIf responseIf = responseCondition.getResponseIf();
List<ResponseRule> ifResponseRules = responseIf.getResponseRules();
if (ifResponseRules == null || ifResponseRules.size() != 1 || !(ifResponseRules.get(0) instanceof SetOutcomeValue)) {
continue;
}
SetOutcomeValue setOutcomeValue = (SetOutcomeValue) responseIf.getResponseRules().get(0);
if (!findBaseValueInExpression(setOutcomeValue.getExpression(), feedback.getIdentifier())) {
continue;
}
List<Expression> expressions = responseIf.getExpressions();
if (expressions == null || expressions.size() != 1 || !(expressions.get(0) instanceof And)) {
continue;
}
List<Variable> variables = QueryUtils.search(Variable.class, expressions.get(0));
if (variables != null && variables.size() == 1) {
Variable bValue = variables.get(0);
ComplexReferenceIdentifier identifier = bValue.getIdentifier();
if (identifier.equals(QTI21Constants.SCORE_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.NUM_ATTEMPTS_CLX_IDENTIFIER)) {
return true;
}
if (identifier.equals(QTI21Constants.CORRECT_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.INCORRECT_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.EMPTY_CLX_IDENTIFIER)) {
return false;
}
String identifierToString = identifier.toString();
if (identifierToString.contains("RESPONSE_")) {
return true;
}
}
}
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.node.expression.Expression in project openolat by klemens.
the class AssessmentTestBuilder method buildCutValue.
/* Passed
<outcomeCondition>
<outcomeIf>
<gte>
<sum>
<testVariables variableIdentifier="SCORE" />
</sum>
<baseValue baseType="float">
1
</baseValue>
</gte>
<setOutcomeValue identifier="PASS">
<baseValue baseType="boolean">
true
</baseValue>
</setOutcomeValue>
</outcomeIf>
<outcomeElse>
<setOutcomeValue identifier="PASS">
<baseValue baseType="boolean">
false
</baseValue>
</setOutcomeValue>
</outcomeElse>
</outcomeCondition>
*/
private void buildCutValue() {
if (cutValue != null) {
OutcomeDeclaration passDeclaration = assessmentTest.getOutcomeDeclaration(QTI21Constants.PASS_IDENTIFIER);
if (passDeclaration == null) {
passDeclaration = AssessmentTestFactory.createOutcomeDeclaration(assessmentTest, QTI21Constants.PASS_IDENTIFIER, false);
assessmentTest.getOutcomeDeclarations().add(passDeclaration);
}
boolean updated = false;
if (cutValueRule != null && cutValueRule.getOutcomeIf().getExpressions().size() > 0) {
Expression gte = cutValueRule.getOutcomeIf().getExpressions().get(0);
if (gte.getExpressions().size() > 1) {
Expression baseValue = gte.getExpressions().get(1);
if (baseValue instanceof BaseValue) {
BaseValue value = (BaseValue) baseValue;
value.setSingleValue(new FloatValue(cutValue.doubleValue()));
updated = true;
}
}
}
if (!updated) {
assessmentTest.getOutcomeProcessing().getOutcomeRules().remove(cutValueRule);
cutValueRule = AssessmentTestFactory.createCutValueRule(assessmentTest, cutValue);
assessmentTest.getOutcomeProcessing().getOutcomeRules().add(cutValueRule);
}
} else if (cutValueRule != null) {
assessmentTest.getOutcomeProcessing().getOutcomeRules().remove(cutValueRule);
}
}
Aggregations