Search in sources :

Example 1 with Selection

use of uk.ac.ed.ph.jqtiplus.node.test.Selection in project OpenOLAT by OpenOLAT.

the class BigAssessmentTestPackageBuilder method createAssessmentTest.

@Test
public void createAssessmentTest() throws URISyntaxException {
    String date = format.format(new Date());
    File directory = new File("/HotCoffee/qti/" + date + "/");
    directory.mkdirs();
    ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
    System.out.println(directory);
    // test
    File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
    AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest("Big test " + date, "Section");
    manifest.appendAssessmentTest(testFile.getName());
    TestPart part = assessmentTest.getTestParts().get(0);
    part.getAssessmentSections().clear();
    // section
    for (int i = 0; i < numOfSections; i++) {
        AssessmentSection section = new AssessmentSection(part);
        section.setFixed(Boolean.TRUE);
        section.setVisible(Boolean.TRUE);
        section.setTitle((i + 1) + ". Section");
        section.setIdentifier(IdentifierGenerator.newAsIdentifier("sec"));
        part.getAssessmentSections().add(section);
        Ordering ordering = new Ordering(section);
        ordering.setShuffle(true);
        section.setOrdering(ordering);
        Selection selection = new Selection(section);
        selection.setSelect(4);
        section.setSelection(selection);
        ItemSessionControl itemSessionControl = new ItemSessionControl(section);
        itemSessionControl.setAllowSkipping(Boolean.TRUE);
        itemSessionControl.setAllowComment(Boolean.FALSE);
        itemSessionControl.setShowFeedback(Boolean.FALSE);
        section.setItemSessionControl(itemSessionControl);
        RubricBlock rubrickBlock = new RubricBlock(section);
        rubrickBlock.setViews(Collections.singletonList(View.CANDIDATE));
        section.getRubricBlocks().add(rubrickBlock);
        for (int j = 0; j < numOfQuestions; j++) {
            // single choice
            String itemId = IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix());
            File itemFile = new File(directory, itemId + ".xml");
            AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice("Single choice", "New answer");
            assessmentItem.setTitle((i + 1) + "." + (j + 1) + ". Question SC");
            AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
            manifest.appendAssessmentItem(itemFile.getName());
            try (FileOutputStream out = new FileOutputStream(itemFile)) {
                qtiSerializer.serializeJqtiObject(assessmentItem, out);
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }
    try (FileOutputStream out = new FileOutputStream(testFile)) {
        qtiSerializer.serializeJqtiObject(assessmentTest, out);
    } catch (Exception e) {
        log.error("", e);
    }
    manifest.write(new File(directory, "imsmanifest.xml"));
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) Selection(uk.ac.ed.ph.jqtiplus.node.test.Selection) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) Ordering(uk.ac.ed.ph.jqtiplus.node.test.Ordering) File(java.io.File) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) Test(org.junit.Test)

Example 2 with Selection

use of uk.ac.ed.ph.jqtiplus.node.test.Selection in project OpenOLAT by OpenOLAT.

the class AssessmentSectionOptionsEditorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    section.setTitle(titleEl.getValue());
    // rubrics
    List<RubricBlock> rubricBlocks = new ArrayList<>();
    for (RichTextElement rubricEl : rubricEls) {
        String rubric = rubricEl.getRawValue();
        if (htmlBuilder.containsSomething(rubric)) {
            RubricBlock rubricBlock = (RubricBlock) rubricEl.getUserObject();
            if (rubricBlock == null) {
                rubricBlock = new RubricBlock(section);
                rubricBlock.setViews(Collections.singletonList(View.CANDIDATE));
            }
            rubricBlock.getBlocks().clear();
            htmlBuilder.appendHtml(rubricBlock, rubric);
            rubricBlocks.add(rubricBlock);
        }
    }
    section.getRubricBlocks().clear();
    section.getRubricBlocks().addAll(rubricBlocks);
    // shuffle
    boolean shuffle = (shuffleEl.isOneSelected() && shuffleEl.isSelected(0));
    if (shuffle) {
        if (section.getOrdering() == null) {
            section.setOrdering(new Ordering(section));
        }
        section.getOrdering().setShuffle(shuffle);
    } else {
        section.setOrdering(null);
    }
    // number of selected questions
    Integer randomSelection = null;
    if (StringHelper.containsNonWhitespace(randomSelectedEl.getSelectedKey())) {
        randomSelection = new Integer(randomSelectedEl.getSelectedKey());
    }
    if (randomSelection == null || randomSelection.intValue() < 1) {
        section.setSelection(null);
    } else {
        if (section.getSelection() == null) {
            section.setSelection(new Selection(section));
        }
        section.getSelection().setSelect(randomSelection);
    }
    fireEvent(ureq, new AssessmentSectionEvent(AssessmentSectionEvent.ASSESSMENT_SECTION_CHANGED, section));
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) Selection(uk.ac.ed.ph.jqtiplus.node.test.Selection) ArrayList(java.util.ArrayList) Ordering(uk.ac.ed.ph.jqtiplus.node.test.Ordering) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) AssessmentSectionEvent(org.olat.ims.qti21.ui.editor.events.AssessmentSectionEvent)

