use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project openolat by klemens.
the class FIBEditorController method createEntry.
private AbstractEntry createEntry(String responseIdentifier, String selectedText, String type, boolean newEntry) {
AbstractEntry interaction = null;
if ("string".equalsIgnoreCase(type)) {
TextEntry textInteraction = itemBuilder.createTextEntry(responseIdentifier);
if (StringHelper.containsNonWhitespace(selectedText)) {
String[] alternatives = selectedText.split(",");
for (String alternative : alternatives) {
if (StringHelper.containsNonWhitespace(alternative)) {
alternative = alternative.trim();
if (textInteraction.getSolution() == null) {
textInteraction.setSolution(alternative);
} else {
textInteraction.addAlternative(alternative, textInteraction.getScore());
}
}
}
if (alternatives.length > 0) {
String solution = alternatives[0];
if (newEntry && "gap".equals(solution)) {
solution = "";
}
textInteraction.setSolution(solution);
}
}
interaction = textInteraction;
} else if ("float".equalsIgnoreCase(type)) {
NumericalEntry numericalInteraction = itemBuilder.createNumericalEntry(responseIdentifier);
if (newEntry && "gap".equals(selectedText)) {
// skip it, it's a placeholder
} else if (StringHelper.containsNonWhitespace(selectedText)) {
try {
Double val = Double.parseDouble(selectedText.trim());
numericalInteraction.setSolution(val);
} catch (NumberFormatException e) {
//
}
}
interaction = numericalInteraction;
}
return interaction;
}
use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project openolat by klemens.
the class FIBEditorController method doGapEntry.
private void doGapEntry(UserRequest ureq, String responseIdentifier, String selectedText, String emptySolution, String type, boolean newEntry) {
if (textEntrySettingsCtrl != null || numericalEntrySettingsCtrl != null)
return;
AbstractEntry interaction = itemBuilder.getEntry(responseIdentifier);
if (interaction == null) {
interaction = createEntry(responseIdentifier, selectedText, type, newEntry);
} else if (StringHelper.containsNonWhitespace(selectedText)) {
updateSolution(interaction, selectedText, emptySolution);
}
if (interaction instanceof TextEntry) {
textEntrySettingsCtrl = new FIBTextEntrySettingsController(ureq, getWindowControl(), (TextEntry) interaction, restrictedEdit, readOnly);
listenTo(textEntrySettingsCtrl);
cmc = new CloseableModalController(getWindowControl(), translate("close"), textEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
cmc.activate();
listenTo(cmc);
} else if (interaction instanceof NumericalEntry) {
numericalEntrySettingsCtrl = new FIBNumericalEntrySettingsController(ureq, getWindowControl(), (NumericalEntry) interaction, restrictedEdit, readOnly);
listenTo(numericalEntrySettingsCtrl);
cmc = new CloseableModalController(getWindowControl(), translate("close"), numericalEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
cmc.activate();
listenTo(cmc);
}
}
use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project OpenOLAT by OpenOLAT.
the class FIBEditorController method createEntry.
private AbstractEntry createEntry(String responseIdentifier, String selectedText, String type, boolean newEntry) {
AbstractEntry interaction = null;
if ("string".equalsIgnoreCase(type)) {
TextEntry textInteraction = itemBuilder.createTextEntry(responseIdentifier);
if (StringHelper.containsNonWhitespace(selectedText)) {
String[] alternatives = selectedText.split(",");
for (String alternative : alternatives) {
if (StringHelper.containsNonWhitespace(alternative)) {
alternative = alternative.trim();
if (textInteraction.getSolution() == null) {
textInteraction.setSolution(alternative);
} else {
textInteraction.addAlternative(alternative, textInteraction.getScore());
}
}
}
if (alternatives.length > 0) {
String solution = alternatives[0];
if (newEntry && "gap".equals(solution)) {
solution = "";
}
textInteraction.setSolution(solution);
}
}
interaction = textInteraction;
} else if ("float".equalsIgnoreCase(type)) {
NumericalEntry numericalInteraction = itemBuilder.createNumericalEntry(responseIdentifier);
if (newEntry && "gap".equals(selectedText)) {
// skip it, it's a placeholder
} else if (StringHelper.containsNonWhitespace(selectedText)) {
try {
Double val = Double.parseDouble(selectedText.trim());
numericalInteraction.setSolution(val);
} catch (NumberFormatException e) {
//
}
}
interaction = numericalInteraction;
}
return interaction;
}
use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project OpenOLAT by OpenOLAT.
the class FIBEditorController method doGapEntry.
private void doGapEntry(UserRequest ureq, String responseIdentifier, String selectedText, String emptySolution, String type, boolean newEntry) {
if (textEntrySettingsCtrl != null || numericalEntrySettingsCtrl != null)
return;
AbstractEntry interaction = itemBuilder.getEntry(responseIdentifier);
if (interaction == null) {
interaction = createEntry(responseIdentifier, selectedText, type, newEntry);
} else if (StringHelper.containsNonWhitespace(selectedText)) {
updateSolution(interaction, selectedText, emptySolution);
}
if (interaction instanceof TextEntry) {
textEntrySettingsCtrl = new FIBTextEntrySettingsController(ureq, getWindowControl(), (TextEntry) interaction, restrictedEdit, readOnly);
listenTo(textEntrySettingsCtrl);
cmc = new CloseableModalController(getWindowControl(), translate("close"), textEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
cmc.activate();
listenTo(cmc);
} else if (interaction instanceof NumericalEntry) {
numericalEntrySettingsCtrl = new FIBNumericalEntrySettingsController(ureq, getWindowControl(), (NumericalEntry) interaction, restrictedEdit, readOnly);
listenTo(numericalEntrySettingsCtrl);
cmc = new CloseableModalController(getWindowControl(), translate("close"), numericalEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
cmc.activate();
listenTo(cmc);
}
}
use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry in project OpenOLAT by OpenOLAT.
the class FIBAssessmentItemBuilder method extractEntriesSettingsFromResponseDeclaration.
/**
* We loop around the textEntryInteraction, search the responseDeclaration. responseDeclaration
* of type string are gap text, of type float are numerical.
*/
public void extractEntriesSettingsFromResponseDeclaration() {
DoubleAdder mappedScore = new DoubleAdder();
AtomicInteger countAlternatives = new AtomicInteger(0);
responseIdentifierToTextEntry = new HashMap<>();
List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
for (Interaction interaction : interactions) {
if (interaction instanceof TextEntryInteraction && interaction.getResponseIdentifier() != null) {
AbstractEntry entry = null;
TextEntryInteraction textInteraction = (TextEntryInteraction) interaction;
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
if (responseDeclaration != null) {
if (responseDeclaration.hasBaseType(BaseType.STRING) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
TextEntry textEntry = new TextEntry(textInteraction);
extractTextEntrySettingsFromResponseDeclaration(textEntry, responseDeclaration, countAlternatives, mappedScore);
String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
question = question.replace(marker, marker + " openolatType=\"string\"");
if (StringHelper.containsNonWhitespace(textEntry.getSolution())) {
question = question.replace(marker, marker + " data-qti-solution=\"" + escapeForDataQtiSolution(textEntry.getSolution()) + "\"");
}
entry = textEntry;
} else if (responseDeclaration.hasBaseType(BaseType.FLOAT) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
NumericalEntry numericalEntry = new NumericalEntry(textInteraction);
entry = numericalEntry;
extractNumericalEntrySettings(assessmentItem, numericalEntry, responseDeclaration, countAlternatives, mappedScore);
String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
question = question.replace(marker, marker + " openolatType=\"float\"");
if (numericalEntry.getSolution() != null) {
question = question.replace(marker, marker + " data-qti-solution=\"" + Double.toString(numericalEntry.getSolution()) + "\"");
}
}
}
if (entry != null) {
responseIdentifierToTextEntry.put(interaction.getResponseIdentifier().toString(), entry);
}
}
}
boolean hasMapping = Math.abs(mappedScore.doubleValue() - (-1.0 * countAlternatives.get())) > 0.0001;
scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Aggregations