Search in sources :

Example 71 with ResponseDeclaration

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

the class AssessmentObjectComponentRenderer method renderExtendedTextBox.

/*
	  <xsl:template match="qti:extendedTextInteraction" mode="multibox">
	    <xsl:param name="responseInput" as="element(qw:responseInput)?"/>
	    <xsl:param name="checkJavaScript" as="xs:string?"/>
	    <xsl:param name="stringsCount" as="xs:integer"/>
	    <xsl:param name="allowCreate" select="false()" as="xs:boolean"/>
	    <xsl:variable name="interaction" select="." as="element(qti:extendedTextInteraction)"/>
	    <xsl:for-each select="1 to $stringsCount">
	      <xsl:variable name="i" select="." as="xs:integer"/>
	      <xsl:apply-templates select="$interaction" mode="singlebox">
	        <xsl:with-param name="responseInputString" select="$responseInput/qw:string[position()=$i]"/>
	        <xsl:with-param name="checkJavaScript" select="$checkJavaScript"/>
	        <xsl:with-param name="allowCreate" select="$allowCreate and $i=$stringsCount"/>
	      </xsl:apply-templates>
	      <br />
	    </xsl:for-each>
	  </xsl:template>
	  
	  <xsl:template match="qti:extendedTextInteraction" mode="singlebox">
	    <xsl:param name="responseInputString" as="xs:string?"/>
	    <xsl:param name="checkJavaScript" as="xs:string?"/>
	    <xsl:param name="allowCreate" select="false()" as="xs:boolean"/>
	    <xsl:variable name="is-bad-response" select="qw:is-bad-response(@responseIdentifier)" as="xs:boolean"/>
	    <xsl:variable name="is-invalid-response" select="qw:is-invalid-response(@responseIdentifier)" as="xs:boolean"/>
	    <textarea cols="72" rows="6" name="qtiworks_response_{@responseIdentifier}">
	      <xsl:if test="$isItemSessionEnded">
	        <xsl:attribute name="disabled">disabled</xsl:attribute>
	      </xsl:if>
	      <xsl:if test="$is-bad-response or $is-invalid-response">
	        <xsl:attribute name="class" select="'badResponse'"/>
	      </xsl:if>
	      <xsl:if test="@expectedLines">
	        <xsl:attribute name="rows" select="@expectedLines"/>
	      </xsl:if>
	      <xsl:if test="@expectedLines and @expectedLength">
	        <xsl:attribute name="cols" select="ceiling(@expectedLength div @expectedLines)"/>
	      </xsl:if>
	      <xsl:if test="$checkJavaScript">
	        <xsl:attribute name="onchange" select="$checkJavaScript"/>
	      </xsl:if>
	      <xsl:if test="$allowCreate">
	        <xsl:attribute name="onkeyup" select="'QtiWorksRendering.addNewTextBox(this)'"/>
	      </xsl:if>
	      <xsl:value-of select="$responseInputString"/>
	    </textarea>
	  </xsl:template>
	*/
