use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.
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.Response in project OpenOLAT by OpenOLAT.
the class QTIStatisticsManagerImpl method getNumOfRightAnsweredMultipleChoice.
/**
* calculates the percentage of participants that answered a answer option
* correctly.<br>
* Number at index 0 = answer option 1, Number at index 1 = answer option 2,
* etc.
*
* @param item
* @param numberOfParticipants
* @param olatResource
* @param olatResourceDetail
* @return
*/
@Override
public List<StatisticChoiceOption> getNumOfRightAnsweredMultipleChoice(Item item, QTIStatisticSearchParams searchParams) {
List<StatisticAnswerOption> answerToNumberList = getStatisticAnswerOptionsOfItem(item.getIdent(), searchParams);
List<Response> responses = item.getQuestion().getResponses();
List<StatisticChoiceOption> percentageRightAnswered = new ArrayList<StatisticChoiceOption>();
for (Response response : responses) {
String answerIdent = response.getIdent();
long num = 0;
for (StatisticAnswerOption answerToNumber : answerToNumberList) {
String answer = answerToNumber.getAnswer();
if (answer.indexOf(answerIdent) >= 0) {
num += answerToNumber.getCount();
}
}
percentageRightAnswered.add(new StatisticChoiceOption(response, num));
}
return percentageRightAnswered;
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.
the class QTIStatisticsManagerImpl method getNumOfAnswersPerSingleChoiceAnswerOption.
/**
* calculates how many participants selected answer option 1 and/or option 2
* and/or option 3...
*
* @param aQuestion
* @param olatResource
* @param olatResourceDetail
* @return
*/
@Override
public List<StatisticChoiceOption> getNumOfAnswersPerSingleChoiceAnswerOption(Item item, QTIStatisticSearchParams searchParams) {
List<StatisticAnswerOption> answerToNumberList = getStatisticAnswerOptionsOfItem(item.getIdent(), searchParams);
List<Response> answerOptions = item.getQuestion().getResponses();
List<StatisticChoiceOption> numOfAnswersPerOption = new ArrayList<>();
for (int i = 0; i < answerOptions.size(); i++) {
Response response = answerOptions.get(i);
String responseIdent = response.getIdent();
long num = 0;
for (StatisticAnswerOption answerToNumber : answerToNumberList) {
String answer = answerToNumber.getAnswer();
if (answer.indexOf(responseIdent) >= 0) {
num += answerToNumber.getCount();
}
}
numOfAnswersPerOption.add(new StatisticChoiceOption(response, num));
}
return numOfAnswersPerOption;
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.
the class QTIStatisticsManagerImpl method getNumbersInKPrim.
@Override
public List<StatisticKPrimOption> getNumbersInKPrim(Item item, QTIStatisticSearchParams searchParams) {
List<StatisticAnswerOption> rawDatas = getStatisticAnswerOptionsOfItem(item.getIdent(), searchParams);
List<Response> responses = item.getQuestion().getResponses();
List<StatisticKPrimOption> kprimPoints = new ArrayList<>();
for (Response response : responses) {
String answerIdent = response.getIdent();
boolean isCorrect = response.isCorrect();
String rightFlag = answerIdent + ":" + (isCorrect ? "correct" : "wrong");
String wrongFlag = answerIdent + ":" + (isCorrect ? "wrong" : "correct");
long numCorrect = 0;
long numIncorrect = 0;
long numUnanswered = 0;
for (StatisticAnswerOption rawData : rawDatas) {
String answer = rawData.getAnswer();
if (answer.indexOf(rightFlag) >= 0) {
numCorrect += rawData.getCount();
} else if (answer.indexOf(wrongFlag) >= 0) {
numIncorrect += rawData.getCount();
} else {
numUnanswered += rawData.getCount();
}
}
kprimPoints.add(new StatisticKPrimOption(response, numCorrect, numIncorrect, numUnanswered));
}
return kprimPoints;
}
use of org.olat.ims.qti.editor.beecom.objects.Response in project OpenOLAT by OpenOLAT.
the class QTIStatisticsManagerImpl method getStatisticAnswerOptionsFIB.
@Override
public List<StatisticFIBOption> getStatisticAnswerOptionsFIB(Item item, QTIStatisticSearchParams searchParams) {
List<StatisticFIBOption> options = new ArrayList<>();
Map<String, StatisticFIBOption> optionMap = new HashMap<>();
boolean groupBy = true;
List<Response> responses = item.getQuestion().getResponses();
for (Response response : responses) {
if (response instanceof FIBResponse) {
FIBResponse fibResponse = (FIBResponse) response;
if (FIBResponse.TYPE_BLANK.equals(fibResponse.getType())) {
String ident = fibResponse.getIdent();
String[] correctFIBs = fibResponse.getCorrectBlank().split(";");
if (correctFIBs == null || correctFIBs.length == 0) {
continue;
}
StatisticFIBOption option = new StatisticFIBOption();
option.setCorrectBlank(correctFIBs[0]);
option.setAlternatives(Arrays.asList(correctFIBs));
boolean caseSensitive = "Yes".equals(fibResponse.getCaseSensitive());
groupBy &= !caseSensitive;
option.setCaseSensitive(caseSensitive);
option.setPoints(fibResponse.getPoints());
options.add(option);
optionMap.put(ident, option);
}
}
}
List<StatisticAnswerOption> answerOptions = getStatisticAnswerOptionsOfItem(item.getIdent(), searchParams, groupBy);
for (StatisticAnswerOption answerOption : answerOptions) {
long count = answerOption.getCount();
String concatenedAnswer = answerOption.getAnswer();
Map<String, String> parsedAnswerMap = QTIResultManager.parseResponseStrAnswers(concatenedAnswer);
for (Map.Entry<String, String> parsedAnswerEntry : parsedAnswerMap.entrySet()) {
String ident = parsedAnswerEntry.getKey();
StatisticFIBOption option = optionMap.get(ident);
if (option == null) {
continue;
}
String text = parsedAnswerEntry.getValue();
boolean correct;
if (option.isCaseSensitive()) {
correct = option.getAlternatives().contains(text);
} else {
correct = false;
for (String alt : option.getAlternatives()) {
if (alt.equalsIgnoreCase(text)) {
correct = true;
}
}
}
if (correct) {
option.setNumOfCorrect(option.getNumOfCorrect() + count);
} else {
option.setNumOfIncorrect(option.getNumOfIncorrect() + count);
option.getWrongAnswers().add(text);
}
}
}
return options;
}
Aggregations