use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class OrderInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
OrderInteraction orderInteraction = (OrderInteraction) interaction;
List<SimpleChoice> choices = orderInteraction.getSimpleChoices();
if (choices.size() > 0) {
String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectOrderedIdentifierResponses(item, interaction);
for (int i = 0; i < choices.size(); i++) {
String currentResponse = null;
String currentResponseText = null;
if (responses.size() > i) {
currentResponse = currentResponseText = responses.get(i);
SimpleChoice selectedChoice = orderInteraction.getSimpleChoice(Identifier.assumedLegal(currentResponse));
if (selectedChoice != null) {
currentResponseText = getContent(selectedChoice);
}
}
String correctAnswer = null;
if (correctAnswers.size() > i) {
correctAnswer = correctAnswers.get(i).toString();
}
if (correctAnswer != null && correctAnswer.equals(currentResponse)) {
dataRow.addCell(col++, currentResponseText, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, currentResponseText, null);
}
}
} else {
col++;
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class AssessmentObjectVelocityRenderDecorator method getRespondedVisibleChoices.
/*
<xsl:variable name="respondedChoiceIdentifiers" select="qw:extract-iterable-elements(qw:get-response-value(/, @responseIdentifier))" as="xs:string*"/>
<xsl:variable name="unselectedVisibleChoices" select="$visibleOrderedChoices[not(@identifier = $respondedChoiceIdentifiers)]" as="element(qti:simpleChoice)*"/>
<xsl:variable name="respondedVisibleChoices" as="element(qti:simpleChoice)*">
<xsl:for-each select="$respondedChoiceIdentifiers">
<xsl:sequence select="$thisInteraction/qti:simpleChoice[@identifier=current() and qw:is-visible(.)]"/>
</xsl:for-each>
</xsl:variable>
*/
public OrderChoices getRespondedVisibleChoices(OrderInteraction interaction) {
List<SimpleChoice> visibleChoices = getVisibleOrderedSimpleChoices(interaction);
Value responseValue = getResponseValue(interaction.getResponseIdentifier());
List<String> responseIdentifiers = new ArrayList<>();
if (responseValue instanceof ListValue) {
for (SingleValue singleValue : (ListValue) responseValue) {
responseIdentifiers.add(singleValue.toQtiString());
}
}
List<SimpleChoice> unselectedVisibleChoices = new ArrayList<>(visibleChoices);
for (Iterator<SimpleChoice> it = unselectedVisibleChoices.iterator(); it.hasNext(); ) {
SimpleChoice choice = it.next();
if (responseIdentifiers.contains(choice.getIdentifier().toString())) {
it.remove();
}
}
List<SimpleChoice> respondedVisibleChoices = new ArrayList<>();
for (String responseIdentifier : responseIdentifiers) {
for (SimpleChoice visibleChoice : visibleChoices) {
if (responseIdentifier.equals(visibleChoice.getIdentifier().toString())) {
respondedVisibleChoices.add(visibleChoice);
}
}
}
return new OrderChoices(respondedVisibleChoices, unselectedVisibleChoices);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class CSVToAssessmentItemConverter method processChoice_smc.
private void processChoice_smc(String[] parts, SimpleChoiceAssessmentItemBuilder choiceBuilder) {
double point = parseFloat(parts[0], 1.0f);
String content = parts[1];
ChoiceInteraction interaction = choiceBuilder.getChoiceInteraction();
SimpleChoice newChoice = AssessmentItemFactory.createSimpleChoice(interaction, content, choiceBuilder.getQuestionType().getPrefix());
choiceBuilder.addSimpleChoice(newChoice);
choiceBuilder.setMapping(newChoice.getIdentifier(), point);
if (point > 0.0) {
if (choiceBuilder instanceof MultipleChoiceAssessmentItemBuilder) {
((MultipleChoiceAssessmentItemBuilder) choiceBuilder).addCorrectAnswer(newChoice.getIdentifier());
} else {
((SingleChoiceAssessmentItemBuilder) choiceBuilder).setCorrectAnswer(newChoice.getIdentifier());
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project openolat by klemens.
the class SingleChoiceAssessmentItemBuilder method buildItemBody.
@Override
protected void buildItemBody() {
// remove current blocks
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
blocks.clear();
// add question
getHtmlHelper().appendHtml(assessmentItem.getItemBody(), question);
// add interaction
ChoiceInteraction singleChoiceInteraction = AssessmentItemFactory.createSingleChoiceInteraction(assessmentItem, responseIdentifier, orientation, cssClass);
singleChoiceInteraction.setShuffle(isShuffle());
blocks.add(singleChoiceInteraction);
List<SimpleChoice> choiceList = getChoices();
singleChoiceInteraction.getSimpleChoices().addAll(choiceList);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project openolat by klemens.
the class QTI12To21Converter method convertMultipleChoice.
private AssessmentItemBuilder convertMultipleChoice(Item item) {
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
itemBuilder.clearMapping();
itemBuilder.clearSimpleChoices();
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
convertOrientation(question, itemBuilder);
boolean hasNegative = false;
List<Response> responses = question.getResponses();
for (Response response : responses) {
if (response.getPoints() < 0.0f) {
hasNegative = true;
}
}
boolean singleCorrect = question.isSingleCorrect();
Map<String, Identifier> identToIdentifier = new HashMap<>();
for (Response response : responses) {
String responseText = response.getContent().renderAsHtmlForEditor();
responseText = blockedHtml(responseText);
SimpleChoice newChoice;
if (StringHelper.isHtml(responseText)) {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, "", itemBuilder.getQuestionType().getPrefix());
htmlBuilder.appendHtml(newChoice, responseText);
} else {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, responseText, itemBuilder.getQuestionType().getPrefix());
}
itemBuilder.addSimpleChoice(newChoice);
identToIdentifier.put(response.getIdent(), newChoice.getIdentifier());
double score = response.getPoints();
if (singleCorrect) {
if (response.isCorrect()) {
itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
}
if (score > 0.0f) {
itemBuilder.setMaxScore(score);
}
} else {
if ((hasNegative && response.getPoints() >= 0.0f) || (!hasNegative && response.getPoints() > 0.0f)) {
itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
}
itemBuilder.setMapping(newChoice.getIdentifier(), score);
}
}
convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
if (singleCorrect) {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
} else {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
if (question instanceof ChoiceQuestion) {
ChoiceQuestion choice = (ChoiceQuestion) question;
itemBuilder.setMinScore(new Double(choice.getMinValue()));
itemBuilder.setMaxScore(new Double(choice.getMaxValue()));
}
}
return itemBuilder;
}
Aggregations