use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class HottextAssessmentItemBuilderTest method createHottextAssessmentItem_perAnswer.
/**
* This is an hottextInteraction with 3 choices, one with 3.0 points and correct,
* one with 0.0 points but correct and one false with -1.0 points.
*
* @throws IOException
*/
@Test
public void createHottextAssessmentItem_perAnswer() throws IOException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder("Hot texts", "This is a hot ", "text", qtiSerializer);
itemBuilder.setQuestion("<p>This is <hottext identifier=\"RESPONSE_HOT_1\">hot</hottext>, <hottext identifier=\"RESPONSE_HOT_2\">cold</hottext> or <hottext identifier=\"RESPONSE_HOT_3\">freezing</hottext></p>");
itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_2"));
itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_3"));
itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_1"), -1.0d);
itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_2"), 0.0d);
itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_3"), 3.0d);
itemBuilder.setMaxScore(3.0d);
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
itemBuilder.build();
File itemFile = new File(WebappHelper.getTmpDir(), "hottextAssessmentItem" + UUID.randomUUID() + ".xml");
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(itemBuilder.getAssessmentItem(), out);
} catch (Exception e) {
log.error("", e);
}
{
// correct answers
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_2", "RESPONSE_HOT_3"));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(3.0d), score);
Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
Assert.assertEquals(new IdentifierValue(QTI21Constants.CORRECT_IDENTIFIER), feedbackBasic);
}
{
// max score but not all correct
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_3"));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(3.0d), score);
Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
}
{
// all wrong
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_1"));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(0.0d), score);
Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
}
FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class AssessmentRenderFunctions method renderRecordCardinalityValue.
public static void renderRecordCardinalityValue(StringOutput sb, Value value, String delimiter, String mappingIndicator) {
if (value != null && value.hasCardinality(Cardinality.RECORD)) {
RecordValue oValue = (RecordValue) value;
boolean hasDelimiter = StringHelper.containsNonWhitespace(delimiter);
boolean hasMappingIndicator = StringHelper.containsNonWhitespace(mappingIndicator);
int count = 0;
for (Map.Entry<Identifier, SingleValue> entry : oValue.entrySet()) {
if (hasDelimiter && count++ > 0)
sb.append(delimiter);
String identifierString = entry.getKey().toString();
sb.append(identifierString);
if (hasMappingIndicator) {
sb.append(mappingIndicator);
}
renderSingleCardinalityValue(sb, entry.getValue());
}
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class HotspotInteractionStatisticsController method getSingleChoice.
private Series getSingleChoice(List<HotspotChoiceStatistics> statisticResponses) {
boolean survey = QTIType.survey.equals(resourceResult.getType());
int numOfParticipants = resourceResult.getQTIStatisticAssessment().getNumOfParticipants();
List<Identifier> correctAnswers = getCorrectResponses();
int i = 0;
long numOfResults = 0;
BarSeries d1 = new BarSeries();
List<ResponseInfos> responseInfos = new ArrayList<>();
for (HotspotChoiceStatistics statisticResponse : statisticResponses) {
HotspotChoice 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 {
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.types.Identifier in project OpenOLAT by OpenOLAT.
the class HotspotInteractionStatisticsController method getCorrectResponses.
private List<Identifier> getCorrectResponses() {
List<Identifier> correctAnswers = new ArrayList<>();
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
extractIdentifiersFromCorrectResponse(responseDeclaration.getCorrectResponse(), correctAnswers);
}
return correctAnswers;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class MatchScoreController method forgeScoreElement.
private void forgeScoreElement(MatchWrapper sourceWrapper, MatchWrapper targetWrapper) {
Identifier sourceIdentifier = sourceWrapper.getChoiceIdentifier();
Identifier targetIdentifier = targetWrapper.getChoiceIdentifier();
DirectedPairValue dKey = new DirectedPairValue(sourceIdentifier, targetIdentifier);
if (!scoreWrappers.containsKey(dKey)) {
String key = sourceIdentifier.toString() + "-" + targetIdentifier.toString();
TextElement textEl = uifactory.addTextElement(key, null, 8, "", scoreCont);
MatchScoreWrapper scoreWrapper = new MatchScoreWrapper(sourceIdentifier, targetIdentifier, textEl);
textEl.setDomReplacementWrapperRequired(false);
textEl.setDisplaySize(5);
textEl.setUserObject(scoreWrapper);
textEl.setEnabled(!restrictedEdit && !readOnly);
Double score = itemBuilder.getScore(sourceIdentifier, targetIdentifier);
if (score == null) {
textEl.setValue("0.0");
} else {
textEl.setValue(AssessmentHelper.getRoundedScore(score));
}
scoreWrappers.put(dKey, scoreWrapper);
scoreCont.contextPut(key, scoreWrapper);
}
}
Aggregations