Search in sources :

Example 16 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project openolat by klemens.

the class QTI12To21Converter method convertKPrim.

private AssessmentItemBuilder convertKPrim(Item item) {
    KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
    convertItemBasics(item, itemBuilder);
    Question question = item.getQuestion();
    itemBuilder.setShuffle(question.isShuffle());
    List<Response> responses = question.getResponses();
    List<SimpleAssociableChoice> choices = itemBuilder.getKprimChoices();
    for (int i = 0; i < 4; i++) {
        Response response = responses.get(i);
        SimpleAssociableChoice choice = choices.get(i);
        String answer = response.getContent().renderAsHtmlForEditor();
        answer = blockedHtml(answer);
        if (StringHelper.isHtml(answer)) {
            htmlBuilder.appendHtml(choice, answer);
        } else {
            P firstChoiceText = AssessmentItemFactory.getParagraph(choice, answer);
            choice.getFlowStatics().clear();
            choice.getFlowStatics().add(firstChoiceText);
        }
        if (response.isCorrect()) {
            itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.CORRECT_IDENTIFIER);
        } else {
            itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
        }
    }
    double score = question.getMaxValue();
    itemBuilder.setMinScore(0.0d);
    itemBuilder.setMaxScore(score);
    return itemBuilder;
}
Also used : 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) P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) 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)

Example 17 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project openolat by klemens.

the class QTI21StatisticsManagerImpl method getMatchStatistics.

@Override
public List<MatchStatistics> getMatchStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
    List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
    SimpleMatchSet sourceMatchSets = interaction.getSimpleMatchSets().get(0);
    SimpleMatchSet targetMatchSets = interaction.getSimpleMatchSets().get(1);
    List<MatchStatistics> matchPoints = new ArrayList<>();
    ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
    // readable responses
    Map<Identifier, List<Identifier>> associations = new HashMap<>();
    CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
    QtiNodesExtractor.extractIdentifiersFromCorrectResponse(correctResponse, associations);
    for (SimpleAssociableChoice sourceChoice : sourceMatchSets.getSimpleAssociableChoices()) {
        for (SimpleAssociableChoice targetChoice : targetMatchSets.getSimpleAssociableChoices()) {
            DirectedPairValue dKey = new DirectedPairValue(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
            String choiceIdentifier = dKey.toQtiString();
            String marker = "[" + choiceIdentifier + "]";
            boolean correct = associations.containsKey(sourceChoice.getIdentifier()) && associations.get(sourceChoice.getIdentifier()).contains(targetChoice.getIdentifier());
            long numCorrect = 0;
            long numIncorrect = 0;
            for (RawData rawData : rawDatas) {
                String response = rawData.getStringuifiedResponse();
                if (response.indexOf(marker) >= 0) {
                    if (correct) {
                        numCorrect += rawData.getCount();
                    } else {
                        numIncorrect += rawData.getCount();
                    }
                }
            }
            matchPoints.add(new MatchStatistics(sourceChoice.getIdentifier(), targetChoice.getIdentifier(), numCorrect, numIncorrect));
        }
    }
    return matchPoints;
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) MatchStatistics(org.olat.ims.qti21.model.statistics.MatchStatistics) List(java.util.List) ArrayList(java.util.ArrayList) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 18 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project openolat by klemens.

the class QTI21StatisticsManagerImpl method getKPrimStatistics.

