Search in sources :

Example 51 with Value

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

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 52 with Value

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

the class AssessmentRenderFunctions method getResponseValueAsBase64.

public static String getResponseValueAsBase64(AssessmentItem assessmentItem, AssessmentTestSession candidateSession, ItemSessionState itemSessionState, Identifier identifier, boolean solutionMode) {
    Value val = getResponseValue(assessmentItem, itemSessionState, identifier, solutionMode);
    String encodedString = null;
    if (val instanceof FileValue) {
        FileValue fileValue = (FileValue) val;
        File myStore = CoreSpringFactory.getImpl(AssessmentTestSessionDAO.class).getSessionStorage(candidateSession);
        File submissionDir = new File(myStore, "submissions");
        File submittedFile = new File(submissionDir, fileValue.getFileName());
        try (InputStream inStream = new FileInputStream(submittedFile)) {
            byte[] binaryData = IOUtils.toByteArray(inStream);
            encodedString = new String(Base64.encodeBase64(binaryData), "UTF8");
        } catch (Exception e) {
            log.error("", e);
        }
    }
    return encodedString;
}
Also used : FileValue(uk.ac.ed.ph.jqtiplus.value.FileValue) AssessmentTestSessionDAO(org.olat.ims.qti21.manager.AssessmentTestSessionDAO) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) 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) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 53 with Value

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

the class SingleChoiceAssessmentItemBuilder method extract.

@Override
public void extract() {
    super.extract();
    if (choiceInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
            CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
            if (value instanceof IdentifierValue) {
                IdentifierValue identifierValue = (IdentifierValue) value;
                correctAnswer = identifierValue.identifierValue();
            }
        }
    }
}
Also used : BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) AssessmentItemFactory.createSingleChoiceCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSingleChoiceCorrectResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 54 with Value

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

the class MaximaOperator method evaluateSelf.

@Override
protected Value evaluateSelf(OpenOLATExtensionPackage jqtiExtensionPackage, ProcessingContext context, Value[] childValues, int depth) {
    AttributeList attributes = getAttributes();
    Attribute<?> attrValue = attributes.get("value");
    String code = (String) attrValue.getValue();
    log.debug("Performing scriptRule: code={}, simplify={}" + code);
    /* Pass variables to Maxima */
    final QtiMaximaProcess qtiMaximaProcess = jqtiExtensionPackage.obtainMaximaSessionForThread();
    for (int i = 0; i < childValues.length; i++) {
        Value childValue = childValues[i];
        String val = getValue(childValue);
        code = code.replace("$(" + (i + 1) + ")", val);
    }
    /* Run code */
    log.debug("Executing scriptRule code");
    try {
        qtiMaximaProcess.executeScriptRule(code, true);
    } catch (final MaximaTimeoutException e) {
        context.fireRuntimeError(this, "A timeout occurred executing the ScriptRule logic. Not setting QTI variables and returing FALSE");
        return BooleanValue.FALSE;
    } catch (final RuntimeException e) {
        context.fireRuntimeError(this, "An unexpected problem occurred while trying to run the scriptRule logic. Not setting QTI variables and returing FALSE");
        return BooleanValue.FALSE;
    }
    /* Read variables back */
    log.debug("Reading variables back from Maxima");
    /* Run Maxima code and extract result */
    log.info("Running code to determine result of MAXIMA operator");
    final Class<? extends ValueWrapper> resultClass = GlueValueBinder.getCasReturnClass(ReturnTypeType.FLOAT);
    ValueWrapper maximaResult;
    try {
        maximaResult = qtiMaximaProcess.executeCasProcess(code, true, resultClass);
    } catch (final MaximaTimeoutException e) {
        context.fireRuntimeError(this, "A timeout occurred executing the CasCondition logic. Returning NULL");
        return NullValue.INSTANCE;
    } catch (final MathsContentTooComplexException e) {
        context.fireRuntimeError(this, "An unexpected problem occurred querying the result of CasProcess, so returning NULL");
        return NullValue.INSTANCE;
    } catch (final MathAssessBadCasCodeException e) {
        context.fireRuntimeError(this, "Your CasProcess code did not work as expected. The CAS input was '" + e.getMaximaInput() + "' and the CAS output was '" + e.getMaximaOutput() + "'. The failure reason was: " + e.getReason());
        return NullValue.INSTANCE;
    } catch (final QtiMaximaTypeConversionException e) {
        context.fireRuntimeError(this, "Your CasProcess code did not produce a result that could be converted into the required QTI type. The CAS input was '" + e.getMaximaInput() + "' and the CAS output was '" + e.getMaximaOutput() + "'");
        return NullValue.INSTANCE;
    } catch (final RuntimeException e) {
        log.warn("Unexpected Maxima failure", e);
        context.fireRuntimeError(this, "An unexpected problem occurred while executing this CasProcess");
        return BooleanValue.FALSE;
    }
    /* Bind result */
    Value result = GlueValueBinder.casToJqti(maximaResult);
    if (result == null) {
        context.fireRuntimeError(this, "Failed to convert result from Maxima back to a QTI variable - returning NULL");
        return NullValue.INSTANCE;
    }
    return result;
}
Also used : QtiMaximaProcess(uk.ac.ed.ph.qtiworks.mathassess.glue.maxima.QtiMaximaProcess) ValueWrapper(uk.ac.ed.ph.qtiworks.mathassess.glue.types.ValueWrapper) MathsContentTooComplexException(uk.ac.ed.ph.qtiworks.mathassess.glue.MathsContentTooComplexException) AttributeList(uk.ac.ed.ph.jqtiplus.attribute.AttributeList) MathAssessBadCasCodeException(uk.ac.ed.ph.qtiworks.mathassess.glue.MathAssessBadCasCodeException) QtiMaximaTypeConversionException(uk.ac.ed.ph.qtiworks.mathassess.glue.maxima.QtiMaximaTypeConversionException) BooleanValue(uk.ac.ed.ph.jqtiplus.value.BooleanValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) MaximaTimeoutException(uk.ac.ed.ph.jacomax.MaximaTimeoutException)

Example 55 with Value

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

the class HottextAssessmentItemBuilderTest method createHottextAssessmentItem_perAnswer.

/**
 * This is an hottextInteraction with 3 choices, one with 3.0 points and correct,
 * one with 0.0 points but correct and one false with -1.0 points.
 *
 * @throws IOException
 */
@Test
public void createHottextAssessmentItem_perAnswer() 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.setMapping(Identifier.parseString("RESPONSE_HOT_1"), -1.0d);
    itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_2"), 0.0d);
    itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_3"), 3.0d);
    itemBuilder.setMaxScore(3.0d);
    itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
    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);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.CORRECT_IDENTIFIER), feedbackBasic);
    }
    {
        // max score but not all correct
        Map<Identifier, ResponseData> responseMap = new HashMap<>();
        Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
        responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_3"));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(3.0d), score);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
    }
    {
        // all wrong
        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);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
    }
    FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
Also used : HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) 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)

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