protected void renderExtendedTextBox(AssessmentRenderer renderer, StringOutput sb, AssessmentObjectComponent component, AssessmentItem assessmentItem, ItemSessionState itemSessionState, ExtendedTextInteraction interaction, String responseInputString) {
    String responseUniqueId = component.getResponseUniqueIdentifier(itemSessionState, interaction);
    boolean ended = component.isItemSessionEnded(itemSessionState, renderer.isSolutionMode());
    int expectedLines = interaction.getExpectedLines() == null ? 6 : interaction.getExpectedLines().intValue();
    if (ended) {
        sb.append("<div id='oo_").append(responseUniqueId).append("' style='min-height:").append(expectedLines * 1.5).append("em;' class='form-control textarea_disabled o_disabled o_form_element_disabled");
    } else {
        sb.append("<textarea id='oo_").append(responseUniqueId).append("' name='qtiworks_response_").append(responseUniqueId).append("'");
        if (StringHelper.containsNonWhitespace(interaction.getPlaceholderText())) {
            sb.append(" placeholder=\"").append(StringHelper.escapeHtml(interaction.getPlaceholderText())).append("\"");
        }
        sb.append(" rows='").append(expectedLines).append("'");
        if (interaction.getExpectedLength() == null) {
            sb.append(" cols='72'");
        } else {
            int cols = interaction.getExpectedLength().intValue() / expectedLines;
            sb.append(" cols='").append(cols).append("'");
        }
        ResponseDeclaration responseDeclaration = getResponseDeclaration(assessmentItem, interaction.getResponseIdentifier());
        String checkJavascript = checkJavaScript(responseDeclaration, interaction.getPatternMask());
        if (StringHelper.containsNonWhitespace(checkJavascript)) {
            sb.append(" onchange=\"").append(checkJavascript).append("\"");
        }
        sb.append(" class='form-control");
    }
    if (isBadResponse(itemSessionState, interaction.getResponseIdentifier()) || isInvalidResponse(itemSessionState, interaction.getResponseIdentifier())) {
        sb.append(" badResponse");
    }
    sb.append("'>");
    if (renderer.isSolutionMode()) {
        String placeholder = interaction.getPlaceholderText();
        if (StringHelper.containsNonWhitespace(placeholder)) {
            sb.append(placeholder);
        }
    } else if (StringHelper.containsNonWhitespace(responseInputString)) {
        sb.append(responseInputString);
    }
    if (ended) {
        sb.append("</div>");
    } else {
        sb.append("</textarea>");
        FormJSHelper.appendFlexiFormDirty(sb, component.getQtiItem().getRootForm(), "oo_" + responseUniqueId);
        sb.append(FormJSHelper.getJSStartWithVarDeclaration("oo_" + responseUniqueId)).append("oo_").append(responseUniqueId).append(".on('keypress', function(event, target){if (13 == event.keyCode) {event.stopPropagation()} })").append(FormJSHelper.getJSEnd());
        Form form = component.getQtiItem().getRootForm();
        sb.append(FormJSHelper.getJSStart()).append("jQuery(function() {\n").append(" jQuery('#").append("oo_").append(responseUniqueId).append("').qtiAutosave({\n").append("  responseUniqueId:'").append(responseUniqueId).append("',\n").append("  formName:'").append(form.getFormName()).append("',\n").append("  dispIdField:'").append(form.getDispatchFieldId()).append("',\n").append("  dispId:'").append(component.getQtiItem().getFormDispatchId()).append("',\n").append("  eventIdField:'").append(form.getEventFieldId()).append("'\n").append(" }).tabOverride();\n").append("})\n").append(FormJSHelper.getJSEnd());
    }
}
Also used : Form(org.olat.core.gui.components.form.flexible.impl.Form) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentRenderFunctions.getResponseDeclaration(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getResponseDeclaration)

Example 72 with ResponseDeclaration

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

the class AssessmentObjectVelocityRenderDecorator method getSliderOptions.

/*
	<xsl:variable name="is-discrete" select="qw:get-response-declaration(/, @responseIdentifier)/@baseType='integer'" as="xs:boolean"/>
    <xsl:variable name="min" select="if ($is-discrete) then string(floor(@lowerBound)) else string(@lowerBound)" as="xs:string"/>
    <xsl:variable name="max" select="if ($is-discrete) then string(ceiling(@upperBound)) else string(@upperBound)" as="xs:string"/>
    <xsl:variable name="step" select="if (@step) then @step else if ($is-discrete) then '1' else '0.01'" as="xs:string"/>
    <xsl:value-of select="if (@reverse) then @reverse else 'false'"/>
    */
