use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project OpenOLAT by OpenOLAT.
the class ChoiceInteractionStatisticsController method getSingleChoice.
private Series getSingleChoice() {
List<ChoiceStatistics> statisticResponses = getChoiceInteractionStatistics();
boolean survey = QTIType.survey.equals(resourceResult.getType());
int numOfParticipants = resourceResult.getQTIStatisticAssessment().getNumOfParticipants();
List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectIdentifierResponses(assessmentItem, interaction);
int i = 0;
long numOfResults = 0;
BarSeries d1 = new BarSeries();
List<ResponseInfos> responseInfos = new ArrayList<>();
for (ChoiceStatistics statisticResponse : statisticResponses) {
Choice choice = statisticResponse.getChoice();
String text = getAnswerText(choice);
double ans_count = statisticResponse.getCount();
numOfResults += statisticResponse.getCount();
boolean correct = correctAnswers.contains(choice.getIdentifier());
Float points;
String cssColor;
if (survey) {
points = null;
cssColor = "bar_default";
} else {
Double mappedValue = CorrectResponsesUtil.getMappedValue(assessmentItem, interaction, choice);
if (mappedValue != null) {
points = mappedValue.floatValue();
} else {
// response.getPoints();
points = correct ? 1.0f : 0.0f;
}
cssColor = correct ? "bar_green" : "bar_red";
}
String label = Integer.toString(++i);
d1.add(ans_count, label, cssColor);
responseInfos.add(new ResponseInfos(label, text, points, correct, survey, false));
}
if (numOfResults != numOfParticipants) {
long notAnswered = numOfParticipants - numOfResults;
if (notAnswered > 0) {
String label = Integer.toString(++i);
String text = translate("user.not.answer");
responseInfos.add(new ResponseInfos(label, text, null, false, survey, false));
d1.add(notAnswered, label, "bar_grey");
}
}
List<BarSeries> serieList = Collections.singletonList(d1);
Series series = new Series(serieList, responseInfos, numOfParticipants, false);
series.setChartType(SeriesFactory.BAR_CORRECT);
series.setItemCss("o_qti_scitem");
return series;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project OpenOLAT by OpenOLAT.
the class ChoiceInteractionStatisticsController method getMultipleChoice.
private Series getMultipleChoice(StatisticsItem itemStats) {
List<ChoiceStatistics> statisticResponses = getChoiceInteractionStatistics();
BarSeries d1 = new BarSeries("bar_green", "green", translate("answer.correct"));
BarSeries d2 = new BarSeries("bar_red", "red", translate("answer.false"));
BarSeries d3 = new BarSeries("bar_grey", "grey", translate("answer.noanswer"));
boolean survey = QTIType.survey.equals(resourceResult.getType());
int numOfParticipants = resourceResult.getQTIStatisticAssessment().getNumOfParticipants();
int notAnswered = numOfParticipants - (itemStats == null ? 0 : itemStats.getNumOfResults());
List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectIdentifierResponses(assessmentItem, interaction);
int i = 0;
List<ResponseInfos> responseInfos = new ArrayList<>();
for (ChoiceStatistics statisticResponse : statisticResponses) {
Choice choice = statisticResponse.getChoice();
String text = getAnswerText(choice);
boolean correct = correctAnswers.contains(choice.getIdentifier());
double answersPerAnswerOption = statisticResponse.getCount();
double rightA;
double wrongA;
if (survey) {
rightA = answersPerAnswerOption;
wrongA = 0d;
} else if (correct) {
rightA = answersPerAnswerOption;
wrongA = numOfParticipants - notAnswered - answersPerAnswerOption;
} else {
// minus negative points are not answered right?
rightA = numOfParticipants - notAnswered - answersPerAnswerOption;
wrongA = answersPerAnswerOption;
}
String label = Integer.toString(++i);
d1.add(rightA, label);
d2.add(wrongA, label);
d3.add(notAnswered, label);
Float pointsObj;
if (survey) {
pointsObj = null;
} else {
Double mappedValue = CorrectResponsesUtil.getMappedValue(assessmentItem, interaction, choice);
if (mappedValue != null) {
pointsObj = mappedValue.floatValue();
} else {
pointsObj = correct ? 1.0f : 0.0f;
}
}
responseInfos.add(new ResponseInfos(label, text, pointsObj, correct, survey, false));
}
List<BarSeries> serieList = new ArrayList<>(3);
serieList.add(d1);
if (!survey) {
serieList.add(d2);
serieList.add(d3);
}
Series series = new Series(serieList, responseInfos, numOfParticipants, !survey);
series.setChartType(survey ? SeriesFactory.BAR_ANSWERED : SeriesFactory.BAR_CORRECT_WRONG_NOT);
series.setItemCss("o_qti_scitem");
return series;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project openolat by klemens.
the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem.
@Test
public void readHottextAssessmentItem() throws URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-per-answer-11-4-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
// hot texts
Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htf9250a96f24bc8873c9cc54dfbaaaa"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_3"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_2"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
Choice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_4"));
Assert.assertFalse(itemBuilder.isCorrect(wrong2));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(3.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// per answer
Assert.assertEquals(ScoreEvaluation.perAnswer, itemBuilder.getScoreEvaluationMode());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project openolat by klemens.
the class AssessmentObjectVelocityRenderDecorator method getVisibleOrderedSimpleChoices.
public List<SimpleChoice> getVisibleOrderedSimpleChoices(OrderInteraction interaction) {
List<SimpleChoice> choices;
if (interaction.getShuffle()) {
// <xsl:variable name="shuffledChoiceOrders" select="$itemSessionState/qw:shuffledInteractionChoiceOrder"
// as="element(qw:shuffledInteractionChoiceOrder)*"/>
// <xsl:variable name="choiceSequence" as="xs:string?"
// select="$shuffledChoiceOrders[@responseIdentifier=$interaction/@responseIdentifier]/@choiceSequence"/>
List<Identifier> choiceOrders = itemSessionState.getShuffledInteractionChoiceOrder(interaction.getResponseIdentifier());
choices = new ArrayList<>();
for (Identifier choiceOrder : choiceOrders) {
choices.add(interaction.getSimpleChoice(choiceOrder));
}
} else {
choices = interaction.getSimpleChoices();
}
return choices.stream().filter((choice) -> isVisible(choice, itemSessionState)).collect(Collectors.toList());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice in project openolat by klemens.
the class AssessmentObjectVelocityRenderDecorator method getVisibleOrderedChoices.
public List<GapChoice> getVisibleOrderedChoices(GapMatchInteraction interaction) {
List<GapChoice> choices;
if (interaction.getShuffle()) {
// <xsl:variable name="shuffledChoiceOrders" select="$itemSessionState/qw:shuffledInteractionChoiceOrder"
// as="element(qw:shuffledInteractionChoiceOrder)*"/>
// <xsl:variable name="choiceSequence" as="xs:string?"
// select="$shuffledChoiceOrders[@responseIdentifier=$interaction/@responseIdentifier]/@choiceSequence"/>
List<Identifier> choiceOrders = itemSessionState.getShuffledInteractionChoiceOrder(interaction.getResponseIdentifier());
choices = new ArrayList<>();
for (Identifier choiceOrder : choiceOrders) {
choices.add(interaction.getGapChoice(choiceOrder));
}
} else {
choices = new ArrayList<>(interaction.getGapChoices());
}
return choices.stream().filter((choice) -> isVisible(choice, itemSessionState)).collect(Collectors.toList());
}
Aggregations