use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class GapMatchInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
List<Gap> gaps = getGaps(interaction);
if (gaps.size() > 0) {
GapMatchInteraction gapMatchInteraction = (GapMatchInteraction) interaction;
Set<String> correctAnswers = CorrectResponsesUtil.getCorrectDirectPairResponses(item, interaction, false);
String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
for (Gap gap : gaps) {
String gapIdentifier = gap.getIdentifier().toString();
String gapResponse = null;
for (String r : responses) {
if (r.endsWith(gapIdentifier)) {
gapResponse = r;
}
}
if (gapResponse != null) {
String[] gapResponsePair = gapResponse.split(" ");
if (gapResponsePair.length > 1) {
String gapResponseAssociation = gapResponsePair[0];
Identifier gapResponseIdentifier = Identifier.assumedLegal(gapResponseAssociation);
GapChoice choice = gapMatchInteraction.getGapChoice(gapResponseIdentifier);
String value = null;
if (choice != null) {
value = getTextContent(choice);
}
boolean correct = correctAnswers.contains(gapResponse);
if (correct) {
dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, value);
}
} else {
col++;
}
} else {
col++;
}
}
} else {
col++;
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class GraphicOrderInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
GraphicOrderInteraction orderInteraction = (GraphicOrderInteraction) interaction;
List<HotspotChoice> choices = orderInteraction.getHotspotChoices();
if (choices.size() > 0) {
String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectOrderedIdentifierResponses(item, interaction);
for (int i = 0; i < choices.size(); i++) {
String currentResponse = null;
if (responses.size() > i) {
currentResponse = responses.get(i);
}
String correctAnswer = null;
if (correctAnswers.size() > i) {
correctAnswer = correctAnswers.get(i).toString();
}
if (correctAnswer != null && correctAnswer.equals(currentResponse)) {
dataRow.addCell(col++, currentResponse, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, currentResponse, null);
}
}
} else {
col++;
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class InlineChoiceInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
InlineChoiceInteraction choiceInteraction = (InlineChoiceInteraction) interaction;
List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectIdentifierResponses(item, interaction);
String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
if (StringHelper.containsNonWhitespace(stringuifiedResponse)) {
String inlineResponse = CorrectResponsesUtil.stripResponse(stringuifiedResponse);
Identifier responseIdentifier = Identifier.assumedLegal(inlineResponse);
boolean correct = false;
for (Identifier correctAnswer : correctAnswers) {
if (responseIdentifier.equals(correctAnswer)) {
correct = true;
break;
}
}
InlineChoice selectedChoice = choiceInteraction.getInlineChoice(responseIdentifier);
if (selectedChoice != null) {
String value = getTextContent(selectedChoice);
if (correct) {
dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, value);
}
} else {
col++;
}
} else {
col++;
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class OrderInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
OrderInteraction orderInteraction = (OrderInteraction) interaction;
List<SimpleChoice> choices = orderInteraction.getSimpleChoices();
if (choices.size() > 0) {
String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectOrderedIdentifierResponses(item, interaction);
for (int i = 0; i < choices.size(); i++) {
String currentResponse = null;
String currentResponseText = null;
if (responses.size() > i) {
currentResponse = currentResponseText = responses.get(i);
SimpleChoice selectedChoice = orderInteraction.getSimpleChoice(Identifier.assumedLegal(currentResponse));
if (selectedChoice != null) {
currentResponseText = getContent(selectedChoice);
}
}
String correctAnswer = null;
if (correctAnswers.size() > i) {
correctAnswer = correctAnswers.get(i).toString();
}
if (correctAnswer != null && correctAnswer.equals(currentResponse)) {
dataRow.addCell(col++, currentResponseText, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, currentResponseText, null);
}
}
} else {
col++;
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class HottextAssessmentItemBuilderTest method createHottextAssessmentItem_allCorrectAnswers.
/**
* A basic hottextInteraction with three choices. If all answers
* are correct, the SCORE is 3.0.
*
* @throws IOException
*/
@Test
public void createHottextAssessmentItem_allCorrectAnswers() 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.setMaxScore(3.0d);
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
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);
}
{
// wrong answer
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);
}
FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
Aggregations