Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java =================================================================== diff -u -rbfad24196397ef8759dd17934284e5dfdbc45ff6 -r0e92f71d29f60886f28fd0a6bed3c351a44fd5cf --- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision bfad24196397ef8759dd17934284e5dfdbc45ff6) +++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision 0e92f71d29f60886f28fd0a6bed3c351a44fd5cf) @@ -116,6 +116,7 @@ import org.lamsfoundation.lams.tool.assessment.model.QuestionReference; import org.lamsfoundation.lams.tool.assessment.util.AnswerIntComparator; import org.lamsfoundation.lams.tool.assessment.util.AssessmentEscapeUtils; +import org.lamsfoundation.lams.tool.assessment.util.AssessmentEscapeUtils.AssessmentExcelCell; import org.lamsfoundation.lams.tool.assessment.util.AssessmentSessionComparator; import org.lamsfoundation.lams.tool.assessment.util.SequencableComparator; import org.lamsfoundation.lams.tool.assessment.web.controller.LearningWebsocketServer; @@ -1909,7 +1910,10 @@ } } else { - AssessmentEscapeUtils.addResponseCellForExcelExport(questionResult, userResultRow, false); + AssessmentExcelCell assessmentCell = AssessmentEscapeUtils + .addResponseCellForExcelExport(questionResult, false); + userResultRow.addCell(assessmentCell.value, + assessmentCell.isHighlighted ? IndexedColors.GREEN : IndexedColors.AUTOMATIC); if (doSummaryTable) { summaryNACount = updateSummaryCounts(question, questionResult, summaryOfAnswers, @@ -1968,176 +1972,177 @@ } } - { - // ------------------------------------------------------------------ - // -------------- Third tab: User Summary --------------------------- + /* + * ------------------------------------------------------------------ + * // -------------- Third tab: User Summary --------------------------- + * + * ExcelSheet userSummarySheet = new ExcelSheet(getMessage("label.export.summary.by.user")); + * sheets.add(userSummarySheet); + * + * // Create the question summary + * ExcelRow userSummaryTitle = userSummarySheet.initRow(); + * userSummaryTitle.addCell(getMessage("label.export.user.summary"), true); + * + * ExcelRow summaryRowTitle = userSummarySheet.initRow(); + * summaryRowTitle.addCell("#", true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); + * summaryRowTitle.addCell(getMessage("label.monitoring.question.summary.question"), true, + * ExcelCell.BORDER_STYLE_BOTTOM_THIN); + * summaryRowTitle.addCell(getMessage("label.authoring.basic.list.header.type"), true, + * ExcelCell.BORDER_STYLE_BOTTOM_THIN); + * summaryRowTitle.addCell(getMessage("label.authoring.basic.penalty.factor"), true, + * ExcelCell.BORDER_STYLE_BOTTOM_THIN); + * summaryRowTitle.addCell(getMessage("label.monitoring.question.summary.default.mark"), true, + * ExcelCell.BORDER_STYLE_BOTTOM_THIN); + * summaryRowTitle.addCell(getMessage("label.monitoring.question.summary.average.mark"), true, + * ExcelCell.BORDER_STYLE_BOTTOM_THIN); + * + * Float totalGradesPossible = 0F; + * Float totalAverage = 0F; + * int questionIndex = 1; + * if (assessment.getQuestionReferences() != null) { + * Set questionReferences = new TreeSet<>(new SequencableComparator()); + * questionReferences.addAll(assessment.getQuestionReferences()); + * + * int randomQuestionsCount = 1; + * for (QuestionReference questionReference : questionReferences) { + * + * String title; + * String questionType; + * Float penaltyFactor; + * Float averageMark = null; + * if (questionReference.isRandomQuestion()) { + * + * title = getMessage("label.authoring.basic.type.random.question") + randomQuestionsCount++; + * questionType = getMessage("label.authoring.basic.type.random.question"); + * penaltyFactor = null; + * averageMark = null; + * } else { + * + * AssessmentQuestion question = questionReference.getQuestion(); + * title = question.getQbQuestion().getName(); + * questionType = AssessmentServiceImpl.getQuestionTypeLanguageLabel(question.getType()); + * penaltyFactor = question.getQbQuestion().getPenaltyFactor(); + * + * QuestionSummary questionSummary = questionSummaries.get(question.getUid()); + * if (questionSummary != null) { + * averageMark = questionSummary.getAverageMark(); + * totalAverage += questionSummary.getAverageMark(); + * } + * } + * + * int maxGrade = questionReference.getMaxMark(); + * totalGradesPossible += maxGrade; + * + * ExcelRow questCellRow = userSummarySheet.initRow(); + * questCellRow.addCell(questionIndex++); + * questCellRow.addCell(title); + * questCellRow.addCell(questionType); + * questCellRow.addCell(penaltyFactor); + * questCellRow.addCell(maxGrade); + * questCellRow.addCell(averageMark); + * } + * + * if (totalGradesPossible.floatValue() > 0) { + * ExcelRow totalCellRow = userSummarySheet.initRow(); + * totalCellRow.addEmptyCells(2); + * totalCellRow.addCell(getMessage("label.monitoring.summary.total"), true); + * totalCellRow.addCell(totalGradesPossible); + * totalCellRow.addCell(totalAverage); + * } + * userSummarySheet.addEmptyRow(); + * } + * + * if (sessionDtos != null) { + * List assessmentResults = assessmentResultDao + * .getLastFinishedAssessmentResults(assessment.getContentId()); + * Map userUidToResultMap = new HashMap<>(); + * for (AssessmentResult assessmentResult : assessmentResults) { + * userUidToResultMap.put(assessmentResult.getUser().getUid(), assessmentResult); + * } + * + * for (SessionDTO sessionDTO : sessionDtos) { + * userSummarySheet.addEmptyRow(); + * + * ExcelRow sessionTitle = userSummarySheet.initRow(); + * sessionTitle.addCell(sessionDTO.getSessionName(), true); + * + * AssessmentSession assessmentSession = getSessionBySessionId(sessionDTO.getSessionId()); + * Set assessmentUsers = assessmentSession.getAssessmentUsers(); + * if (assessmentUsers != null) { + * for (AssessmentUser assessmentUser : assessmentUsers) { + * ExcelRow userTitleRow = userSummarySheet.initRow(); + * userTitleRow.addCell(getMessage("label.export.user.id"), true); + * userTitleRow.addCell(getMessage("label.monitoring.user.summary.full.name"), true); + * userTitleRow.addCell(getMessage("label.export.date.attempted"), true); + * userTitleRow.addCell(getMessage("label.monitoring.question.summary.question"), true); + * userTitleRow.addCell(getMessage("label.authoring.basic.option.answer"), true); + * if (assessment.isEnableConfidenceLevels()) { + * userTitleRow.addCell(getMessage("label.confidence"), true); + * } + * userTitleRow.addCell(getMessage("label.export.mark"), true); + * + * if (assessment.isAllowAnswerJustification()) { + * userTitleRow.addCell(getMessage("label.answer.justification"), true); + * } + * + * AssessmentResult assessmentResult = userUidToResultMap.get(assessmentUser.getUid()); + * if (assessmentResult != null) { + * Set questionResults = assessmentResult.getQuestionResults(); + * if (questionResults != null) { + * for (AssessmentQuestionResult questionResult : questionResults) { + * ExcelRow userResultRow = userSummarySheet.initRow(); + * userResultRow.addCell(assessmentUser.getLoginName()); + * userResultRow.addCell(assessmentUser.getFullName()); + * userResultRow.addCell(assessmentResult.getStartDate()); + * userResultRow.addCell(questionResult.getQbQuestion().getName()); + * + * AssessmentEscapeUtils.addResponseCellForExcelExport(questionResult, + * userResultRow, false); + * + * if (assessment.isEnableConfidenceLevels()) { + * String confidenceLevel = null; + * + * switch (assessment.getConfidenceLevelsType()) { + * case 2: + * confidenceLevel = new String[] { getMessage("label.not.confident"), + * getMessage("label.confident"), + * getMessage("label.very.confident") }[questionResult + * .getConfidenceLevel() / 5]; + * break; + * case 3: + * confidenceLevel = new String[] { getMessage("label.not.sure"), + * getMessage("label.sure"), + * getMessage("label.very.sure") }[questionResult + * .getConfidenceLevel() / 5]; + * break; + * default: + * confidenceLevel = questionResult.getConfidenceLevel() * 10 + "%"; + * } + * + * userResultRow.addCell(confidenceLevel); + * } + * + * userResultRow.addCell(questionResult.getMark()); + * + * if (assessment.isAllowAnswerJustification()) { + * userResultRow.addCell(AssessmentEscapeUtils + * .escapeStringForExcelExport(questionResult.getJustification())); + * } + * } + * } + * + * ExcelRow userTotalRow = userSummarySheet.initRow(); + * userTotalRow.addEmptyCells(assessment.isEnableConfidenceLevels() ? 5 : 4); + * userTotalRow.addCell(getMessage("label.monitoring.summary.total"), true); + * userTotalRow.addCell(assessmentResult.getGrade()); + * userSummarySheet.addEmptyRow(); + * } + * } + * } + * } + * } + */ - ExcelSheet userSummarySheet = new ExcelSheet(getMessage("label.export.summary.by.user")); - sheets.add(userSummarySheet); - - // Create the question summary - ExcelRow userSummaryTitle = userSummarySheet.initRow(); - userSummaryTitle.addCell(getMessage("label.export.user.summary"), true); - - ExcelRow summaryRowTitle = userSummarySheet.initRow(); - summaryRowTitle.addCell("#", true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle.addCell(getMessage("label.monitoring.question.summary.question"), true, - ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle.addCell(getMessage("label.authoring.basic.list.header.type"), true, - ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle.addCell(getMessage("label.authoring.basic.penalty.factor"), true, - ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle.addCell(getMessage("label.monitoring.question.summary.default.mark"), true, - ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle.addCell(getMessage("label.monitoring.question.summary.average.mark"), true, - ExcelCell.BORDER_STYLE_BOTTOM_THIN); - - Float totalGradesPossible = 0F; - Float totalAverage = 0F; - int questionIndex = 1; - if (assessment.getQuestionReferences() != null) { - Set questionReferences = new TreeSet<>(new SequencableComparator()); - questionReferences.addAll(assessment.getQuestionReferences()); - - int randomQuestionsCount = 1; - for (QuestionReference questionReference : questionReferences) { - - String title; - String questionType; - Float penaltyFactor; - Float averageMark = null; - if (questionReference.isRandomQuestion()) { - - title = getMessage("label.authoring.basic.type.random.question") + randomQuestionsCount++; - questionType = getMessage("label.authoring.basic.type.random.question"); - penaltyFactor = null; - averageMark = null; - } else { - - AssessmentQuestion question = questionReference.getQuestion(); - title = question.getQbQuestion().getName(); - questionType = AssessmentServiceImpl.getQuestionTypeLanguageLabel(question.getType()); - penaltyFactor = question.getQbQuestion().getPenaltyFactor(); - - QuestionSummary questionSummary = questionSummaries.get(question.getUid()); - if (questionSummary != null) { - averageMark = questionSummary.getAverageMark(); - totalAverage += questionSummary.getAverageMark(); - } - } - - int maxGrade = questionReference.getMaxMark(); - totalGradesPossible += maxGrade; - - ExcelRow questCellRow = userSummarySheet.initRow(); - questCellRow.addCell(questionIndex++); - questCellRow.addCell(title); - questCellRow.addCell(questionType); - questCellRow.addCell(penaltyFactor); - questCellRow.addCell(maxGrade); - questCellRow.addCell(averageMark); - } - - if (totalGradesPossible.floatValue() > 0) { - ExcelRow totalCellRow = userSummarySheet.initRow(); - totalCellRow.addEmptyCells(2); - totalCellRow.addCell(getMessage("label.monitoring.summary.total"), true); - totalCellRow.addCell(totalGradesPossible); - totalCellRow.addCell(totalAverage); - } - userSummarySheet.addEmptyRow(); - } - - if (sessionDtos != null) { - List assessmentResults = assessmentResultDao - .getLastFinishedAssessmentResults(assessment.getContentId()); - Map userUidToResultMap = new HashMap<>(); - for (AssessmentResult assessmentResult : assessmentResults) { - userUidToResultMap.put(assessmentResult.getUser().getUid(), assessmentResult); - } - - for (SessionDTO sessionDTO : sessionDtos) { - userSummarySheet.addEmptyRow(); - - ExcelRow sessionTitle = userSummarySheet.initRow(); - sessionTitle.addCell(sessionDTO.getSessionName(), true); - - AssessmentSession assessmentSession = getSessionBySessionId(sessionDTO.getSessionId()); - Set assessmentUsers = assessmentSession.getAssessmentUsers(); - if (assessmentUsers != null) { - for (AssessmentUser assessmentUser : assessmentUsers) { - ExcelRow userTitleRow = userSummarySheet.initRow(); - userTitleRow.addCell(getMessage("label.export.user.id"), true); - userTitleRow.addCell(getMessage("label.monitoring.user.summary.full.name"), true); - userTitleRow.addCell(getMessage("label.export.date.attempted"), true); - userTitleRow.addCell(getMessage("label.monitoring.question.summary.question"), true); - userTitleRow.addCell(getMessage("label.authoring.basic.option.answer"), true); - if (assessment.isEnableConfidenceLevels()) { - userTitleRow.addCell(getMessage("label.confidence"), true); - } - userTitleRow.addCell(getMessage("label.export.mark"), true); - - if (assessment.isAllowAnswerJustification()) { - userTitleRow.addCell(getMessage("label.answer.justification"), true); - } - - AssessmentResult assessmentResult = userUidToResultMap.get(assessmentUser.getUid()); - if (assessmentResult != null) { - Set questionResults = assessmentResult.getQuestionResults(); - if (questionResults != null) { - for (AssessmentQuestionResult questionResult : questionResults) { - ExcelRow userResultRow = userSummarySheet.initRow(); - userResultRow.addCell(assessmentUser.getLoginName()); - userResultRow.addCell(assessmentUser.getFullName()); - userResultRow.addCell(assessmentResult.getStartDate()); - userResultRow.addCell(questionResult.getQbQuestion().getName()); - - AssessmentEscapeUtils.addResponseCellForExcelExport(questionResult, - userResultRow, false); - - if (assessment.isEnableConfidenceLevels()) { - String confidenceLevel = null; - - switch (assessment.getConfidenceLevelsType()) { - case 2: - confidenceLevel = new String[] { getMessage("label.not.confident"), - getMessage("label.confident"), - getMessage("label.very.confident") }[questionResult - .getConfidenceLevel() / 5]; - break; - case 3: - confidenceLevel = new String[] { getMessage("label.not.sure"), - getMessage("label.sure"), - getMessage("label.very.sure") }[questionResult - .getConfidenceLevel() / 5]; - break; - default: - confidenceLevel = questionResult.getConfidenceLevel() * 10 + "%"; - } - - userResultRow.addCell(confidenceLevel); - } - - userResultRow.addCell(questionResult.getMark()); - - if (assessment.isAllowAnswerJustification()) { - userResultRow.addCell(AssessmentEscapeUtils - .escapeStringForExcelExport(questionResult.getJustification())); - } - } - } - - ExcelRow userTotalRow = userSummarySheet.initRow(); - userTotalRow.addEmptyCells(assessment.isEnableConfidenceLevels() ? 5 : 4); - userTotalRow.addCell(getMessage("label.monitoring.summary.total"), true); - userTotalRow.addCell(assessmentResult.getGrade()); - userSummarySheet.addEmptyRow(); - } - } - } - } - } - } // ------------------------------------------------------------------ // -------------- Third tab: Learner summary --------------------------- @@ -2255,7 +2260,10 @@ userResultRow.addCell(questionResult.getMark(), ExcelCell.BORDER_STYLE_LEFT_THIN); // option chosen or full answer - AssessmentEscapeUtils.addResponseCellForExcelExport(questionResult, userResultRow, true); + AssessmentExcelCell assessmentCell = AssessmentEscapeUtils + .addResponseCellForExcelExport(questionResult, true); + userResultRow.addCell(assessmentCell.value, + assessmentCell.isHighlighted ? IndexedColors.GREEN : IndexedColors.AUTOMATIC); // learner interaction QbQuestion question = questionResult.getQbQuestion(); Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/util/AssessmentEscapeUtils.java =================================================================== diff -u -rcea7b9b1c1155b6499f4a7fe9cba545f1686ce27 -r0e92f71d29f60886f28fd0a6bed3c351a44fd5cf --- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/util/AssessmentEscapeUtils.java (.../AssessmentEscapeUtils.java) (revision cea7b9b1c1155b6499f4a7fe9cba545f1686ce27) +++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/util/AssessmentEscapeUtils.java (.../AssessmentEscapeUtils.java) (revision 0e92f71d29f60886f28fd0a6bed3c351a44fd5cf) @@ -27,7 +27,6 @@ import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; -import org.apache.poi.ss.usermodel.IndexedColors; import org.lamsfoundation.lams.qb.model.QbOption; import org.lamsfoundation.lams.qb.model.QbQuestion; import org.lamsfoundation.lams.tool.assessment.dto.AssessmentResultDTO; @@ -38,10 +37,19 @@ import org.lamsfoundation.lams.tool.assessment.dto.UserSummaryItem; import org.lamsfoundation.lams.tool.assessment.model.AssessmentOptionAnswer; import org.lamsfoundation.lams.tool.assessment.model.AssessmentQuestionResult; -import org.lamsfoundation.lams.util.excel.ExcelRow; public class AssessmentEscapeUtils { + public static class AssessmentExcelCell { + public Object value; + public boolean isHighlighted; + + private AssessmentExcelCell(Object value, boolean isHighlighted) { + this.value = value; + this.isHighlighted = isHighlighted; + } + } + /** * Escapes all characters that may brake JS code on assigning Java value to JS String variable (particularly escapes * all quotes in the following way \"). @@ -230,46 +238,35 @@ /** * Used only for excell export (for getUserSummaryData() method). */ - public static void addResponseCellForExcelExport(AssessmentQuestionResult questionResult, ExcelRow row, + public static AssessmentExcelCell addResponseCellForExcelExport(AssessmentQuestionResult questionResult, boolean useLettersForMcq) { if (questionResult == null) { - row.addEmptyCell(); - return; + return null; } - Object value = null; switch (questionResult.getQbQuestion().getType()) { case QbQuestion.TYPE_ESSAY: - value = AssessmentEscapeUtils.escapeStringForExcelExport(questionResult.getAnswer()); - break; + Object value = AssessmentEscapeUtils.escapeStringForExcelExport(questionResult.getAnswer()); + return new AssessmentExcelCell(value, false); case QbQuestion.TYPE_MATCHING_PAIRS: - AssessmentEscapeUtils.getOptionResponse(questionResult, QbQuestion.TYPE_MATCHING_PAIRS, row, - useLettersForMcq); - return; + return AssessmentEscapeUtils.getOptionResponse(questionResult, QbQuestion.TYPE_MATCHING_PAIRS, false); case QbQuestion.TYPE_MULTIPLE_CHOICE: - AssessmentEscapeUtils.getOptionResponse(questionResult, QbQuestion.TYPE_MULTIPLE_CHOICE, row, + return AssessmentEscapeUtils.getOptionResponse(questionResult, QbQuestion.TYPE_MULTIPLE_CHOICE, useLettersForMcq); - return; case QbQuestion.TYPE_NUMERICAL: - value = questionResult.getAnswer(); - break; + return new AssessmentExcelCell(questionResult.getAnswer(), false); case QbQuestion.TYPE_ORDERING: - AssessmentEscapeUtils.getOptionResponse(questionResult, QbQuestion.TYPE_ORDERING, row, - useLettersForMcq); - return; + return AssessmentEscapeUtils.getOptionResponse(questionResult, QbQuestion.TYPE_ORDERING, false); case QbQuestion.TYPE_VERY_SHORT_ANSWERS: - value = questionResult.getAnswer(); - break; + return new AssessmentExcelCell(questionResult.getAnswer(), false); case QbQuestion.TYPE_TRUE_FALSE: boolean isCorrect = questionResult.getQbQuestion().getCorrectAnswer() == questionResult .getAnswerBoolean(); - row.addCell(questionResult.getAnswerBoolean(), - isCorrect ? IndexedColors.GREEN : IndexedColors.AUTOMATIC); - return; + return new AssessmentExcelCell(questionResult.getAnswerBoolean(), isCorrect); case QbQuestion.TYPE_MARK_HEDGING: //taken care beforehand } - row.addCell(value); + return null; } public static String escapeStringForExcelExport(String input) { @@ -279,7 +276,7 @@ /** * Used only for excell export (for getUserSummaryData() method). */ - private static void getOptionResponse(AssessmentQuestionResult questionResult, int type, ExcelRow row, + private static AssessmentExcelCell getOptionResponse(AssessmentQuestionResult questionResult, int type, boolean useLettersForMcq) { StringBuilder sb = new StringBuilder(); @@ -291,7 +288,7 @@ Set optionAnswers = questionResult.getOptionAnswers(); if (optionAnswers != null) { if (type == QbQuestion.TYPE_MULTIPLE_CHOICE) { - highlightCell = useLettersForMcq; + highlightCell = true; int letter = 'A'; for (QbOption option : options) { for (AssessmentOptionAnswer optionAnswer : optionAnswers) { @@ -312,6 +309,10 @@ letter++; } + // do not highlight if we use full answers, not letters, + // or if no answer was provided + highlightCell &= useLettersForMcq && StringUtils.isNotBlank(sb.toString()); + } else if (type == QbQuestion.TYPE_ORDERING) { for (int i = 0; i < optionAnswers.size(); i++) { for (AssessmentOptionAnswer optionAnswer : optionAnswers) { @@ -347,12 +348,12 @@ } } - String ret = sb.toString().replaceAll("\\<.*?\\>|\\r|\\n", ""); + String ret = sb.toString().replaceAll("\\<.*?\\>|\\r|\\n", "").strip(); if (trimLastComma) { ret = ret.substring(0, ret.lastIndexOf(",")); } - row.addCell(ret, highlightCell ? IndexedColors.GREEN : IndexedColors.AUTOMATIC); + return new AssessmentExcelCell(StringUtils.isBlank(ret) ? null : ret, highlightCell); } } \ No newline at end of file