// stringuifiedResponse: [a93247453265982 correct][b93247453265983 correct][c93247453265984 correct][d93247453265985 correct]
@Override
public List<KPrimStatistics> getKPrimStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
    List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
    List<SimpleMatchSet> matchSets = interaction.getSimpleMatchSets();
    List<KPrimStatistics> kprimPoints = new ArrayList<>();
    SimpleMatchSet fourMatchSet = matchSets.get(0);
    ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
    // readable responses
    Set<String> rightResponses = new HashSet<>();
    List<MapEntry> mapEntries = responseDeclaration.getMapping().getMapEntries();
    for (MapEntry mapEntry : mapEntries) {
        SingleValue mapKey = mapEntry.getMapKey();
        if (mapKey instanceof DirectedPairValue) {
            DirectedPairValue pairValue = (DirectedPairValue) mapKey;
            String source = pairValue.sourceValue().toString();
            String destination = pairValue.destValue().toString();
            rightResponses.add("[" + source + " " + destination + "]");
        }
    }
    for (SimpleAssociableChoice choice : fourMatchSet.getSimpleAssociableChoices()) {
        String choiceIdentifier = choice.getIdentifier().toString();
        String markerCorrect = "[" + choiceIdentifier + " correct]";
        String markerWrong = "[" + choiceIdentifier + " wrong]";
        boolean isCorrectRight = rightResponses.contains(markerCorrect);
        String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
        String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
        long numCorrect = 0;
        long numIncorrect = 0;
        long numUnanswered = 0;
        for (RawData rawData : rawDatas) {
            String response = rawData.getStringuifiedResponse();
            if (response.indexOf(rightFlag) >= 0) {
                numCorrect += rawData.getCount();
            } else if (response.indexOf(wrongFlag) >= 0) {
                numIncorrect += rawData.getCount();
            } else {
                numUnanswered += rawData.getCount();
            }
        }
        kprimPoints.add(new KPrimStatistics(choice.getIdentifier(), isCorrectRight, numCorrect, numIncorrect, numUnanswered));
    }
    return kprimPoints;
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ArrayList(java.util.ArrayList) KPrimStatistics(org.olat.ims.qti21.model.statistics.KPrimStatistics) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) HashSet(java.util.HashSet)

Example 19 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project openolat by klemens.

the class MatchInteractionArchive method writeInteractionData.

@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
    MatchInteraction matchInteraction = (MatchInteraction) interaction;
    String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
    if (!StringHelper.containsNonWhitespace(stringuifiedResponse)) {
        col += matchInteraction.getSimpleMatchSets().get(0).getSimpleAssociableChoices().size();
    } else {
        boolean kprim = matchInteraction.getResponseIdentifier().toString().startsWith("KPRIM_") || QTI21QuestionType.hasClass(matchInteraction, QTI21Constants.CSS_MATCH_KPRIM);
        Set<String> correctAnswers = CorrectResponsesUtil.getCorrectDirectPairResponses(item, matchInteraction, false);
        List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
        SimpleMatchSet firstMatchSet = matchInteraction.getSimpleMatchSets().get(0);
        SimpleMatchSet secondMatchSet = matchInteraction.getSimpleMatchSets().get(1);
        for (SimpleAssociableChoice choice : firstMatchSet.getSimpleAssociableChoices()) {
            String choiceIdentifier = choice.getIdentifier().toString();
            if (kprim) {
                String markerCorrect = choiceIdentifier + " correct";
                String markerWrong = choiceIdentifier + " wrong";
                boolean isCorrectRight = correctAnswers.contains(markerCorrect);
                String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
                String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
                String value = null;
                if (stringuifiedResponse.contains(markerCorrect)) {
                    value = "+";
                } else if (stringuifiedResponse.contains(markerWrong)) {
                    value = "-";
                }
                if (stringuifiedResponse.indexOf(rightFlag) >= 0) {
                    dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
                } else if (stringuifiedResponse.indexOf(wrongFlag) >= 0) {
                    dataRow.addCell(col++, value, null);
                } else {
                    col++;
                }
            } else {
                String aResponse = null;
                for (String r : responses) {
                    if (r.startsWith(choiceIdentifier)) {
                        aResponse = r;
                    }
                }
                if (StringHelper.containsNonWhitespace(aResponse)) {
                    boolean correct = correctAnswers.contains(aResponse);
                    String value = null;
                    for (SimpleAssociableChoice association : secondMatchSet.getSimpleAssociableChoices()) {
                        if (aResponse.endsWith(association.getIdentifier().toString())) {
                            value = getContent(association);
                            break;
                        }
                    }
                    if (correct) {
                        dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
                    } else {
                        dataRow.addCell(col++, value, null);
                    }
                } else {
                    col++;
                }
            }
        }
    }
    return col;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)

Example 20 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project openolat by klemens.

the class AssessmentObjectVelocityRenderDecorator method getVisibleOrderedChoices.