Example 3 with Selection

use of uk.ac.ed.ph.jqtiplus.node.test.Selection in project OpenOLAT by OpenOLAT.

the class QTI12To21Converter method convert.

private void convert(Section section, TestPart testPart) throws URISyntaxException {
    AssessmentSection assessmentSection = AssessmentTestFactory.appendAssessmentSection("Section", testPart);
    assessmentSection.setTitle(section.getTitle());
    convertDuration(section.getDuration(), assessmentSection);
    RubricBlock rubricBlock = assessmentSection.getRubricBlocks().get(0);
    rubricBlock.getBlocks().clear();
    String objectives = section.getObjectives();
    htmlBuilder.appendHtml(rubricBlock, blockedHtml(objectives));
    boolean shuffle = SelectionOrdering.RANDOM.equals(section.getSelection_ordering().getOrderType());
    assessmentSection.getOrdering().setShuffle(shuffle);
    int selectionNum = section.getSelection_ordering().getSelectionNumber();
    if (selectionNum > 0) {
        Selection selection = new Selection(assessmentSection);
        selection.setSelect(selectionNum);
        assessmentSection.setSelection(selection);
    }
    List<Item> items = section.getItems();
    for (Item item : items) {
        AssessmentItemBuilder itemBuilder = null;
        if (item != null && item.getQuestion() != null) {
            int questionType = item.getQuestion().getType();
            switch(questionType) {
                case Question.TYPE_SC:
                    itemBuilder = convertSingleChoice(item);
                    break;
                case Question.TYPE_MC:
                    itemBuilder = convertMultipleChoice(item);
                    break;
                case Question.TYPE_KPRIM:
                    itemBuilder = convertKPrim(item);
                    break;
                case Question.TYPE_FIB:
                    itemBuilder = convertFIB(item);
                    break;
                case Question.TYPE_ESSAY:
                    itemBuilder = convertEssay(item);
                    break;
            }
        } else {
            errors.add(item.getTitle());
            log.error("Item without question: " + item);
        }
        if (itemBuilder != null) {
            itemBuilder.build();
            AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
            AssessmentItemRef itemRef = new AssessmentItemRef(assessmentSection);
            String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
            itemRef.setIdentifier(Identifier.parseString(itemId));
            convertItemBasics(item, itemRef);
            File itemFile = new File(unzippedDirRoot, itemId + ".xml");
            itemRef.setHref(new URI(itemFile.getName()));
            assessmentSection.getSectionParts().add(itemRef);
            persistAssessmentObject(itemFile, assessmentItem);
            appendResourceAndMetadata(item, itemBuilder, itemFile);
            // collect max score
            Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
            if (maxScore != null && maxScore.doubleValue() > 0.0d) {
                atomicMaxScore.add(maxScore.doubleValue());
            }
        }
    }
}
Also used : Selection(uk.ac.ed.ph.jqtiplus.node.test.Selection) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) URI(java.net.URI) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) File(java.io.File)

Example 4 with Selection

use of uk.ac.ed.ph.jqtiplus.node.test.Selection in project openolat by klemens.

the class QTI12To21Converter method convert.

private void convert(Section section, TestPart testPart) throws URISyntaxException {
    AssessmentSection assessmentSection = AssessmentTestFactory.appendAssessmentSection("Section", testPart);
    assessmentSection.setTitle(section.getTitle());
    convertDuration(section.getDuration(), assessmentSection);
    RubricBlock rubricBlock = assessmentSection.getRubricBlocks().get(0);
    rubricBlock.getBlocks().clear();
    String objectives = section.getObjectives();
    htmlBuilder.appendHtml(rubricBlock, blockedHtml(objectives));
    boolean shuffle = SelectionOrdering.RANDOM.equals(section.getSelection_ordering().getOrderType());
    assessmentSection.getOrdering().setShuffle(shuffle);
    int selectionNum = section.getSelection_ordering().getSelectionNumber();
    if (selectionNum > 0) {
        Selection selection = new Selection(assessmentSection);
        selection.setSelect(selectionNum);
        assessmentSection.setSelection(selection);
    }
    List<Item> items = section.getItems();
    for (Item item : items) {
        AssessmentItemBuilder itemBuilder = null;
        if (item != null && item.getQuestion() != null) {
            int questionType = item.getQuestion().getType();
            switch(questionType) {
                case Question.TYPE_SC:
                    itemBuilder = convertSingleChoice(item);
                    break;
                case Question.TYPE_MC:
                    itemBuilder = convertMultipleChoice(item);
                    break;
                case Question.TYPE_KPRIM:
                    itemBuilder = convertKPrim(item);
                    break;
                case Question.TYPE_FIB:
                    itemBuilder = convertFIB(item);
                    break;
                case Question.TYPE_ESSAY:
                    itemBuilder = convertEssay(item);
                    break;
            }
        } else {
            errors.add(item.getTitle());
            log.error("Item without question: " + item);
        }
        if (itemBuilder != null) {
            itemBuilder.build();
            AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
            AssessmentItemRef itemRef = new AssessmentItemRef(assessmentSection);
            String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
            itemRef.setIdentifier(Identifier.parseString(itemId));
            convertItemBasics(item, itemRef);
            File itemFile = new File(unzippedDirRoot, itemId + ".xml");
            itemRef.setHref(new URI(itemFile.getName()));
            assessmentSection.getSectionParts().add(itemRef);
            persistAssessmentObject(itemFile, assessmentItem);
            appendResourceAndMetadata(item, itemBuilder, itemFile);
            // collect max score
            Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
            if (maxScore != null && maxScore.doubleValue() > 0.0d) {
                atomicMaxScore.add(maxScore.doubleValue());
            }
        }
    }
}
Also used : Selection(uk.ac.ed.ph.jqtiplus.node.test.Selection) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) URI(java.net.URI) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) File(java.io.File)

