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());
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations