Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/GroupSummary.java =================================================================== diff -u -re8a7110708b15579af2c6b31ac52a6da427fef6d -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/GroupSummary.java (.../GroupSummary.java) (revision e8a7110708b15579af2c6b31ac52a6da427fef6d) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/GroupSummary.java (.../GroupSummary.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -35,6 +35,9 @@ private int mark; private int totalAttempts; private String totalPercentage; + + //used for itemSummary page + private int numberColumns; private Collection users; private Collection itemDtos; @@ -97,7 +100,15 @@ public void setTotalPercentage(String totalPercentage) { this.totalPercentage = totalPercentage; } + + public int getNumberColumns() { + return numberColumns; + } + public void setNumberColumns(int numberColumns) { + this.numberColumns = numberColumns; + } + public Collection getUsers() { return users; } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/ScratchieItemDTO.java =================================================================== diff -u -re8a7110708b15579af2c6b31ac52a6da427fef6d -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/ScratchieItemDTO.java (.../ScratchieItemDTO.java) (revision e8a7110708b15579af2c6b31ac52a6da427fef6d) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/ScratchieItemDTO.java (.../ScratchieItemDTO.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -12,6 +12,7 @@ private Long uid; private String title; + private Integer type; private List optionDtos; private boolean unraveledOnFirstAttempt; private int userMark; @@ -44,7 +45,15 @@ public void setTitle(String title) { this.title = title; } + + public Integer getType() { + return type; + } + public void setType(Integer type) { + this.type = type; + } + public List getOptionDtos() { return optionDtos; } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java =================================================================== diff -u -ra9f95a26e562a58b55c99f2c18e253c151ef457a -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision a9f95a26e562a58b55c99f2c18e253c151ef457a) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -224,6 +224,14 @@ * @return */ int countSessionsByContentId(Long toolContentId); + + /** + * Return all sessions. + * + * @param toolContentId + * @return + */ + List getSessionsByContentId(Long toolContentId); /** * Save or update scratchie session. @@ -302,7 +310,7 @@ */ List getMonitoringSummary(Long contentId, boolean isIncludeOnlyLeaders); - List getQuestionSummary(Long contentId, Long itemUid); + List getGroupSummariesByItem(Long contentId, Long itemUid); /** * In order to group BurningQuestions by items, organise them as a list of BurningQuestionItemDTOs. @@ -328,6 +336,11 @@ * @return */ List exportExcel(Long contentId); + + /** + * Used by TblMonitoringController.tra() to get numberOfFirstChoiceEvents. + */ + List getSummaryByTeam(Scratchie scratchie, Collection sortedItems); /** * Create refection entry into notebook tool. Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -r98fb8bd4f3c36bbdcfe9b9445757f685d972cc02 -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision 98fb8bd4f3c36bbdcfe9b9445757f685d972cc02) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -419,6 +419,11 @@ public int countSessionsByContentId(Long toolContentId) { return scratchieSessionDao.getByContentId(toolContentId).size(); } + + @Override + public List getSessionsByContentId(Long toolContentId) { + return scratchieSessionDao.getByContentId(toolContentId); + } @Override public void saveOrUpdateScratchieSession(ScratchieSession resSession) { @@ -828,6 +833,16 @@ if (item.getQbQuestion().getType() != QbQuestion.TYPE_VERY_SHORT_ANSWERS) { continue; } + //clear optionDtos in case fillItemsWithVsaAnswers is used in a loop +// item.getOptionDtos().clear(); + List optionDtosFromScratchieUsers = new LinkedList<>(); + for (OptionDTO optionDto : item.getOptionDtos()) { + if (optionDto.getDisplayOrder() == -200) { + optionDtosFromScratchieUsers.add(optionDto); + } + } + item.getOptionDtos().clear(); + item.getOptionDtos().addAll(optionDtosFromScratchieUsers); //populate Scratchie items with VSA answers, entered by learners in Assessment tool if (scratchie.isAnswersFetchingEnabled()) { @@ -839,6 +854,7 @@ optionDto.setCorrect(assessmentAnswer.isCorrect()); optionDto.setUserId(assessmentAnswer.getUserId()); optionDto.setQbQuestionUid(assessmentAnswer.getQbQuestionUid()); +optionDto.setDisplayOrder(-100); if (!scratchie.isConfidenceLevelsEnabled()) { //don't show confidence levels for (ConfidenceLevelDTO confidenceLevel : assessmentAnswer.getConfidenceLevels()) { @@ -863,6 +879,7 @@ if (itemQbQuestionUid.equals(optionDtoIter.getQbQuestionUid()) && isAnswersEqual(item, optionDtoIter.getAnswer(), userLog.getAnswer())) { optionDto = optionDtoIter; + //skip showing ConfidenceLevel, as we already show it due to this user's answer in Assessment skipAddingUserAnswerToConfidenceLevel = optionDtoIter.getUserId() .equals(leader.getUserId()); break; @@ -877,8 +894,10 @@ optionDto.setQbQuestionUid(itemQbQuestionUid); String answer = userLog.getAnswer(); optionDto.setAnswer(answer); + optionDto.setDisplayOrder(-200); boolean isCorrect = ScratchieServiceImpl.isItemUnraveledByAnswers(item, List.of(answer)); optionDto.setCorrect(isCorrect); + optionDto.setUserId(leader.getUserId()); item.getOptionDtos().add(optionDto); } @@ -944,7 +963,7 @@ public static boolean isItemUnraveledByAnswers(ScratchieItem item, List userAnswers) { QbQuestion qbQuestion = item.getQbQuestion(); - QbOption correctAnswersGroup = qbQuestion.getQbOptions().get(0).getMaxMark() == 1 + QbOption correctAnswersGroup = qbQuestion.getQbOptions().get(0).isCorrect() ? qbQuestion.getQbOptions().get(0) : qbQuestion.getQbOptions().get(1); String[] correctAnswers = correctAnswersGroup.getName().strip().split("\\r\\n"); @@ -1028,11 +1047,11 @@ } @Override - public List getQuestionSummary(Long contentId, Long itemUid) { + public List getGroupSummariesByItem(Long contentId, Long itemUid) { List groupSummaryList = new ArrayList<>(); - Scratchie scratchie = getScratchieByContentId(contentId); ScratchieItem item = scratchieItemDao.getByUid(itemUid); boolean isMcqItem = item.getQbQuestion().getType() == QbQuestion.TYPE_MULTIPLE_CHOICE; + List options = item.getQbQuestion().getQbOptions(); List sessionList = scratchieSessionDao.getByContentId(contentId); for (ScratchieSession session : sessionList) { @@ -1041,27 +1060,17 @@ GroupSummary groupSummary = new GroupSummary(session); List sessionAttempts = scratchieAnswerVisitDao.getLogsBySessionAndItem(sessionId, itemUid); + int numberColumns = options.size() > sessionAttempts.size() || isMcqItem ? options.size() : sessionAttempts.size(); + groupSummary.setNumberColumns(numberColumns); Map optionMap = new HashMap<>(); - if (isMcqItem) { - List options = item.getQbQuestion().getQbOptions(); - for (QbOption dbOption : options) { - // clone it so it doesn't interfere with values from other sessions - OptionDTO optionDto = new OptionDTO(dbOption); - int[] attempts = new int[options.size()]; - optionDto.setAttempts(attempts); - optionMap.put(dbOption.getUid(), optionDto); - } - - } else { - item.getOptionDtos().clear(); - fillItemsWithVsaAnswers(List.of(item), sessionId, scratchie, sessionAttempts); - List optionDtos = item.getOptionDtos(); - for (OptionDTO optionDto : optionDtos) { - int[] attempts = new int[optionDtos.size()]; - optionDto.setAttempts(attempts); - optionMap.put(Long.valueOf(optionDto.getAnswerHash()), optionDto); - } + Long i = 0l; + for (QbOption dbOption : options) { + // clone it so it doesn't interfere with values from other sessions + OptionDTO optionDto = new OptionDTO(dbOption); + int[] attempts = new int[numberColumns]; + optionDto.setAttempts(attempts); + optionMap.put(dbOption.getUid(), optionDto); } // calculate attempts table @@ -1070,18 +1079,26 @@ int attemptNumber = 0; for (ScratchieAnswerVisitLog attempt : sessionAttempts) { - Long optionUidOrAnswer = isMcqItem ? attempt.getQbOption().getUid() - : attempt.getAnswer().hashCode(); - OptionDTO optionDto = optionMap.get(optionUidOrAnswer); - int[] attempts = optionDto == null ? new int[optionMap.size()] : optionDto.getAttempts(); + Long optionUid; + if (isMcqItem) { + optionUid = attempt.getQbOption().getUid(); + + } else { + String answer = attempt.getAnswer(); + boolean isCorrect = ScratchieServiceImpl.isItemUnraveledByAnswers(item, List.of(answer)); + boolean isFirstAnswersGroupCorrect = options.get(0).isCorrect(); + + optionUid = isCorrect && isFirstAnswersGroupCorrect + || !isCorrect && !isFirstAnswersGroupCorrect ? options.get(0).getUid() : options.get(1).getUid(); + } + OptionDTO optionDto = optionMap.get(optionUid); + int[] attempts = optionDto.getAttempts(); // +1 for corresponding choice attempts[attemptNumber++]++; } } - Collection sortedOptions = new LinkedList<>(); - sortedOptions.addAll(optionMap.values()); - groupSummary.setOptionDtos(sortedOptions); + groupSummary.setOptionDtos(optionMap.values()); groupSummaryList.add(groupSummary); } @@ -1091,11 +1108,10 @@ groupSummaryTotal.setSessionId(0L); groupSummaryTotal.setSessionName("Summary"); groupSummaryTotal.setMark(0); + groupSummaryTotal.setNumberColumns(options.size()); Map optionMapTotal = new HashMap<>(); - List options = item.getQbQuestion().getQbOptions(); for (QbOption dbOption : options) { - // clone it so it doesn't interfere with values from other sessions OptionDTO optionDto = new OptionDTO(dbOption); int[] attempts = new int[options.size()]; @@ -1116,9 +1132,7 @@ } } - Collection sortedOptions = new TreeSet<>(); - sortedOptions.addAll(optionMapTotal.values()); - groupSummaryTotal.setOptionDtos(sortedOptions); + groupSummaryTotal.setOptionDtos(optionMapTotal.values()); groupSummaryList.add(0, groupSummaryTotal); } @@ -1265,7 +1279,39 @@ public ScratchieUser getUser(Long uid) { return (ScratchieUser) scratchieUserDao.getObject(ScratchieUser.class, uid); } + + /** + * Return list of correct AnswerLetters, one per each item + */ + public static List getCorrectAnswerLetters(Collection items) { + List correctAnswerLetters = new ArrayList<>(); + for (ScratchieItem item : items) { + boolean isMcqItem = item.getQbQuestion().getType() == QbQuestion.TYPE_MULTIPLE_CHOICE; + // find out the correct answer's sequential letter - A,B,C... + String correctAnswerLetter = ""; + if (isMcqItem) { + int answerCount = 1; + for (OptionDTO answer : item.getOptionDtos()) { + if (answer.isCorrect()) { + correctAnswerLetter = String.valueOf((char) ((answerCount + 'A') - 1)); + break; + } + answerCount++; + } + + } else { + List options = item.getQbQuestion().getQbOptions(); + if (!options.isEmpty()) { + correctAnswerLetter = options.get(0).isCorrect() ? "A" : "B"; + } + } + correctAnswerLetters.add(correctAnswerLetter); + } + + return correctAnswerLetters; + } + @Override public List exportExcel(Long contentId) { Scratchie scratchie = scratchieDao.getByContentId(contentId); @@ -1355,18 +1401,7 @@ row = reportByTeamSheet.initRow(); row.addCell(getMessage("label.correct.answer")); - for (ScratchieItem item : items) { - - // find out the correct answer's sequential letter - A,B,C... - String correctAnswerLetter = ""; - int answerCount = 1; - for (OptionDTO answer : item.getOptionDtos()) { - if (answer.isCorrect()) { - correctAnswerLetter = String.valueOf((char) ((answerCount + 'A') - 1)); - break; - } - answerCount++; - } + for (String correctAnswerLetter : ScratchieServiceImpl.getCorrectAnswerLetters(items)) { row.addCell(correctAnswerLetter); } @@ -1524,7 +1559,7 @@ SimpleDateFormat fullDateFormat = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); for (ScratchieItem item : items) { - List itemSummary = getQuestionSummary(contentId, item.getUid()); + List itemSummary = getGroupSummariesByItem(contentId, item.getUid()); boolean isMcqItem = item.getQbQuestion().getType() == QbQuestion.TYPE_MULTIPLE_CHOICE; row = researchAndAnalysisSheet.initRow(); @@ -1636,13 +1671,14 @@ false); int i = 1; + boolean isMcqItem = item.getQbQuestion().getType() == QbQuestion.TYPE_MULTIPLE_CHOICE; List logs = scratchieAnswerVisitDao.getLogsBySessionAndItem(sessionId, item.getUid()); for (ScratchieAnswerVisitLog log : logs) { row = researchAndAnalysisSheet.initRow(); row.addCell(Integer.valueOf(i++)); - String answerDescr = removeHtmlMarkup(log.getQbOption().getName()); - row.addCell(answerDescr); + String answerDescr = isMcqItem ? log.getQbOption().getName() : log.getAnswer(); + row.addCell(removeHtmlMarkup(answerDescr)); row.addCell(fullDateFormat.format(log.getAccessDate())); } @@ -1742,8 +1778,9 @@ logs = new ArrayList<>(); } + boolean isMcqItem = itemDto.getType() == QbQuestion.TYPE_MULTIPLE_CHOICE; for (ScratchieAnswerVisitLog log : logs) { - String answer = removeHtmlMarkup(log.getQbOption().getName()); + String answer = removeHtmlMarkup(isMcqItem ? log.getQbOption().getName() : log.getAnswer()); row.addCell(answer); } for (int i = logs.size(); i < itemDto.getOptionDtos().size(); i++) { @@ -1858,7 +1895,8 @@ /** * Serves merely for excel export purposes. Produces data for "Summary By Team" section. */ - private List getSummaryByTeam(Scratchie scratchie, Collection sortedItems) { + @Override + public List getSummaryByTeam(Scratchie scratchie, Collection sortedItems) { List groupSummaries = new ArrayList<>(); String[] presetMarks = getPresetMarks(scratchie); @@ -1870,18 +1908,16 @@ ArrayList itemDtos = new ArrayList<>(); ScratchieUser groupLeader = session.getGroupLeader(); - List logs = scratchieAnswerVisitDao.getLogsBySession(sessionId); - //populate Scratchie items with VSA answers (both from Assessment tool and entered by current learner) - fillItemsWithVsaAnswers(sortedItems, sessionId, scratchie, logs); for (ScratchieItem item : sortedItems) { ScratchieItemDTO itemDto = new ScratchieItemDTO(); int numberOfAttempts = 0; int mark = -1; boolean isUnraveledOnFirstAttempt = false; String optionsSequence = ""; - boolean isMcqItem = item.getQbQuestion().getType() == QbQuestion.TYPE_MULTIPLE_CHOICE; + QbQuestion qbQuestion = item.getQbQuestion(); + boolean isMcqItem = qbQuestion.getType() == QbQuestion.TYPE_MULTIPLE_CHOICE; // if there is no group leader don't calculate numbers - there aren't any if (groupLeader != null) { @@ -1903,28 +1939,37 @@ && ScratchieServiceImpl.isItemUnraveled(item, logs); // find out options' sequential letters - A,B,C... - for (ScratchieAnswerVisitLog itemAttempt : visitLogs) { + for (ScratchieAnswerVisitLog visitLog : visitLogs) { String sequencialLetter = ""; - int optionCount = 1; - for (OptionDTO optionDto : item.getOptionDtos()) { - boolean isOptionMet = isMcqItem - && optionDto.getQbOptionUid().equals(itemAttempt.getQbOption().getUid()) - || !isMcqItem - && isAnswersEqual(item, optionDto.getAnswer(), itemAttempt.getAnswer()); - if (isOptionMet) { - sequencialLetter = String.valueOf((char) ((optionCount + 'A') - 1)); - break; + if (isMcqItem) { + int optionCount = 1; + for (OptionDTO optionDto : item.getOptionDtos()) { + boolean isOptionMet = optionDto.getQbOptionUid() + .equals(visitLog.getQbOption().getUid()); + if (isOptionMet) { + sequencialLetter = String.valueOf((char) ((optionCount + 'A') - 1)); + break; + } + optionCount++; } - optionCount++; + + } else { + String answer = visitLog.getAnswer(); + boolean isCorrect = ScratchieServiceImpl.isItemUnraveledByAnswers(item, List.of(answer)); + boolean isFirstAnswersGroupCorrect = qbQuestion.getQbOptions().get(0).isCorrect(); + + sequencialLetter = isCorrect && isFirstAnswersGroupCorrect + || !isCorrect && !isFirstAnswersGroupCorrect ? "A" : "B"; } optionsSequence += optionsSequence.isEmpty() ? sequencialLetter : ", " + sequencialLetter; } } itemDto.setUid(item.getUid()); - itemDto.setTitle(item.getQbQuestion().getName()); + itemDto.setTitle(qbQuestion.getName()); + itemDto.setType(qbQuestion.getType()); itemDto.setOptionDtos(item.getOptionDtos()); itemDto.setUserAttempts(numberOfAttempts); itemDto.setUserMark(mark); Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/MonitoringController.java =================================================================== diff -u -rb4d4f30a226e762635770f831a7582be62d812cb -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/MonitoringController.java (.../MonitoringController.java) (revision b4d4f30a226e762635770f831a7582be62d812cb) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/MonitoringController.java (.../MonitoringController.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -142,10 +142,7 @@ @RequestMapping("/itemSummary") private String itemSummary(HttpServletRequest request) { - String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession() - .getAttribute(sessionMapID); - request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + SessionMap sessionMap = getSessionMap(request); Long itemUid = WebUtil.readLongParam(request, ScratchieConstants.ATTR_ITEM_UID); if (itemUid.equals(-1L)) { @@ -155,12 +152,12 @@ request.setAttribute(ScratchieConstants.ATTR_ITEM, item); Long contentId = (Long) sessionMap.get(ScratchieConstants.ATTR_TOOL_CONTENT_ID); - List summaryList = scratchieService.getQuestionSummary(contentId, itemUid); + List summaryList = scratchieService.getGroupSummariesByItem(contentId, itemUid); // escape JS sensitive characters in option descriptions for (GroupSummary summary : summaryList) { for (OptionDTO optionDto : summary.getOptionDtos()) { - String escapedAnswer = StringEscapeUtils.escapeJavaScript(optionDto.getAnswer()); + String escapedAnswer = StringEscapeUtils.escapeJavaScript(optionDto.getAnswer()).replace("\\r\\n", "
"); optionDto.setAnswer(escapedAnswer); } } @@ -186,17 +183,9 @@ /** * Set Submission Deadline - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException */ @RequestMapping("/setSubmissionDeadline") private String setSubmissionDeadline(HttpServletRequest request, HttpServletResponse response) throws IOException { - Long contentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); Scratchie scratchie = scratchieService.getScratchieByContentId(contentID); @@ -221,16 +210,11 @@ /** * Exports tool results into excel. - * - * @throws IOException */ @RequestMapping("/exportExcel") @ResponseStatus(HttpStatus.OK) private void exportExcel(HttpServletRequest request, HttpServletResponse response) throws IOException { - - String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession() - .getAttribute(sessionMapID); + SessionMap sessionMap = getSessionMap(request); Scratchie scratchie = (Scratchie) sessionMap.get(ScratchieConstants.ATTR_SCRATCHIE); List sheets = scratchieService.exportExcel(scratchie.getContentId()); @@ -258,12 +242,8 @@ @RequestMapping("/getMarkChartData") private String getMarkChartData(HttpServletRequest request, HttpServletResponse res) throws IOException, ServletException { + SessionMap sessionMap = getSessionMap(request); - String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession() - .getAttribute(sessionMapID); - request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - Scratchie scratchie = (Scratchie) sessionMap.get(ScratchieConstants.ATTR_SCRATCHIE); List results = null; @@ -286,12 +266,8 @@ @RequestMapping("/statistic") private String statistic(HttpServletRequest request) { + SessionMap sessionMap = getSessionMap(request); - String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession() - .getAttribute(sessionMapID); - request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - Scratchie scratchie = (Scratchie) sessionMap.get(ScratchieConstants.ATTR_SCRATCHIE); if (scratchie != null) { LeaderResultsDTO leaderDto = scratchieService.getLeaderResultsDTOForLeaders(scratchie.getContentId()); @@ -311,4 +287,11 @@ } return "pages/monitoring/parts/statisticpart"; } + + @SuppressWarnings("unchecked") + private SessionMap getSessionMap(HttpServletRequest request) { + String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); + request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return (SessionMap) request.getSession().getAttribute(sessionMapID); + } } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/TblMonitorController.java =================================================================== diff -u -r6791a1a89c3b773b5dedccb451a7ab6039925d11 -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/TblMonitorController.java (.../TblMonitorController.java) (revision 6791a1a89c3b773b5dedccb451a7ab6039925d11) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/TblMonitorController.java (.../TblMonitorController.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -41,17 +41,22 @@ import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.log4j.Logger; +import org.apache.poi.ss.usermodel.IndexedColors; +import org.lamsfoundation.lams.qb.model.QbQuestion; import org.lamsfoundation.lams.tool.scratchie.ScratchieConstants; import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionDTO; import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionItemDTO; import org.lamsfoundation.lams.tool.scratchie.dto.GroupSummary; import org.lamsfoundation.lams.tool.scratchie.dto.OptionDTO; import org.lamsfoundation.lams.tool.scratchie.dto.ScratchieItemDTO; import org.lamsfoundation.lams.tool.scratchie.model.Scratchie; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieAnswerVisitLog; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieConfigItem; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieItem; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieSession; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieUser; import org.lamsfoundation.lams.tool.scratchie.service.IScratchieService; +import org.lamsfoundation.lams.tool.scratchie.service.ScratchieServiceImpl; import org.lamsfoundation.lams.tool.scratchie.util.ScratchieItemComparator; import org.lamsfoundation.lams.util.AlphanumComparator; import org.lamsfoundation.lams.util.FileUtil; @@ -94,21 +99,22 @@ request.setAttribute("items", items); if (attemptedLearnersNumber != 0) { - // find the first page in excel file - List sheets = scratchieService.exportExcel(toolContentId); - ExcelSheet firstPageData = sheets.get(0); - - int groupsSize = scratchieService.countSessionsByContentId(toolContentId); - ArrayList groupRows = new ArrayList<>(); - for (int groupCount = 0; groupCount < groupsSize; groupCount++) { - ExcelRow groupRow = firstPageData.getRow(5 + groupCount); - - String[] groupRow2 = new String[2]; - groupRow2[0] = (String) groupRow.getCell(1); - groupRow2[1] = String.valueOf((Double) groupRow.getCell(groupRow.getCells().size() - 1) * 100); - groupRows.add(groupRow2); + List groupSummaries = scratchieService.getSummaryByTeam(scratchie, items); + + //calculate what is the percentage of first choice events in each session + for (GroupSummary summary : groupSummaries) { + int numberOfFirstChoiceEvents = 0; + for (ScratchieItemDTO itemDto : summary.getItemDtos()) { + if (itemDto.isUnraveledOnFirstAttempt()) { + numberOfFirstChoiceEvents++; + } + } + + Double percentage = (items.size() == 0) ? 0 : (double) numberOfFirstChoiceEvents * 100 / items.size(); + summary.setTotalPercentage(percentage.toString()); } - request.setAttribute("groupRows", groupRows); + + request.setAttribute("groupSummaries", groupSummaries); } return "pages/tblmonitoring/tra"; @@ -126,34 +132,22 @@ items.addAll(scratchie.getScratchieItems()); request.setAttribute("items", items); - //find second page in excel file - List sheets = scratchieService.exportExcel(toolContentId); - ExcelSheet secondPageData = sheets.get(1); + //correct answers row + List correctAnswerLetters = ScratchieServiceImpl.getCorrectAnswerLetters(items); + request.setAttribute("correctAnswerLetters", correctAnswerLetters); - //correct answers - ExcelRow correctOptionsRow = secondPageData.getRow(4); - request.setAttribute("correctAnswers", correctOptionsRow); - - //prepare data for displaying user answers table - int groupsSize = scratchieService.countSessionsByContentId(toolContentId); - ArrayList sessionDtos = new ArrayList<>(); - for (int groupCount = 0; groupCount < groupsSize; groupCount++) { - ExcelRow groupRow = secondPageData.getRows().get(6 + groupCount); - - GroupSummary groupSummary = new GroupSummary(); - String sessionName = groupRow.getCell(0).toString(); - groupSummary.setSessionName(sessionName); - - Collection itemDtos = new ArrayList<>(); - for (int i = 1; i <= items.size(); i++) { - ScratchieItemDTO itemDto = new ScratchieItemDTO(); - String optionSequence = groupRow.getCell(i).toString(); + List groupSummaries = scratchieService.getSummaryByTeam(scratchie, items); + for (GroupSummary summary : groupSummaries) { + //prepare OptionDtos to display + int i = 0; + for (ScratchieItemDTO itemDto : summary.getItemDtos()) { + String optionSequence = itemDto.getOptionsSequence(); String[] optionLetters = optionSequence.split(", "); List optionDtos = new LinkedList<>(); for (int j = 0; j < optionLetters.length; j++) { String optionLetter = optionLetters[j]; - String correctOptionLetter = correctOptionsRow.getCell(i).toString(); + String correctOptionLetter = correctAnswerLetters.get(i); OptionDTO optionDto = new OptionDTO(); optionDto.setAnswer(optionLetter); @@ -162,25 +156,22 @@ } itemDto.setOptionDtos(optionDtos); - itemDtos.add(itemDto); + i++; } - groupSummary.setItemDtos(itemDtos); - - if (!itemDtos.isEmpty()) { - int total = (Integer) groupRow.getCell(itemDtos.size() + 1); - groupSummary.setMark(total); - - String totalPercentageStr = groupRow.getCell(itemDtos.size() + 2).toString(); - int totalPercentage = NumberUtils.isNumber(totalPercentageStr) - ? (int) (Double.parseDouble(totalPercentageStr) * 100) - : 0; - groupSummary.setTotalPercentage(totalPercentage + "%"); + + //calculate what is the percentage of first choice events in each session + int numberOfFirstChoiceEvents = 0; + for (ScratchieItemDTO itemDto : summary.getItemDtos()) { + if (itemDto.isUnraveledOnFirstAttempt()) { + numberOfFirstChoiceEvents++; + } } - - sessionDtos.add(groupSummary); + summary.setMark(numberOfFirstChoiceEvents); + Double percentage = (items.size() == 0) ? 0 : (double) numberOfFirstChoiceEvents * 100 / items.size(); + summary.setTotalPercentage(percentage + "%"); } - request.setAttribute("sessionDtos", sessionDtos); + request.setAttribute("sessionDtos", groupSummaries); request.setAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID, toolContentId); return "pages/tblmonitoring/traStudentChoices"; } @@ -195,7 +186,6 @@ @RequestMapping("/exportExcel") @ResponseStatus(HttpStatus.OK) public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws IOException { - Long toolContentId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); List sheets = scratchieService.exportExcel(toolContentId); @@ -219,7 +209,6 @@ @ResponseBody public String isBurningQuestionsEnabled(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - long toolContentId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); Scratchie scratchie = scratchieService.getScratchieByContentId(toolContentId); @@ -236,7 +225,6 @@ */ @RequestMapping("/burningQuestions") public String burningQuestions(HttpServletRequest request) throws IOException, ServletException { - long toolContentId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); Scratchie scratchie = scratchieService.getScratchieByContentId(toolContentId); @@ -282,7 +270,6 @@ */ @RequestMapping("/getModalDialogForTeamsTab") public String getModalDialogForTeamsTab(HttpServletRequest request) throws IOException, ServletException { - long toolContentId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); Long userId = WebUtil.readLongParam(request, AttributeNames.PARAM_USER_ID); Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/servlet/PopulateMarksServlet.java =================================================================== diff -u -rf2ad75cef0c507a64877942631fee13efbc6ed50 -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/servlet/PopulateMarksServlet.java (.../PopulateMarksServlet.java) (revision f2ad75cef0c507a64877942631fee13efbc6ed50) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/servlet/PopulateMarksServlet.java (.../PopulateMarksServlet.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -35,7 +35,6 @@ import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieSessionDAO; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieSession; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieUser; import org.lamsfoundation.lams.tool.scratchie.service.IScratchieService; @@ -49,8 +48,6 @@ @Autowired private static IScratchieService scratchieService; - @Autowired - private static ScratchieSessionDAO scratchieSessionDAO; /* * Request Spring to lookup the applicationContext tied to the current ServletContext and inject service beans @@ -91,7 +88,7 @@ //otherwise - only the ones that belong to specified toolContentId } else { - List dbSessions = scratchieSessionDAO.getByContentId(toolContentId); + List dbSessions = scratchieService.getSessionsByContentId(toolContentId); sessions.addAll(dbSessions); } Index: lams_tool_scratchie/web/pages/monitoring/parts/itemSummary.jsp =================================================================== diff -u -r3126fb6636e4164bdc6e539eab16ed2a7618fe7e -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/web/pages/monitoring/parts/itemSummary.jsp (.../itemSummary.jsp) (revision 3126fb6636e4164bdc6e539eab16ed2a7618fe7e) +++ lams_tool_scratchie/web/pages/monitoring/parts/itemSummary.jsp (.../itemSummary.jsp) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -49,14 +49,14 @@ iconSet: 'fontAwesome', colNames:[ "" - - ," ${i.index + 1}" + + ," ${i+1}" ], colModel:[ {name:'option',index:'option', width:180} - - ,{name:'choice${i.index}', index:'${i.index}choice', align:"center", sorttype:"int"} + + ,{name:'choice${i}', index:'${i}choice', align:"center", sorttype:"int"} ], multiselect: false @@ -65,7 +65,7 @@ jQuery("#session${summary.sessionId}").addRowData(${i.index + 1}, { option:" ()" - + ,choice${j}:"${optionDto.attempts[j]}" }); Index: lams_tool_scratchie/web/pages/tblmonitoring/tra.jsp =================================================================== diff -u -r3126fb6636e4164bdc6e539eab16ed2a7618fe7e -re4ab7517268533520c11b8cb076abd74d7721d89 --- lams_tool_scratchie/web/pages/tblmonitoring/tra.jsp (.../tra.jsp) (revision 3126fb6636e4164bdc6e539eab16ed2a7618fe7e) +++ lams_tool_scratchie/web/pages/tblmonitoring/tra.jsp (.../tra.jsp) (revision e4ab7517268533520c11b8cb076abd74d7721d89) @@ -1,4 +1,5 @@ <%@ include file="/common/taglibs.jsp"%> +<% pageContext.setAttribute("newLineChar", "\r\n"); %>