Search in sources :

Example 51 with ResponseCondition

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition in project openolat by klemens.

the class AssessmentItemFactory method createMaxScoreBoundLimitRule.

/**
 * Rule which ensure that the final score is not above the max. score value.
 */
public static ResponseRule createMaxScoreBoundLimitRule(ResponseProcessing responseProcessing) {
    /*
		<responseCondition>
			<responseIf>
				<gt>
					<variable identifier="SCORE" /><variable identifier="MAXSCORE" />
				</gt>
				<setOutcomeValue identifier="SCORE">
					<variable identifier="MAXSCORE" />
				</setOutcomeValue>
			</responseIf>
		</responseCondition>
		*/
    ResponseCondition rule = new ResponseCondition(responseProcessing);
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    Gt gt = new Gt(responseIf);
    responseIf.setExpression(gt);
    Variable scoreVar = new Variable(gt);
    scoreVar.setIdentifier(SCORE_CLX_IDENTIFIER);
    gt.getExpressions().add(scoreVar);
    Variable maxScoreVar = new Variable(gt);
    maxScoreVar.setIdentifier(MAXSCORE_CLX_IDENTIFIER);
    gt.getExpressions().add(maxScoreVar);
    SetOutcomeValue setOutcomeValue = new SetOutcomeValue(responseIf);
    setOutcomeValue.setIdentifier(SCORE_IDENTIFIER);
    Variable maxScoreOutcomeVar = new Variable(setOutcomeValue);
    maxScoreOutcomeVar.setIdentifier(MAXSCORE_CLX_IDENTIFIER);
    setOutcomeValue.setExpression(maxScoreOutcomeVar);
    responseIf.getResponseRules().add(setOutcomeValue);
    return rule;
}
Also used : Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) Gt(uk.ac.ed.ph.jqtiplus.node.expression.operator.Gt) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 52 with ResponseCondition

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition 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;
}
Also used : ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) ResponseRule(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 53 with ResponseCondition

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition in project openolat by klemens.

the class AssessmentItemFactory method createMinScoreBoundLimitRule.

/**
 * Rule which ensure that the final score is not under the min. score value.
 */
public static ResponseRule createMinScoreBoundLimitRule(ResponseProcessing responseProcessing) {
    /*
		<responseCondition>
			<responseIf>
				<lt>
					<variable identifier="SCORE" /><variable identifier="MINSCORE" />
				</lt>
				<setOutcomeValue identifier="SCORE">
					<variable identifier="MINSCORE" />
				</setOutcomeValue>
			</responseIf>
		</responseCondition>
		*/
    ResponseCondition rule = new ResponseCondition(responseProcessing);
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    Lt lt = new Lt(responseIf);
    responseIf.setExpression(lt);
    Variable scoreVar = new Variable(lt);
    scoreVar.setIdentifier(SCORE_CLX_IDENTIFIER);
    lt.getExpressions().add(scoreVar);
    Variable minScoreVar = new Variable(lt);
    minScoreVar.setIdentifier(MINSCORE_CLX_IDENTIFIER);
    lt.getExpressions().add(minScoreVar);
    SetOutcomeValue setOutcomeValue = new SetOutcomeValue(responseIf);
    setOutcomeValue.setIdentifier(SCORE_IDENTIFIER);
    Variable minScoreOutcomeVar = new Variable(setOutcomeValue);
    minScoreOutcomeVar.setIdentifier(MINSCORE_CLX_IDENTIFIER);
    setOutcomeValue.setExpression(minScoreOutcomeVar);
    responseIf.getResponseRules().add(setOutcomeValue);
    return rule;
}
Also used : Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) Lt(uk.ac.ed.ph.jqtiplus.node.expression.operator.Lt) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 54 with ResponseCondition

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition in project openolat by klemens.

the class ModalFeedbackBuilder method isCorrectSolutionRule.

public boolean isCorrectSolutionRule() {
    ResponseCondition feedbackRule = findFeedbackResponseCondition(modalFeedback.getIdentifier(), QTI21Constants.CORRECT_SOLUTION_IDENTIFIER);
    boolean allOk = findBaseValueInExpressionsOfResponseIf(feedbackRule, QTI21Constants.INCORRECT_IDENTIFIER);
    allOk |= modalFeedback.getOutcomeIdentifier() != null && QTI21Constants.CORRECT_SOLUTION_IDENTIFIER.equals(modalFeedback.getOutcomeIdentifier());
    return allOk;
}
Also used : ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Aggregations

ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)54 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)28 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)28 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)22 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)18 And (uk.ac.ed.ph.jqtiplus.node.expression.operator.And)16 Match (uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)10 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)10 ModalFeedback (uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback)8 ArrayList (java.util.ArrayList)6 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)6 Correct (uk.ac.ed.ph.jqtiplus.node.expression.general.Correct)6 Equal (uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal)6 IsNull (uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull)6 Multiple (uk.ac.ed.ph.jqtiplus.node.expression.operator.Multiple)6 Sum (uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)6 ResponseRule (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule)6 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)6 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)6 MapResponse (uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse)4