use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTIWordExport method renderItem.
public static void renderItem(Item item, OpenXMLDocument document, boolean withResponses, Translator translator) {
Element el = DocumentFactory.getInstance().createElement("dummy");
item.addToElement(el);
Element itemEl = (Element) el.elements().get(0);
org.olat.ims.qti.container.qtielements.Item foo = new org.olat.ims.qti.container.qtielements.Item(itemEl);
RenderInstructions renderInstructions = new RenderInstructions();
renderInstructions.put(RenderInstructions.KEY_STATICS_PATH, "/");
renderInstructions.put(RenderInstructions.KEY_LOCALE, translator.getLocale());
renderInstructions.put(RenderInstructions.KEY_RENDER_TITLE, Boolean.TRUE);
if (item.getQuestion() != null) {
Map<String, String> iinput = new HashMap<String, String>();
String questionType = null;
String questionScore = null;
Question question = item.getQuestion();
if (question instanceof ChoiceQuestion) {
ChoiceQuestion choice = (ChoiceQuestion) question;
if (question.getType() == Question.TYPE_SC) {
questionType = translator.translate("item.type.sc");
fetchPointsOfMultipleChoices(itemEl, choice, iinput);
} else if (question.getType() == Question.TYPE_MC) {
questionType = translator.translate("item.type.mc");
fetchPointsOfMultipleChoices(itemEl, choice, iinput);
} else if (question.getType() == Question.TYPE_KPRIM) {
questionType = translator.translate("item.type.kprim");
fetchPointsOfKPrim(itemEl, choice, iinput);
}
} else if (question instanceof FIBQuestion) {
questionType = translator.translate("item.type.sc");
for (Response response : question.getResponses()) {
FIBResponse fibResponse = (FIBResponse) response;
if ("BLANK".equals(fibResponse.getType())) {
iinput.put(fibResponse.getIdent(), fibResponse.getCorrectBlank());
}
}
} else if (question instanceof EssayQuestion) {
questionType = translator.translate("item.type.essay");
}
if (question != null && question.getMaxValue() > 0.0f) {
questionScore = AssessmentHelper.getRoundedScore(question.getMaxValue());
questionScore = translator.translate("item.score.long", new String[] { questionScore });
}
renderInstructions.put(RenderInstructions.KEY_RENDER_CORRECT_RESPONSES, new Boolean(withResponses));
renderInstructions.put(RenderInstructions.KEY_CORRECT_RESPONSES_MAP, iinput);
renderInstructions.put(RenderInstructions.KEY_QUESTION_TYPE, questionType);
renderInstructions.put(RenderInstructions.KEY_QUESTION_SCORE, questionScore);
renderInstructions.put(RenderInstructions.KEY_QUESTION_OO_TYPE, new Integer(question.getType()));
}
foo.renderOpenXML(document, renderInstructions);
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTIStatisticResourceResult method getController.
public Controller getController(UserRequest ureq, WindowControl wControl, TooledStackedPanel stackPanel, TreeNode selectedNode, boolean printMode) {
if (selectedNode instanceof StatisticResourceNode) {
return createAssessmentController(ureq, wControl, stackPanel, printMode);
} else if (selectedNode instanceof SectionNode) {
return createAssessmentController(ureq, wControl, stackPanel, printMode);
} else if (selectedNode instanceof ItemNode) {
Section section = null;
INode sectionNode = selectedNode.getParent();
if (sectionNode instanceof SectionNode) {
section = (Section) ((SectionNode) sectionNode).getUserObject();
}
Item item = (Item) ((ItemNode) selectedNode).getUserObject();
return createItemController(ureq, wControl, section, item, printMode);
}
return null;
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTIStatisticsManagerImpl method getStatisticAnswerOptions.
@Override
public List<StatisticSurveyItem> getStatisticAnswerOptions(QTIStatisticSearchParams searchParams, List<Item> items) {
StringBuilder sb = new StringBuilder();
sb.append("select res.itemIdent, res.answer, count(res.key) from qtistatsresult res ").append(" inner join res.resultSet rset");
decorateRSet(sb, searchParams).append(" and res.duration > 0").append(" group by res.itemIdent, res.answer").append(" order by res.itemIdent");
TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
decorateRSetQuery(query, searchParams);
List<Object[]> results = query.getResultList();
if (results.isEmpty()) {
return Collections.emptyList();
}
Map<String, Item> identToItemMap = new HashMap<>();
for (Item item : items) {
identToItemMap.put(item.getIdent(), item);
}
StatisticSurveyItem currentItem = null;
Map<Item, StatisticSurveyItem> itemToStatisticsMap = new HashMap<>();
for (Object[] result : results) {
String itemIdent = (String) result[0];
String answer = (String) result[1];
Long numOfAnswers = (Long) result[2];
Item item = identToItemMap.get(itemIdent);
if (currentItem == null || !currentItem.getItem().getIdent().equals(itemIdent)) {
currentItem = new StatisticSurveyItem(item);
itemToStatisticsMap.put(item, currentItem);
}
Response response = findResponses(item, answer);
currentItem.getResponses().add(new StatisticSurveyItemResponse(response, answer, numOfAnswers));
}
List<StatisticSurveyItem> reorderList = new ArrayList<>();
for (Item item : items) {
StatisticSurveyItem statsItem = itemToStatisticsMap.get(item);
if (statsItem != null) {
reorderList.add(statsItem);
}
}
return reorderList;
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTIStatisticsManagerImpl method getStatisticPerItem.
@Override
public List<StatisticItem> getStatisticPerItem(List<Item> items, QTIStatisticSearchParams searchParams, double numOfParticipants) {
StringBuilder sb = new StringBuilder();
sb.append("select res.itemIdent, res.score, count(res.key) from qtistatsresult res ").append(" inner join res.resultSet rset");
decorateRSet(sb, searchParams);
sb.append(" group by res.itemIdent, res.score");
TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class);
decorateRSetQuery(query, searchParams);
List<Object[]> results = query.getResultList();
Map<String, StatisticItemHelper> itemToHelpers = new HashMap<>();
for (Object[] result : results) {
String itemIdent = (String) result[0];
Float score = (Float) result[1];
Long count = (Long) result[2];
if (count == null || score == null || itemIdent == null)
continue;
StatisticItemHelper helper = itemToHelpers.get(itemIdent);
if (helper == null) {
helper = new StatisticItemHelper();
itemToHelpers.put(itemIdent, helper);
}
helper.count += count.longValue();
helper.totalScore += (count.longValue() * score.doubleValue());
for (Item item : items) {
if (item.getIdent().equals(itemIdent)) {
double maxValue = item.getQuestion().getMaxValue();
if (Math.abs(score.doubleValue() - maxValue) < 0.0001) {
helper.countCorrectAnswers += count.longValue();
}
}
}
}
List<StatisticItem> averages = new ArrayList<>();
for (Item item : items) {
StatisticItemHelper helper = itemToHelpers.get(item.getIdent());
if (helper == null) {
averages.add(new StatisticItem(item, -1.0, -1.0, -1, -1));
} else {
long numOfAnswersItem = helper.count;
long numOfCorrectAnswers = helper.countCorrectAnswers;
double average = (helper.totalScore / helper.count);
double averageParticipants = (helper.totalScore / numOfParticipants);
averages.add(new StatisticItem(item, average, averageParticipants, numOfAnswersItem, numOfCorrectAnswers));
}
}
return averages;
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTI12AssessmentStatisticsController method initScoreStatisticPerItem.
private void initScoreStatisticPerItem(List<Item> items, double numOfParticipants) {
BarSeries d1 = new BarSeries();
BarSeries d2 = new BarSeries();
List<StatisticItem> statisticItems = qtiStatisticsManager.getStatisticPerItem(items, resourceResult.getSearchParams(), numOfParticipants);
int i = 0;
List<ItemInfos> itemInfos = new ArrayList<>(items.size());
for (StatisticItem statisticItem : statisticItems) {
Item item = statisticItem.getItem();
String label = Integer.toString(++i);
String text = item.getTitle();
d1.add(statisticItem.getAverageScore(), label);
double numOfRightAnswers = statisticItem.getNumOfCorrectAnswers();
double res = numOfRightAnswers;
d2.add(res, label);
itemInfos.add(new ItemInfos(label, text));
}
mainVC.contextPut("itemInfoList", itemInfos);
VelocityContainer averageScorePeritemVC = createVelocityContainer("hbar_average_score_per_item");
Stringuified data1 = BarSeries.getDatasAndColors(Collections.singletonList(d1), "bar_default");
averageScorePeritemVC.contextPut("datas", data1);
mainVC.put("averageScorePerItemChart", averageScorePeritemVC);
VelocityContainer percentRightAnswersPerItemVC = createVelocityContainer("hbar_right_answer_per_item");
Stringuified data2 = BarSeries.getDatasAndColors(Collections.singletonList(d2), "bar_green");
percentRightAnswersPerItemVC.contextPut("datas", data2);
percentRightAnswersPerItemVC.contextPut("numOfParticipants", Long.toString(Math.round(numOfParticipants)));
mainVC.put("percentRightAnswersPerItemChart", percentRightAnswersPerItemVC);
}
Aggregations