Search in sources :

Example 6 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.

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)

Example 7 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.

the class AssessmentRenderFunctions method renderRecordCardinalityValue.

public static void renderRecordCardinalityValue(StringOutput sb, Value value, String delimiter, String mappingIndicator) {
    if (value != null && value.hasCardinality(Cardinality.RECORD)) {
        RecordValue oValue = (RecordValue) value;
        boolean hasDelimiter = StringHelper.containsNonWhitespace(delimiter);
        boolean hasMappingIndicator = StringHelper.containsNonWhitespace(mappingIndicator);
        int count = 0;
        for (Map.Entry<Identifier, SingleValue> entry : oValue.entrySet()) {
            if (hasDelimiter && count++ > 0)
                sb.append(delimiter);
            String identifierString = entry.getKey().toString();
            sb.append(identifierString);
            if (hasMappingIndicator) {
                sb.append(mappingIndicator);
            }
            renderSingleCardinalityValue(sb, entry.getValue());
        }
    }
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) Map(java.util.Map)

Example 8 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.

the class HotspotInteractionStatisticsController method getSingleChoice.

private Series getSingleChoice(List<HotspotChoiceStatistics> statisticResponses) {
    boolean survey = QTIType.survey.equals(resourceResult.getType());
    int numOfParticipants = resourceResult.getQTIStatisticAssessment().getNumOfParticipants();
    List<Identifier> correctAnswers = getCorrectResponses();
    int i = 0;
    long numOfResults = 0;
    BarSeries d1 = new BarSeries();
    List<ResponseInfos> responseInfos = new ArrayList<>();
    for (HotspotChoiceStatistics statisticResponse : statisticResponses) {
        HotspotChoice choice = statisticResponse.getChoice();
        String text = getAnswerText(choice);
        double ans_count = statisticResponse.getCount();
        numOfResults += statisticResponse.getCount();
        boolean correct = correctAnswers.contains(choice.getIdentifier());
        Float points;
        String cssColor;
        if (survey) {
            points = null;
            cssColor = "bar_default";
        } else {
            Double mappedValue = CorrectResponsesUtil.getMappedValue(assessmentItem, interaction, choice);
            if (mappedValue != null) {
                points = mappedValue.floatValue();
            } else {
                points = correct ? 1.0f : 0.0f;
            }
            cssColor = correct ? "bar_green" : "bar_red";
        }
        String label = Integer.toString(++i);
        d1.add(ans_count, label, cssColor);
        responseInfos.add(new ResponseInfos(label, text, points, correct, survey, false));
    }
    if (numOfResults != numOfParticipants) {
        long notAnswered = numOfParticipants - numOfResults;
        if (notAnswered > 0) {
            String label = Integer.toString(++i);
            String text = translate("user.not.answer");
            responseInfos.add(new ResponseInfos(label, text, null, false, survey, false));
            d1.add(notAnswered, label, "bar_grey");
        }
    }
    List<BarSeries> serieList = Collections.singletonList(d1);
    Series series = new Series(serieList, responseInfos, numOfParticipants, false);
    series.setChartType(SeriesFactory.BAR_CORRECT);
    series.setItemCss("o_qti_scitem");
    return series;
}
Also used : ArrayList(java.util.ArrayList) BarSeries(org.olat.core.gui.components.chart.BarSeries) Series(org.olat.ims.qti.statistics.ui.Series) BarSeries(org.olat.core.gui.components.chart.BarSeries) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ResponseInfos(org.olat.ims.qti.statistics.ui.ResponseInfos) HotspotChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice) HotspotChoiceStatistics(org.olat.ims.qti21.model.statistics.HotspotChoiceStatistics)

Example 9 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.

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 10 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.

the class MatchScoreController method forgeScoreElement.

private void forgeScoreElement(MatchWrapper sourceWrapper, MatchWrapper targetWrapper) {
    Identifier sourceIdentifier = sourceWrapper.getChoiceIdentifier();
    Identifier targetIdentifier = targetWrapper.getChoiceIdentifier();
    DirectedPairValue dKey = new DirectedPairValue(sourceIdentifier, targetIdentifier);
    if (!scoreWrappers.containsKey(dKey)) {
        String key = sourceIdentifier.toString() + "-" + targetIdentifier.toString();
        TextElement textEl = uifactory.addTextElement(key, null, 8, "", scoreCont);
        MatchScoreWrapper scoreWrapper = new MatchScoreWrapper(sourceIdentifier, targetIdentifier, textEl);
        textEl.setDomReplacementWrapperRequired(false);
        textEl.setDisplaySize(5);
        textEl.setUserObject(scoreWrapper);
        textEl.setEnabled(!restrictedEdit && !readOnly);
        Double score = itemBuilder.getScore(sourceIdentifier, targetIdentifier);
        if (score == null) {
            textEl.setValue("0.0");
        } else {
            textEl.setValue(AssessmentHelper.getRoundedScore(score));
        }
        scoreWrappers.put(dKey, scoreWrapper);
        scoreCont.contextPut(key, scoreWrapper);
    }
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)

Aggregations

Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)208 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)62 ArrayList (java.util.ArrayList)53 HashMap (java.util.HashMap)52 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)46 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)42 Value (uk.ac.ed.ph.jqtiplus.value.Value)42 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)40 Map (java.util.Map)32 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)24 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)24 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)24 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)22 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)22 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)22 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)22 List (java.util.List)20 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)20 SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)20 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)20