Search in sources :

Example 11 with SimpleChoice

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;
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) OrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.OrderInteraction)

Example 12 with SimpleChoice

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);
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) AssessmentRenderFunctions.renderValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) FileValue(uk.ac.ed.ph.jqtiplus.value.FileValue) ArrayList(java.util.ArrayList)

Example 13 with SimpleChoice

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());
        }
    }
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)

Example 14 with SimpleChoice

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);
}
Also used : AssessmentItemFactory.appendSimpleChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendSimpleChoice) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssessmentItemFactory.appendChoiceInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction)

Example 15 with SimpleChoice

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;
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) HashMap(java.util.HashMap) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Aggregations

SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)54 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)32 Test (org.junit.Test)16 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)16 ArrayList (java.util.ArrayList)14 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)14 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)14 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)14 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)14 URL (java.net.URL)12 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)12 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)12 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)10 HashMap (java.util.HashMap)8 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)8 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)8 Value (uk.ac.ed.ph.jqtiplus.value.Value)6 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)5 IOException (java.io.IOException)4 Map (java.util.Map)4