public SliderOptions getSliderOptions(SliderInteraction interaction) {
    ResponseDeclaration responseDeclaration = getResponseDeclaration(interaction.getResponseIdentifier());
    boolean discrete = responseDeclaration.hasBaseType(BaseType.INTEGER);
    boolean reverse = interaction.getReverse() == null ? false : interaction.getReverse().booleanValue();
    String step;
    if (interaction.getStep() != null) {
        step = Integer.toString(interaction.getStep().intValue());
    } else {
        step = discrete ? "1" : "0.01";
    }
    String min;
    String max;
    if (discrete) {
        min = Long.toString(java.lang.Math.round(java.lang.Math.floor(interaction.getLowerBound())));
        max = Long.toString(java.lang.Math.round(java.lang.Math.ceil(interaction.getUpperBound())));
    } else {
        min = Long.toString(java.lang.Math.round(interaction.getLowerBound()));
        max = Long.toString(java.lang.Math.round(interaction.getUpperBound()));
    }
    return new SliderOptions(discrete, reverse, min, max, step);
}
Also used : ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 73 with ResponseDeclaration

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

the class HotspotInteractionStatisticsController method getCorrectResponses.

private List<Identifier> getCorrectResponses() {
    List<Identifier> correctAnswers = new ArrayList<>();
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        extractIdentifiersFromCorrectResponse(responseDeclaration.getCorrectResponse(), correctAnswers);
    }
    return correctAnswers;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ArrayList(java.util.ArrayList) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 74 with ResponseDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration 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 75 with ResponseDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.

the class QTI21StatisticsManagerImpl method getTextEntryInteractionsStatistic.

@Override
public List<AbstractTextEntryInteractionStatistics> getTextEntryInteractionsStatistic(String itemRefIdent, AssessmentItem item, List<TextEntryInteraction> interactions, QTI21StatisticSearchParams searchParams) {
    List<AbstractTextEntryInteractionStatistics> options = new ArrayList<>();
    Map<String, AbstractTextEntryInteractionStatistics> optionMap = new HashMap<>();
    for (TextEntryInteraction interaction : interactions) {
        Identifier responseIdentifier = interaction.getResponseIdentifier();
        ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
        if (responseDeclaration.hasBaseType(BaseType.STRING)) {
            TextEntryInteractionStatistics stats = getTextEntryInteractionSettings(responseIdentifier, responseDeclaration);
            optionMap.put(responseIdentifier.toString(), stats);
            options.add(stats);
        } else if (responseDeclaration.hasBaseType(BaseType.FLOAT)) {
            NumericalInputInteractionStatistics stats = getNumericalInputInteractionSettings(responseIdentifier, responseDeclaration, item);
            optionMap.put(responseIdentifier.toString(), stats);
            options.add(stats);
        }
    }
    for (TextEntryInteraction interaction : interactions) {
        String responseIdentifier = interaction.getResponseIdentifier().toString();
        List<RawData> datas = getRawDatas(itemRefIdent, responseIdentifier, searchParams);
        for (RawData data : datas) {
            Long count = data.getCount();
            if (count != null && count.longValue() > 0) {
                AbstractTextEntryInteractionStatistics stats = optionMap.get(responseIdentifier);
                String response = data.getStringuifiedResponse();
                if (response != null && response.length() >= 2 && response.startsWith("[") && response.endsWith("]")) {
                    response = response.substring(1, response.length() - 1);
                }
                if (stats.matchResponse(response)) {
                    stats.addCorrect(count.longValue());
                } else {
                    stats.addIncorrect(count.longValue());
                    stats.addWrongResponses(response);
                }
            }
        }
    }
    return options;
}
Also used : TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractTextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.AbstractTextEntryInteractionStatistics) TextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.TextEntryInteractionStatistics) AbstractTextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.AbstractTextEntryInteractionStatistics) NumericalInputInteractionStatistics(org.olat.ims.qti21.model.statistics.NumericalInputInteractionStatistics) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Aggregations

ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)132 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)54 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)40 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)36 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)28 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)28 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)24 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)24 ArrayList (java.util.ArrayList)22 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)22 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)22 AssessmentItemFactory.appendDefaultItemBody (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody)20 AssessmentItemFactory.createResponseProcessing (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing)20 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)18 Value (uk.ac.ed.ph.jqtiplus.value.Value)16 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)14 HashMap (java.util.HashMap)12 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)12 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)12 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)10