public List<SimpleAssociableChoice> getVisibleOrderedChoices(MatchInteraction interaction, int pos) {
    try {
        List<SimpleAssociableChoice> choices;
        if (interaction.getShuffle()) {
            List<Identifier> choiceOrders = itemSessionState.getShuffledInteractionChoiceOrder(interaction.getResponseIdentifier());
            Map<Identifier, SimpleAssociableChoice> idTochoice = new HashMap<>();
            List<SimpleAssociableChoice> allChoices = interaction.getSimpleMatchSets().get(pos).getSimpleAssociableChoices();
            for (SimpleAssociableChoice allChoice : allChoices) {
                idTochoice.put(allChoice.getIdentifier(), allChoice);
            }
            choices = new ArrayList<>();
            for (Identifier choiceOrder : choiceOrders) {
                SimpleAssociableChoice choice = idTochoice.get(choiceOrder);
                if (choice != null) {
                    choices.add(choice);
                }
            }
        } else {
            choices = interaction.getSimpleMatchSets().get(pos).getSimpleAssociableChoices();
        }
        return choices.stream().filter((choice) -> isVisible(choice, itemSessionState)).collect(Collectors.toList());
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : URLBuilder(org.olat.core.gui.render.URLBuilder) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) GraphicAssociateInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicAssociateInteraction) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) Choice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice) Map(java.util.Map) Flow(uk.ac.ed.ph.jqtiplus.node.content.basic.Flow) InlineChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.InlineChoiceInteraction) StringOutput(org.olat.core.gui.render.StringOutput) OLog(org.olat.core.logging.OLog) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) FlowStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.FlowStatic) HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) Translator(org.olat.core.gui.translator.Translator) InlineChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.InlineChoice) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) FormJSHelper(org.olat.core.gui.components.form.flexible.impl.FormJSHelper) AssociateInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.AssociateInteraction) StringInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.StringInteraction) Value(uk.ac.ed.ph.jqtiplus.value.Value) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssociableHotspot(uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.AssociableHotspot) Collectors(java.util.stream.Collectors) GapImg(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.GapImg) List(java.util.List) BlockStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.BlockStatic) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) AssessmentRenderFunctions.renderValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderValue) TextOrVariable(uk.ac.ed.ph.jqtiplus.node.content.variable.TextOrVariable) BaseType(uk.ac.ed.ph.jqtiplus.value.BaseType) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) GraphicOrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicOrderInteraction) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) Settings(org.olat.core.helpers.Settings) Orientation(uk.ac.ed.ph.jqtiplus.value.Orientation) QtiNode(uk.ac.ed.ph.jqtiplus.node.QtiNode) GapChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.GapChoice) QueryUtils(uk.ac.ed.ph.jqtiplus.utils.QueryUtils) CandidateSessionContext(org.olat.ims.qti21.ui.CandidateSessionContext) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) HashMap(java.util.HashMap) StringMultipleAttribute(uk.ac.ed.ph.jqtiplus.attribute.value.StringMultipleAttribute) Prompt(uk.ac.ed.ph.jqtiplus.node.item.interaction.Prompt) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) ResponseData(uk.ac.ed.ph.jqtiplus.types.ResponseData) ArrayList(java.util.ArrayList) Gap(uk.ac.ed.ph.jqtiplus.node.item.interaction.content.Gap) SliderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.SliderInteraction) Cardinality(uk.ac.ed.ph.jqtiplus.value.Cardinality) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) OrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.OrderInteraction) StringHelper(org.olat.core.util.StringHelper) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) Iterator(java.util.Iterator) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) HotspotChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) IOException(java.io.IOException) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Shape(uk.ac.ed.ph.jqtiplus.node.expression.operator.Shape) GraphicGapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicGapMatchInteraction) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) GapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GapMatchInteraction) Tracing(org.olat.core.logging.Tracing) FileValue(uk.ac.ed.ph.jqtiplus.value.FileValue) BodyElement(uk.ac.ed.ph.jqtiplus.node.content.BodyElement) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HashMap(java.util.HashMap) IOException(java.io.IOException)

Aggregations

SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)54 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)20 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)18 ArrayList (java.util.ArrayList)17 SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)16 AssessmentItemFactory.createSimpleAssociableChoice (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice)14 HashMap (java.util.HashMap)12 List (java.util.List)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)10 AssessmentItemEvent (org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)10 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)10 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)10 FlowFormItem (org.olat.ims.qti21.ui.components.FlowFormItem)7 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6 File (java.io.File)4 UserRequest (org.olat.core.gui.UserRequest)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4