use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class AssessmentTestDisplayController method handleTemporaryResponse.
private void handleTemporaryResponse(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap) {
NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
TestSessionState testSessionState = testSessionController.getTestSessionState();
TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
if (currentItemKey == null) {
//
return;
}
String cmd = ureq.getParameter("tmpResponse");
if (!qtiWorksCtrl.validateResponseIdentifierCommand(cmd, currentItemKey)) {
// this is not the right node in the plan
return;
}
final Date timestamp = ureq.getRequestTimestamp();
final Map<Identifier, ResponseData> responseDataMap = new HashMap<>();
if (stringResponseMap != null) {
for (final Entry<Identifier, ResponseInput> responseEntry : stringResponseMap.entrySet()) {
final Identifier identifier = responseEntry.getKey();
final ResponseInput responseData = responseEntry.getValue();
if (responseData instanceof StringInput) {
responseDataMap.put(identifier, new StringResponseData(((StringInput) responseData).getResponseData()));
}
}
}
ParentPartItemRefs parentParts = getParentSection(currentItemKey);
String assessmentItemIdentifier = currentItemKey.getIdentifier().toString();
AssessmentItemSession itemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, assessmentItemIdentifier);
TestPlanNode currentItemRefNode = testSessionState.getTestPlan().getNode(currentItemKey);
ItemSessionController itemSessionController = (ItemSessionController) testSessionController.getItemProcessingContext(currentItemRefNode);
ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
List<Interaction> interactions = itemSessionController.getInteractions();
Map<Identifier, Interaction> interactionMap = new HashMap<>();
for (Interaction interaction : interactions) {
interactionMap.put(interaction.getResponseIdentifier(), interaction);
}
Map<Identifier, AssessmentResponse> candidateResponseMap = qtiService.getAssessmentResponses(itemSession);
for (Entry<Identifier, ResponseData> responseEntry : responseDataMap.entrySet()) {
Identifier responseIdentifier = responseEntry.getKey();
ResponseData responseData = responseEntry.getValue();
AssessmentResponse candidateItemResponse;
if (candidateResponseMap.containsKey(responseIdentifier)) {
candidateItemResponse = candidateResponseMap.get(responseIdentifier);
} else {
candidateItemResponse = qtiService.createAssessmentResponse(candidateSession, itemSession, responseIdentifier.toString(), ResponseLegality.VALID, responseData.getType());
}
switch(responseData.getType()) {
case STRING:
{
List<String> data = ((StringResponseData) responseData).getResponseData();
String stringuifiedResponse = ResponseFormater.format(data);
candidateItemResponse.setStringuifiedResponse(stringuifiedResponse);
break;
}
default:
throw new OLATRuntimeException("Unexpected switch case: " + responseData.getType());
}
candidateResponseMap.put(responseIdentifier, candidateItemResponse);
itemSessionState.setRawResponseData(responseIdentifier, responseData);
try {
Interaction interaction = interactionMap.get(responseIdentifier);
interaction.bindResponse(itemSessionController, responseData);
} catch (final ResponseBindingException e) {
//
}
}
/* Copy uncommitted responses over */
for (final Entry<Identifier, Value> uncommittedResponseEntry : itemSessionState.getUncommittedResponseValues().entrySet()) {
final Identifier identifier = uncommittedResponseEntry.getKey();
final Value value = uncommittedResponseEntry.getValue();
itemSessionState.setResponseValue(identifier, value);
}
/* Persist CandidateResponse entities */
qtiService.recordTestAssessmentResponses(itemSession, candidateResponseMap.values());
/* Record resulting event */
final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.ITEM_EVENT, null, currentItemKey, testSessionState, notificationRecorder);
candidateAuditLogger.logCandidateEvent(candidateEvent, candidateResponseMap);
/* Record current result state */
AssessmentResult assessmentResult = computeTestAssessmentResult(timestamp, candidateSession);
synchronized (this) {
qtiService.recordTestAssessmentResult(candidateSession, testSessionState, assessmentResult, candidateAuditLogger);
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class AssessmentResultController method initFormSections.
private void initFormSections(FormLayoutContainer layoutCont, Results testResults) {
List<Results> itemResults = new ArrayList<>();
layoutCont.contextPut("itemResults", itemResults);
Map<Identifier, AssessmentItemRef> identifierToRefs = new HashMap<>();
for (AssessmentItemRef itemRef : resolvedAssessmentTest.getAssessmentItemRefs()) {
identifierToRefs.put(itemRef.getIdentifier(), itemRef);
}
Map<TestPlanNode, Results> resultsMap = new HashMap<>();
TestPlan testPlan = testSessionState.getTestPlan();
List<TestPlanNode> nodes = testPlan.getTestPlanNodeList();
for (TestPlanNode node : nodes) {
TestPlanNodeKey testPlanNodeKey = node.getKey();
TestNodeType testNodeType = node.getTestNodeType();
if (testNodeType == TestNodeType.ASSESSMENT_SECTION) {
Results r = new Results(true, node.getSectionPartTitle(), "o_mi_qtisection", options.isSectionSummary());
AssessmentSectionSessionState sectionState = testSessionState.getAssessmentSectionSessionStates().get(testPlanNodeKey);
if (sectionState != null) {
r.setSessionState(sectionState);
}
resultsMap.put(node, r);
itemResults.add(r);
testResults.setNumberOfSections(testResults.getNumberOfSections() + 1);
} else if (testNodeType == TestNodeType.ASSESSMENT_ITEM_REF) {
Results results = initFormItemResult(layoutCont, node, identifierToRefs, resultsMap);
if (results != null) {
itemResults.add(results);
}
testResults.setNumberOfQuestions(testResults.getNumberOfQuestions() + 1);
if (results.sessionStatus == SessionStatus.FINAL) {
testResults.setNumberOfAnsweredQuestions(testResults.getNumberOfAnsweredQuestions() + 1);
}
if (results.hasMaxScore()) {
testResults.addMaxScore(results);
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class AssessmentResultController method initFormItemResult.
private Results initFormItemResult(FormLayoutContainer layoutCont, TestPlanNode node, Map<Identifier, AssessmentItemRef> identifierToRefs, Map<TestPlanNode, Results> resultsMap) {
TestPlanNodeKey testPlanNodeKey = node.getKey();
Identifier identifier = testPlanNodeKey.getIdentifier();
AssessmentItemRef itemRef = identifierToRefs.get(identifier);
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
QTI21QuestionType type = QTI21QuestionType.getType(assessmentItem);
AssessmentItemSession itemSession = identifierToItemSession.get(identifier.toString());
Results r = new Results(false, node.getSectionPartTitle(), type.getCssClass(), options.isQuestionSummary());
// init
r.setSessionStatus(null);
r.setItemIdentifier(node.getIdentifier().toString());
ItemSessionState sessionState = testSessionState.getItemSessionStates().get(testPlanNodeKey);
if (sessionState != null) {
r.setSessionState(sessionState);
SessionStatus sessionStatus = sessionState.getSessionStatus();
if (sessionState != null) {
r.setSessionStatus(sessionStatus);
}
}
ItemResult itemResult = assessmentResult.getItemResult(identifier.toString());
if (itemResult != null) {
extractOutcomeVariable(itemResult.getItemVariables(), r);
}
if (itemSession != null) {
if (itemSession.getManualScore() != null) {
r.setScore(itemSession.getManualScore());
r.setManualScore(itemSession.getManualScore());
}
r.setComment(itemSession.getCoachComment());
}
// update max score of section
if (options.isUserSolutions() || options.isCorrectSolutions()) {
InteractionResults interactionResults = initFormItemInteractions(layoutCont, sessionState, resolvedAssessmentItem);
r.setInteractionResults(interactionResults);
if (options.isCorrectSolutions()) {
String correctSolutionId = "correctSolutionItem" + count++;
FeedbackResultFormItem correctSolutionItem = new FeedbackResultFormItem(correctSolutionId, resolvedAssessmentItem);
initInteractionResultFormItem(correctSolutionItem, sessionState);
layoutCont.add(correctSolutionId, correctSolutionItem);
r.setCorrectSolutionItem(correctSolutionItem);
}
}
updateSectionScoreInformations(node, r, resultsMap);
return r;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class AssessmentTestComponentRenderer method renderPrintedVariable.
@Override
protected void renderPrintedVariable(AssessmentRenderer renderer, StringOutput sb, AssessmentObjectComponent component, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, PrintedVariable printedVar) {
AssessmentTestComponent testCmp = (AssessmentTestComponent) component;
Identifier identifier = printedVar.getIdentifier();
sb.append("<span class='printedVariable'>");
if (itemSessionState == null) {
Value outcomeValue = testCmp.getTestSessionController().getTestSessionState().getOutcomeValue(identifier);
if (outcomeValue != null) {
OutcomeDeclaration outcomeDeclaration = testCmp.getAssessmentTest().getOutcomeDeclaration(identifier);
renderPrintedVariable(renderer, sb, printedVar, outcomeDeclaration, outcomeValue);
}
} else {
Value templateValue = itemSessionState.getTemplateValues().get(identifier);
Value outcomeValue = itemSessionState.getOutcomeValues().get(identifier);
if (outcomeValue != null) {
OutcomeDeclaration outcomeDeclaration = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful().getOutcomeDeclaration(identifier);
renderPrintedVariable(renderer, sb, printedVar, outcomeDeclaration, outcomeValue);
} else if (templateValue != null) {
TemplateDeclaration templateDeclaration = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful().getTemplateDeclaration(identifier);
renderPrintedVariable(renderer, sb, printedVar, templateDeclaration, templateValue);
} else {
sb.append("(variable ").append(identifier.toString()).append(" was not found)");
}
}
sb.append("</span>");
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class FIBAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title, EntryType type) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.fib, title);
// define the response
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
if (type == EntryType.numerical) {
ResponseDeclaration responseDeclaration = createNumericalEntryResponseDeclaration(assessmentItem, responseDeclarationId, 42);
assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
} else {
ResponseDeclaration responseDeclaration = createTextEntryResponseDeclaration(assessmentItem, responseDeclarationId, "gap", Collections.emptyList());
assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
}
// outcomes
appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
appendTextEntryInteraction(itemBody, responseDeclarationId);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
Aggregations