Example 5 with Selection

use of uk.ac.ed.ph.jqtiplus.node.test.Selection in project openolat by klemens.

the class BigAssessmentTestPackageBuilder method createAssessmentTest.

@Test
public void createAssessmentTest() throws URISyntaxException {
    String date = format.format(new Date());
    File directory = new File("/HotCoffee/qti/" + date + "/");
    directory.mkdirs();
    ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
    System.out.println(directory);
    // test
    File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
    AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest("Big test " + date, "Section");
    manifest.appendAssessmentTest(testFile.getName());
    TestPart part = assessmentTest.getTestParts().get(0);
    part.getAssessmentSections().clear();
    // section
    for (int i = 0; i < numOfSections; i++) {
        AssessmentSection section = new AssessmentSection(part);
        section.setFixed(Boolean.TRUE);
        section.setVisible(Boolean.TRUE);
        section.setTitle((i + 1) + ". Section");
        section.setIdentifier(IdentifierGenerator.newAsIdentifier("sec"));
        part.getAssessmentSections().add(section);
        Ordering ordering = new Ordering(section);
        ordering.setShuffle(true);
        section.setOrdering(ordering);
        Selection selection = new Selection(section);
        selection.setSelect(4);
        section.setSelection(selection);
        ItemSessionControl itemSessionControl = new ItemSessionControl(section);
        itemSessionControl.setAllowSkipping(Boolean.TRUE);
        itemSessionControl.setAllowComment(Boolean.FALSE);
        itemSessionControl.setShowFeedback(Boolean.FALSE);
        section.setItemSessionControl(itemSessionControl);
        RubricBlock rubrickBlock = new RubricBlock(section);
        rubrickBlock.setViews(Collections.singletonList(View.CANDIDATE));
        section.getRubricBlocks().add(rubrickBlock);
        for (int j = 0; j < numOfQuestions; j++) {
            // single choice
            String itemId = IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix());
            File itemFile = new File(directory, itemId + ".xml");
            AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice("Single choice", "New answer");
            assessmentItem.setTitle((i + 1) + "." + (j + 1) + ". Question SC");
            AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
            manifest.appendAssessmentItem(itemFile.getName());
            try (FileOutputStream out = new FileOutputStream(itemFile)) {
                qtiSerializer.serializeJqtiObject(assessmentItem, out);
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }
    try (FileOutputStream out = new FileOutputStream(testFile)) {
        qtiSerializer.serializeJqtiObject(assessmentTest, out);
    } catch (Exception e) {
        log.error("", e);
    }
    manifest.write(new File(directory, "imsmanifest.xml"));
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) Selection(uk.ac.ed.ph.jqtiplus.node.test.Selection) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ItemSessionControl(uk.ac.ed.ph.jqtiplus.node.test.ItemSessionControl) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) FileOutputStream(java.io.FileOutputStream) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) Ordering(uk.ac.ed.ph.jqtiplus.node.test.Ordering) File(java.io.File) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) Test(org.junit.Test)

Aggregations

RubricBlock (uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock)6 Selection (uk.ac.ed.ph.jqtiplus.node.test.Selection)6 File (java.io.File)4 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)4 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)4 Ordering (uk.ac.ed.ph.jqtiplus.node.test.Ordering)4 FileOutputStream (java.io.FileOutputStream)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Test (org.junit.Test)2 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 Item (org.olat.ims.qti.editor.beecom.objects.Item)2 AssessmentItemBuilder (org.olat.ims.qti21.model.xml.AssessmentItemBuilder)2 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)2 EssayAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder)2 FIBAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder)2