Search in sources :

Example 41 with Value

use of uk.ac.ed.ph.jqtiplus.value.Value in project openolat by klemens.

the class AssessmentRenderFunctions method testFeedbackVisible.

public static final boolean testFeedbackVisible(TestFeedback testFeedback, TestSessionState testSessionState) {
    // <xsl:variable name="identifierMatch" select="boolean(qw:value-contains(qw:get-test-outcome-value(@outcomeIdentifier), @identifier))" as="xs:boolean"/>
    Identifier outcomeIdentifier = testFeedback.getOutcomeIdentifier();
    Value outcomeValue = testSessionState.getOutcomeValue(outcomeIdentifier);
    boolean identifierMatch = valueContains(outcomeValue, testFeedback.getOutcomeValue());
    // <xsl:if test="($identifierMatch and @showHide='show') or (not($identifierMatch) and @showHide='hide')">
    if ((identifierMatch && testFeedback.getVisibilityMode() == VisibilityMode.SHOW_IF_MATCH) || (!identifierMatch && testFeedback.getVisibilityMode() == VisibilityMode.HIDE_IF_MATCH)) {
        return true;
    }
    return false;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) DurationValue(uk.ac.ed.ph.jqtiplus.value.DurationValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) BooleanValue(uk.ac.ed.ph.jqtiplus.value.BooleanValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) FileValue(uk.ac.ed.ph.jqtiplus.value.FileValue)

Example 42 with Value

use of uk.ac.ed.ph.jqtiplus.value.Value in project OpenOLAT by OpenOLAT.

the class HottextAssessmentItemBuilderTest method createHottextAssessmentItem_allCorrectAnswers.

/**
 * A basic hottextInteraction with three choices. If all answers
 * are correct, the SCORE is 3.0.
 *
 * @throws IOException
 */
@Test
public void createHottextAssessmentItem_allCorrectAnswers() throws IOException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder("Hot texts", "This is a hot ", "text", qtiSerializer);
    itemBuilder.setQuestion("<p>This is <hottext identifier=\"RESPONSE_HOT_1\">hot</hottext>, <hottext identifier=\"RESPONSE_HOT_2\">cold</hottext> or <hottext identifier=\"RESPONSE_HOT_3\">freezing</hottext></p>");
    itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_2"));
    itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_3"));
    itemBuilder.setMaxScore(3.0d);
    itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
    itemBuilder.build();
    File itemFile = new File(WebappHelper.getTmpDir(), "hottextAssessmentItem" + 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("RESPONSE_HOT_2", "RESPONSE_HOT_3"));
        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("RESPONSE_HOT_1"));
        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());
}
Also used : HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) FileOutputStream(java.io.FileOutputStream) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 43 with Value

use of uk.ac.ed.ph.jqtiplus.value.Value in project OpenOLAT by OpenOLAT.

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());
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) ArrayList(java.util.ArrayList) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) FileOutputStream(java.io.FileOutputStream) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 44 with Value

use of uk.ac.ed.ph.jqtiplus.value.Value in project OpenOLAT by OpenOLAT.

the class CorrectResponsesUtil method getCorrectIntegerResponses.

public static final List<Integer> getCorrectIntegerResponses(AssessmentItem assessmentItem, Interaction interaction) {
    List<Integer> correctAnswers = new ArrayList<>(5);
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.SINGLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
            if (value instanceof IntegerValue) {
                IntegerValue identifierValue = (IntegerValue) value;
                correctAnswers.add(identifierValue.intValue());
            }
        } else if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                for (SingleValue sValue : multiValue.getAll()) {
                    if (sValue instanceof IntegerValue) {
                        IntegerValue identifierValue = (IntegerValue) value;
                        correctAnswers.add(identifierValue.intValue());
                    }
                }
            }
        }
    }
    return correctAnswers;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 45 with Value

use of uk.ac.ed.ph.jqtiplus.value.Value in project OpenOLAT by OpenOLAT.

the class AssessmentTestDisplayController method processOutcomeVariables.

private void processOutcomeVariables(TestResult resultNode, TestPlanInfos testPlanInfos, boolean submit) {
    Float score = null;
    Boolean pass = null;
    double completion = testPlanInfos.getCompletion();
    for (final ItemVariable itemVariable : resultNode.getItemVariables()) {
        if (itemVariable instanceof OutcomeVariable) {
            OutcomeVariable outcomeVariable = (OutcomeVariable) itemVariable;
            Identifier identifier = outcomeVariable.getIdentifier();
            if (QTI21Constants.SCORE_IDENTIFIER.equals(identifier)) {
                Value value = itemVariable.getComputedValue();
                if (value instanceof NumberValue) {
                    score = (float) ((NumberValue) value).doubleValue();
                }
            } else if (QTI21Constants.PASS_IDENTIFIER.equals(identifier)) {
                Value value = itemVariable.getComputedValue();
                if (value instanceof BooleanValue) {
                    pass = ((BooleanValue) value).booleanValue();
                }
            }
        }
    }
    if (submit) {
        outcomesListener.submit(score, pass, completion, candidateSession.getKey());
    } else if (candidateSession != null && candidateSession.getFinishTime() == null) {
        // don't change the outcome if the test is finished
        outcomesListener.updateOutcomes(score, pass, completion);
    }
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) NumberValue(uk.ac.ed.ph.jqtiplus.value.NumberValue) BooleanValue(uk.ac.ed.ph.jqtiplus.value.BooleanValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) NumberValue(uk.ac.ed.ph.jqtiplus.value.NumberValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) BooleanValue(uk.ac.ed.ph.jqtiplus.value.BooleanValue) ItemVariable(uk.ac.ed.ph.jqtiplus.node.result.ItemVariable) OutcomeVariable(uk.ac.ed.ph.jqtiplus.node.result.OutcomeVariable)

Aggregations

Value (uk.ac.ed.ph.jqtiplus.value.Value)70 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)46 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)34 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)32 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)32 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)30 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)28 OrderedValue (uk.ac.ed.ph.jqtiplus.value.OrderedValue)24 NullValue (uk.ac.ed.ph.jqtiplus.value.NullValue)18 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)16 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)16 BooleanValue (uk.ac.ed.ph.jqtiplus.value.BooleanValue)16 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)14 ArrayList (java.util.ArrayList)12 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)12 Test (org.junit.Test)11 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)10 File (java.io.File)8 IOException (java.io.IOException)8 AssessmentRenderFunctions.contentAsString (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)8