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"));
}
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));
}
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());
}
}
}
}
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());
}
}
}
}
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"));
}
Aggregations