use of org.olat.ims.qti21.AssessmentItemSession in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method calculateSectionScore.
private BigDecimal calculateSectionScore(SessionResponses responses, SectionInfos section) {
BigDecimal sectionScore = BigDecimal.valueOf(0l);
for (ItemInfos item : section.getItemInfos()) {
AssessmentItemRef itemRef = item.getAssessmentItemRef();
String itemRefIdentifier = itemRef.getIdentifier().toString();
AssessmentItemSession itemSession = responses.getItemSession(itemRefIdentifier);
if (itemSession != null) {
if (itemSession.getManualScore() != null) {
sectionScore = sectionScore.add(itemSession.getManualScore());
} else if (itemSession.getScore() != null) {
sectionScore = sectionScore.add(itemSession.getScore());
}
}
}
return sectionScore;
}
use of org.olat.ims.qti21.AssessmentItemSession in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method writeData.
/**
* The 2 lists, sessions and responses are order by the user name and the test session key.
* @param sessions A list of test sessions ordered by test session key
* @param responses A list of responses ordered by test session key
* @param exportSheet
* @param workbook
*/
private void writeData(List<AssessmentTestSession> sessions, List<AssessmentResponse> responses, OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
int numOfSessions = sessions.size();
Map<AssessmentTestSession, SessionResponses> sessionToResponses = new HashMap<>();
for (int i = 0; i < numOfSessions; i++) {
AssessmentTestSession testSession = sessions.get(i);
sessionToResponses.put(testSession, new SessionResponses(testSession));
}
int numOfResponses = responses.size();
for (int j = 0; j < numOfResponses; j++) {
AssessmentResponse response = responses.get(j);
AssessmentItemSession itemSession = response.getAssessmentItemSession();
AssessmentTestSession responseTestSession = itemSession.getAssessmentTestSession();
SessionResponses sessionResponses = sessionToResponses.get(responseTestSession);
if (sessionResponses != null) {
sessionResponses.addResponse(itemSession, response);
}
}
for (int i = 0; i < numOfSessions; i++) {
AssessmentTestSession testSession = sessions.get(i);
SessionResponses sessionResponses = sessionToResponses.get(testSession);
writeDataRow(i + 2, sessionResponses, exportSheet, workbook);
}
}
use of org.olat.ims.qti21.AssessmentItemSession in project OpenOLAT by OpenOLAT.
the class AssessmentItemSessionDAO method createAndPersistAssessmentItemSession.
public AssessmentItemSession createAndPersistAssessmentItemSession(AssessmentTestSession assessmentTestSession, ParentPartItemRefs parentParts, String assessmentItemIdentifier) {
AssessmentItemSessionImpl itemSession = new AssessmentItemSessionImpl();
Date now = new Date();
itemSession.setCreationDate(now);
itemSession.setLastModified(now);
itemSession.setAssessmentItemIdentifier(assessmentItemIdentifier);
itemSession.setAssessmentTestSession(assessmentTestSession);
if (parentParts != null) {
itemSession.setSectionIdentifier(parentParts.getSectionIdentifier());
itemSession.setTestPartIdentifier(parentParts.getTestPartIdentifier());
}
dbInstance.getCurrentEntityManager().persist(itemSession);
return itemSession;
}
use of org.olat.ims.qti21.AssessmentItemSession in project OpenOLAT by OpenOLAT.
the class QTI21ServiceImpl method getAssessmentResponses.
@Override
public Map<Identifier, AssessmentResponse> getAssessmentResponses(AssessmentItemSession assessmentItemSession) {
List<AssessmentResponse> responses = testResponseDao.getResponses(assessmentItemSession);
Map<Identifier, AssessmentResponse> responseMap = new HashMap<>();
for (AssessmentResponse response : responses) {
responseMap.put(Identifier.assumedLegal(response.getResponseIdentifier()), response);
}
return responseMap;
}
use of org.olat.ims.qti21.AssessmentItemSession 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);
}
}
Aggregations