Index: lams_tool_lamc/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/conf/language/lams/ApplicationResources_en_AU.properties,v diff -u -r1.38 -r1.39 --- lams_tool_lamc/conf/language/lams/ApplicationResources_en_AU.properties 12 Aug 2013 16:29:03 -0000 1.38 +++ lams_tool_lamc/conf/language/lams/ApplicationResources_en_AU.properties 26 Aug 2013 11:03:49 -0000 1.39 @@ -274,4 +274,14 @@ label.submit =Finished label.learning.draft.autosaved =Draft autosaved +label.report.by.question =Report by question IRA +label.report.by.student =Report by student IRA +label.not.available =N/A +label.legend =Legend +label.denotes.correct.answer =*- Denontes the correct answer +label.correct.answer =Correct Answer +label.ave =Ave +label.class.mean =Class Mean +label.median =Median + #======= End labels: Exported 265 labels for en AU ===== Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredAnswersDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredAnswersDTO.java,v diff -u -r1.11 -r1.12 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredAnswersDTO.java 8 May 2013 13:18:25 -0000 1.11 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredAnswersDTO.java 26 Aug 2013 11:03:49 -0000 1.12 @@ -47,7 +47,7 @@ private List candidateAnswersCorrect; - private Map questionAttempts; + private Map> questionAttempts; /** * @return Returns the question. @@ -82,15 +82,15 @@ /** * @return Returns the questionAttempts. */ - public Map getQuestionAttempts() { + public Map> getQuestionAttempts() { return questionAttempts; } /** * @param questionAttempts * The questionAttempts to set. */ - public void setQuestionAttempts(Map questionAttempts) { + public void setQuestionAttempts(Map> questionAttempts) { this.questionAttempts = questionAttempts; } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McSessionMarkDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McSessionMarkDTO.java,v diff -u -r1.3 -r1.4 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McSessionMarkDTO.java 8 May 2013 13:18:25 -0000 1.3 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McSessionMarkDTO.java 26 Aug 2013 11:03:49 -0000 1.4 @@ -36,7 +36,7 @@ public class McSessionMarkDTO implements Comparable { private String sessionId; private String sessionName; - private Map userMarks; + private Map userMarks; public String toString() { return new ToStringBuilder(this).append("Listing SessionMarkDTO: ").append("sessionId: ", sessionId) @@ -85,15 +85,15 @@ /** * @return Returns the userMarks. */ - public Map getUserMarks() { + public Map getUserMarks() { return userMarks; } /** * @param userMarks * The userMarks to set. */ - public void setUserMarks(Map userMarks) { + public void setUserMarks(Map userMarks) { this.userMarks = userMarks; } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java,v diff -u -r1.7 -r1.8 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java 8 May 2013 13:18:25 -0000 1.7 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java 26 Aug 2013 11:03:49 -0000 1.8 @@ -41,6 +41,7 @@ private String fullName; private Date attemptTime; private Integer[] marks; + private String[] answeredOptions; private Long totalMark; public String toString() { @@ -63,8 +64,23 @@ public void setMarks(Integer[] marks) { this.marks = marks; } + + /** + * @return Returns the answeredOptions - sequencial letter of the option that was chosen. + */ + public String[] getAnsweredOptions() { + return answeredOptions; + } /** + * @param answeredOptions + * The answeredOptions to set. + */ + public void setAnsweredOptions(String[] answeredOptions) { + this.answeredOptions = answeredOptions; + } + + /** * @return Returns the queUsrId. */ public String getQueUsrId() { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java,v diff -u -r1.22 -r1.23 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java 12 Aug 2013 16:29:03 -0000 1.22 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java 26 Aug 2013 11:03:49 -0000 1.23 @@ -24,6 +24,7 @@ import java.util.List; +import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; /** @@ -69,9 +70,9 @@ */ public McOptsContent getOptionContentByOptionText(final String option, final Long mcQueContentUid); - public List findMcOptionCorrectByQueId(Long mcQueContentId); + public List findMcOptionCorrectByQueId(Long mcQueContentId); - public List populateCandidateAnswersDTO(Long mcQueContentId); + public List populateCandidateAnswersDTO(Long mcQueContentId); /** *

Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java,v diff -u -r1.21 -r1.22 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java 12 Aug 2013 16:29:02 -0000 1.21 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java 26 Aug 2013 11:03:49 -0000 1.22 @@ -45,7 +45,7 @@ * @param uid * @return */ - public void saveMcUsrAttempt(McUsrAttempt mcUsrAttempt); + void saveMcUsrAttempt(McUsrAttempt mcUsrAttempt); /** * * @@ -56,7 +56,7 @@ * @param mcUsrAttempt * @return */ - public void updateMcUsrAttempt(McUsrAttempt mcUsrAttempt); + void updateMcUsrAttempt(McUsrAttempt mcUsrAttempt); /** * * @@ -67,19 +67,27 @@ * @param mcUsrAttempt * @return */ - public void removeAllUserAttempts(Long queUserUid); + void removeAllUserAttempts(Long queUserUid); /** * Get the most recent attempts (for all questions) for one user in one tool session * * @param queUserUid * @return */ - public List getUserAttempts(Long queUserUid); + List getUserAttempts(Long queUserUid); /** * Get the highest attempt order for a user for a particular question */ - public McUsrAttempt getUserAttemptByQuestion(Long queUsrUid, Long mcQueContentId); + McUsrAttempt getUserAttemptByQuestion(Long queUsrUid, Long mcQueContentId); + + /** + * Count how many attempts done to this option + * + * @param optionUid + * @return + */ + int getAttemptsCountPerOption(Long optionUid); } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java,v diff -u -r1.26 -r1.27 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java 12 Aug 2013 16:29:03 -0000 1.26 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java 26 Aug 2013 11:03:49 -0000 1.27 @@ -60,41 +60,36 @@ return null; } - public List populateCandidateAnswersDTO(Long mcQueContentId) { - List listCandidateAnswersData = new LinkedList(); + public List populateCandidateAnswersDTO(Long mcQueContentId) { + List listCandidateAnswersData = new LinkedList(); - HibernateTemplate templ = this.getHibernateTemplate(); if (mcQueContentId != null) { - List list = getSession().createQuery(FIND_MC_OPTIONS_CONTENT) + List options = getSession().createQuery(FIND_MC_OPTIONS_CONTENT) .setLong("mcQueContentUid", mcQueContentId.longValue()).list(); - if (list != null && list.size() > 0) { - Iterator listIterator = list.iterator(); - while (listIterator.hasNext()) { - McOptsContent mcOptsContent = (McOptsContent) listIterator.next(); + if (options != null && options.size() > 0) { + for (McOptsContent option : options) { McCandidateAnswersDTO mcCandidateAnswersDTO = new McCandidateAnswersDTO(); - mcCandidateAnswersDTO.setCandidateAnswer(mcOptsContent.getMcQueOptionText()); - mcCandidateAnswersDTO.setCorrect(new Boolean(mcOptsContent.isCorrectOption()).toString()); + mcCandidateAnswersDTO.setCandidateAnswer(option.getMcQueOptionText()); + mcCandidateAnswersDTO.setCorrect(new Boolean(option.isCorrectOption()).toString()); listCandidateAnswersData.add(mcCandidateAnswersDTO); } } } return listCandidateAnswersData; } - public List findMcOptionCorrectByQueId(Long mcQueContentId) { + public List findMcOptionCorrectByQueId(Long mcQueContentId) { - List listOptionCorrect = new LinkedList(); + List listOptionCorrect = new LinkedList(); if (mcQueContentId != null) { - List list = getSession().createQuery(FIND_MC_OPTIONS_CONTENT) + List options = getSession().createQuery(FIND_MC_OPTIONS_CONTENT) .setLong("mcQueContentUid", mcQueContentId.longValue()).list(); - if (list != null && list.size() > 0) { - Iterator listIterator = list.iterator(); - while (listIterator.hasNext()) { - McOptsContent mcOptsContent = (McOptsContent) listIterator.next(); - listOptionCorrect.add(new Boolean(mcOptsContent.isCorrectOption()).toString()); + if (options != null && options.size() > 0) { + for (McOptsContent option : options) { + listOptionCorrect.add(new Boolean(option.isCorrectOption()).toString()); } } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java,v diff -u -r1.25 -r1.26 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java 12 Aug 2013 16:29:03 -0000 1.25 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java 26 Aug 2013 11:03:49 -0000 1.26 @@ -50,11 +50,17 @@ private static final String LOAD_ALL_QUESTION_ATTEMPTS = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.mcQueUsr.uid=:queUsrUid" + " order by mcUsrAttempt.mcQueContentId, mcUsrAttempt.mcOptionsContent.uid"; + + private static final String FIND_ATTEMPTS_COUNT_BY_OPTION = "select count(*) from " + + McUsrAttempt.class.getName() + + " as attempt where attempt.mcOptionsContent.uid=? AND attempt.mcQueUsr.responseFinalised = true"; - public void saveMcUsrAttempt(McUsrAttempt mcUsrAttempt) { + @Override + public void saveMcUsrAttempt(McUsrAttempt mcUsrAttempt) { this.getHibernateTemplate().save(mcUsrAttempt); } + @Override public List getUserAttempts(final Long queUserUid) { return (List) getSession().createQuery(LOAD_ALL_QUESTION_ATTEMPTS) .setLong("queUsrUid", queUserUid.longValue()).list(); @@ -73,11 +79,13 @@ return userAttempt; } + @Override public void updateMcUsrAttempt(McUsrAttempt mcUsrAttempt) { this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().update(mcUsrAttempt); } + @Override public void removeAllUserAttempts(Long queUserUid) { this.getSession().setFlushMode(FlushMode.AUTO); @@ -88,5 +96,13 @@ this.getHibernateTemplate().delete(userAttempt); } } + + @Override + public int getAttemptsCountPerOption(Long optionUid) { + List list = getHibernateTemplate().find(FIND_ATTEMPTS_COUNT_BY_OPTION, new Object[] { optionUid }); + if (list == null || list.size() == 0) + return 0; + return ((Number) list.get(0)).intValue(); + } } \ No newline at end of file Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java,v diff -u -r1.69 -r1.70 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java 12 Aug 2013 16:29:03 -0000 1.69 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java 26 Aug 2013 11:03:49 -0000 1.70 @@ -22,9 +22,12 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.service; +import java.io.IOException; import java.io.InputStream; import java.util.List; +import javax.servlet.http.HttpServletRequest; + import org.lamsfoundation.lams.contentrepository.ITicket; import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; @@ -36,6 +39,7 @@ import org.lamsfoundation.lams.tool.exception.SessionDataExistsException; import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.mc.McApplicationException; +import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; import org.lamsfoundation.lams.tool.mc.McLearnerAnswersDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; @@ -121,7 +125,7 @@ void updateMcQueUsr(McQueUsr mcQueUsr) throws McApplicationException; - List populateCandidateAnswersDTO(Long mcQueContentId) throws McApplicationException; + List populateCandidateAnswersDTO(Long mcQueContentId) throws McApplicationException; McSession getMcSessionByUID(Long uid) throws McApplicationException; @@ -145,27 +149,15 @@ void deleteMcOptionsContentByUID(Long uid) throws McApplicationException; - User getCurrentUserData(String username) throws McApplicationException; - - Lesson getCurrentLesson(long lessonId) throws McApplicationException; - void saveMcContent(McContent mc) throws McApplicationException; boolean studentActivityOccurredGlobal(McContent mcContent) throws McApplicationException; McUsrAttempt getUserAttemptByQuestion(Long queUsrUid, Long mcQueContentId) throws McApplicationException; - int countIncompleteSession(McContent mc) throws McApplicationException; - - boolean studentActivityOccurred(McContent mc) throws McApplicationException; - void copyToolContent(Long fromContentId, Long toContentId) throws ToolException; - void setAsForceCompleteSession(Long toolSessionId) throws McApplicationException; - - void setAsForceComplete(Long userId) throws McApplicationException; - void setAsDefineLater(Long toolContentId, boolean value) throws DataMissingException, ToolException; void setAsRunOffline(Long toolContentId, boolean value) throws DataMissingException, ToolException; @@ -246,5 +238,19 @@ * @return */ List buildLearnerAnswersDTOList(McContent mcContent, McQueUsr user); + + /** + * prepareSessionDataSpreadsheet + * + * @param request + * @param response + * @param mcContent + * @param mcService + * @param currentMonitoredToolSession + * + * @return data to write out + */ + byte[] prepareSessionDataSpreadsheet(HttpServletRequest request, McContent mcContent, + String currentMonitoredToolSession) throws IOException; } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java,v diff -u -r1.111 -r1.112 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java 12 Aug 2013 16:29:03 -0000 1.111 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java 26 Aug 2013 11:03:49 -0000 1.112 @@ -22,22 +22,36 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.service; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeSet; import java.util.Vector; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.IndexedColors; import org.lamsfoundation.lams.contentrepository.AccessDeniedException; import org.lamsfoundation.lams.contentrepository.FileException; import org.lamsfoundation.lams.contentrepository.ICredentials; @@ -56,7 +70,6 @@ import org.lamsfoundation.lams.learningdesign.service.ExportToolContentException; import org.lamsfoundation.lams.learningdesign.service.IExportToolContentService; import org.lamsfoundation.lams.learningdesign.service.ImportToolContentException; -import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.notebook.service.ICoreNotebookService; import org.lamsfoundation.lams.tool.IToolVO; @@ -71,7 +84,10 @@ import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.mc.McAppConstants; import org.lamsfoundation.lams.tool.mc.McApplicationException; +import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; import org.lamsfoundation.lams.tool.mc.McLearnerAnswersDTO; +import org.lamsfoundation.lams.tool.mc.McSessionMarkDTO; +import org.lamsfoundation.lams.tool.mc.McUserMarkDTO; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.dao.IMcContentDAO; import org.lamsfoundation.lams.tool.mc.dao.IMcOptionsContentDAO; @@ -87,8 +103,8 @@ import org.lamsfoundation.lams.tool.mc.pojos.McSession; import org.lamsfoundation.lams.tool.mc.pojos.McUploadedFile; import org.lamsfoundation.lams.tool.mc.pojos.McUsrAttempt; +import org.lamsfoundation.lams.tool.mc.web.MonitoringUtil; import org.lamsfoundation.lams.tool.service.ILamsToolService; -import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.MessageService; @@ -529,7 +545,7 @@ } } - public List populateCandidateAnswersDTO(Long mcQueContentId) throws McApplicationException { + public List populateCandidateAnswersDTO(Long mcQueContentId) throws McApplicationException { try { return mcOptionsContentDAO.populateCandidateAnswersDTO(mcQueContentId); } catch (DataAccessException e) { @@ -721,46 +737,7 @@ } } - public User getCurrentUserData(String username) throws McApplicationException { - try { - /** - * this will return null if the username not found - */ - User user = userManagementService.getUserByLogin(username); - if (user == null) { - McServicePOJO.logger.error("No user with the username: " + username + " exists."); - throw new McApplicationException("No user with that username exists."); - } - return user; - } catch (DataAccessException e) { - throw new McApplicationException("Unable to find current user information" + " Root Cause: [" - + e.getMessage() + "]", e); - } - } - /** - * - * Unused method - * - * @param lessonId - * @return - * @throws McApplicationException - */ - public Lesson getCurrentLesson(long lessonId) throws McApplicationException { - try { - /** - * this is a mock implementation to make the project compile and work. When the Lesson service is ready, we - * need to switch to real service implementation. - */ - return new Lesson(); - /** return lsDAO.find(lsessionId); */ - } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is loading" + " learning session:" - + e.getMessage(), e); - } - } - - /** * checks the parameter content in the user responses table * * @param mcContent @@ -781,31 +758,309 @@ } return false; } + + @Override + public byte[] prepareSessionDataSpreadsheet(HttpServletRequest request, McContent mcContent, + String currentMonitoredToolSession) throws IOException { + + Set questions = mcContent.getMcQueContents(); + int maxOptionsInQuestion = 0; + for (McQueContent question : questions) { + if (question.getMcOptionsContents().size() > maxOptionsInQuestion) { + maxOptionsInQuestion = question.getMcOptionsContents().size(); + } + } + + int totalNumberOfUsers = 0; + for (McSession session : (Set) mcContent.getMcSessions()) { + totalNumberOfUsers += session.getMcQueUsers().size(); + } + + List sessionMarkDTOs = MonitoringUtil.buildGroupsMarkData(mcContent, this); + + // create an empty excel file + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFCellStyle greenColor = wb.createCellStyle(); + greenColor.setFillForegroundColor(IndexedColors.GREEN.getIndex()); + greenColor.setFillPattern(CellStyle.SOLID_FOREGROUND); + + // ======================================================= Report by question IRA page + // ======================================= + + HSSFSheet sheet = wb.createSheet(messageService.getMessage("label.report.by.question")); - public int countIncompleteSession(McContent mc) throws McApplicationException { - // int countIncompleteSession=mcSessionDAO.countIncompleteSession(mc); - int countIncompleteSession = 2; - return countIncompleteSession; - } + HSSFRow row; + HSSFCell cell; + int rowCount = 0; + + row = sheet.createRow(rowCount++); + int count = 0; + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.question")); + for (int optionCount = 0; optionCount < maxOptionsInQuestion; optionCount++) { + cell = row.createCell(count++); + cell.setCellValue(String.valueOf((char)(optionCount + 'A'))); + } + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.not.available")); + + for (McQueContent question : questions) { - /** - * checks the parameter content in the tool sessions table - * - * find out if any student has ever used (logged in through the url and replied) to this content return true even if - * you have only one content passed as parameter referenced in the tool sessions table - * - * @param mc - * @return boolean - * @throws McApplicationException - */ - public boolean studentActivityOccurred(McContent mc) throws McApplicationException { - // int countStudentActivity=mcSessionDAO.studentActivityOccurred(mc); - int countStudentActivity = 2; + row = sheet.createRow(rowCount); + count = 0; - if (countStudentActivity > 0) { - return true; + cell = row.createCell(count++); + cell.setCellValue(rowCount); + rowCount++; + + int totalPercentage = 0; + for (McOptsContent option : (Set) question.getMcOptionsContents()) { + int optionAttemptCount = mcUsrAttemptDAO.getAttemptsCountPerOption(option.getUid()); + cell = row.createCell(count++); + int percentage = optionAttemptCount * 100 / totalNumberOfUsers; + cell.setCellValue(percentage + "%"); + totalPercentage += percentage; + if (option.isCorrectOption()) { + cell.setCellStyle(greenColor); + } + } + cell = row.createCell(maxOptionsInQuestion + 1); + cell.setCellValue(100 - totalPercentage + "%"); } - return false; + + rowCount++; + row = sheet.createRow(rowCount++); + cell = row.createCell(0); + cell.setCellValue(messageService.getMessage("label.legend")); + row = sheet.createRow(rowCount++); + cell = row.createCell(0); + cell.setCellValue(messageService.getMessage("label.denotes.correct.answer")); + cell.setCellStyle(greenColor); + cell = row.createCell(1); + cell.setCellStyle(greenColor); + cell = row.createCell(2); + cell.setCellStyle(greenColor); + + // ======================================================= Report by student IRA page + // ======================================= + + sheet = wb.createSheet(messageService.getMessage("label.report.by.student")); + rowCount = 0; + + row = sheet.createRow(rowCount++); + count = 2; + for (int questionCount = 0; questionCount < questions.size(); questionCount++) { + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.question") + questionCount); + } + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.total")); + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.total") + " %"); + + row = sheet.createRow(rowCount++); + count = 1; + ArrayList correctAnswers = new ArrayList(); + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.correct.answer")); + for (McQueContent question : questions) { + + // find out the correct answer's sequential letter - A,B,C... + String correctAnswerLetter = ""; + int answerCount = 1; + for (McOptsContent option : (Set) question.getMcOptionsContents()) { + if (option.isCorrectOption()) { + correctAnswerLetter = String.valueOf((char) (answerCount + 'A' - 1)); + break; + } + answerCount++; + } + cell = row.createCell(count++); + cell.setCellValue(correctAnswerLetter); + correctAnswers.add(correctAnswerLetter); + } + + row = sheet.createRow(rowCount++); + count = 0; + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("group.label")); + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.learner")); + + int groupCount = 0; + ArrayList totalPercentList = new ArrayList(); + int[] numberOfCorrectAnswersPerQuestion = new int[questions.size()]; + for (McSessionMarkDTO sessionMarkDTO : sessionMarkDTOs) { + Map usersMarksMap = sessionMarkDTO.getUserMarks(); + groupCount++; + + for (McUserMarkDTO userMark : usersMarksMap.values()) { + row = sheet.createRow(rowCount++); + count = 0; + cell = row.createCell(count++); + cell.setCellValue(groupCount); + + cell = row.createCell(count++); + cell.setCellValue(userMark.getFullName()); + + String[] answeredOptions = userMark.getAnsweredOptions(); + int numberOfCorrectlyAnsweredByUser = 0; + for (int i = 0; i < answeredOptions.length; i++) { + String answeredOption = answeredOptions[i]; + cell = row.createCell(count++); + cell.setCellValue(answeredOption); + if (StringUtils.equals(answeredOption, correctAnswers.get(i))) { + cell.setCellStyle(greenColor); + numberOfCorrectlyAnsweredByUser++; + numberOfCorrectAnswersPerQuestion[count-3]++; + } + } + + cell = row.createCell(count++); + cell.setCellValue(userMark.getTotalMark()); + + int totalPercents = numberOfCorrectlyAnsweredByUser * 100 / questions.size(); + totalPercentList.add(totalPercents); + cell = row.createCell(count++); + cell.setCellValue(totalPercents + "%"); + } + + rowCount++; + } + + //ave + row = sheet.createRow(rowCount++); + count = 1; + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.ave")); + for (int numberOfCorrectAnswers : numberOfCorrectAnswersPerQuestion) { + cell = row.createCell(count++); + cell.setCellValue(numberOfCorrectAnswers * 100 / totalPercentList.size() + "%"); + } + + //class mean + Integer[] totalPercents = totalPercentList.toArray(new Integer[0]); + Arrays.sort(totalPercents); + int sum = 0; + for (int i = 0; i < totalPercents.length; i++) { + sum += totalPercents[i]; + } + row = sheet.createRow(rowCount++); + cell = row.createCell(1); + cell.setCellValue(messageService.getMessage("label.class.mean")); + if (totalPercents.length != 0) { + int classMean = sum / totalPercents.length; + cell = row.createCell(questions.size() + 3); + cell.setCellValue(classMean + "%"); + } + + // median + row = sheet.createRow(rowCount++); + cell = row.createCell(1); + cell.setCellValue(messageService.getMessage("label.median")); + if (totalPercents.length != 0) { + int median; + int middle = totalPercents.length / 2; + if (totalPercents.length % 2 == 1) { + median = totalPercents[middle]; + } else { + median = (int) ((totalPercents[middle - 1] + totalPercents[middle]) / 2.0); + } + cell = row.createCell(questions.size() + 3); + cell.setCellValue(median + "%"); + } + + row = sheet.createRow(rowCount++); + cell = row.createCell(0); + cell.setCellValue(messageService.getMessage("label.legend")); + + row = sheet.createRow(rowCount++); + cell = row.createCell(0); + cell.setCellValue(messageService.getMessage("label.denotes.correct.answer")); + cell.setCellStyle(greenColor); + cell = row.createCell(1); + cell.setCellStyle(greenColor); + cell = row.createCell(2); + cell.setCellStyle(greenColor); + + // ======================================================= Marks page + // ======================================= + + sheet = wb.createSheet("Marks"); + + rowCount = 0; + count = 0; + + row = sheet.createRow(rowCount++); + for (McQueContent question : questions) { + cell = row.createCell(2 + count++); + cell.setCellValue(messageService.getMessage("label.monitoring.downloadMarks.question.mark", + new Object[] { count, question.getMark() })); + } + + for (McSessionMarkDTO sessionMarkDTO : sessionMarkDTOs) { + Map usersMarksMap = sessionMarkDTO.getUserMarks(); + + String currentSessionId = sessionMarkDTO.getSessionId(); + String currentSessionName = sessionMarkDTO.getSessionName(); + + if (currentMonitoredToolSession.equals("All") || currentMonitoredToolSession.equals(currentSessionId)) { + + row = sheet.createRow(rowCount++); + + cell = row.createCell(0); + cell.setCellValue(messageService.getMessage("group.label")); + + cell = row.createCell(1); + cell.setCellValue(currentSessionName); + cell.setCellStyle(greenColor); + + rowCount++; + count = 0; + + row = sheet.createRow(rowCount++); + + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.learner")); + + cell = row.createCell(count++); + cell.setCellValue(messageService.getMessage("label.monitoring.downloadMarks.username")); + + cell = row.createCell(questions.size() + 2); + cell.setCellValue(messageService.getMessage("label.total")); + + for (McUserMarkDTO userMark : usersMarksMap.values()) { + row = sheet.createRow(rowCount++); + count = 0; + + cell = row.createCell(count++); + cell.setCellValue(userMark.getFullName()); + + cell = row.createCell(count++); + cell.setCellValue(userMark.getUserName()); + + Integer[] marks = userMark.getMarks(); + for (int i = 0; i < marks.length; i++) { + cell = row.createCell(count++); + Integer mark = (marks[i] == null) ? 0 : marks[i]; + cell.setCellValue(mark); + } + + cell = row.createCell(count++); + cell.setCellValue(userMark.getTotalMark()); + } + + rowCount++; + } + + } + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + wb.write(bos); + + byte[] data = bos.toByteArray(); + + return data; } /** @@ -936,62 +1191,6 @@ } /** - * TO BE DEFINED-FUTURE API gets called from monitoring module - * - * update the tool session status to COMPLETE for this tool session - * - * @param Long - * toolSessionId - */ - public void setAsForceCompleteSession(Long toolSessionId) throws McApplicationException { - McSession mcSession = getMcSessionById(toolSessionId); - mcSession.setSessionStatus(McSession.COMPLETED); - updateMcSession(mcSession); - } - - /** - * TO BE DEFINED - * - * update the tool session status to COMPLETE for this user IMPLEMENT THIS!!!! Is this from ToolContentManager??? - * - * - * @param userId - */ - public void setAsForceComplete(Long userId) throws McApplicationException { - McQueUsr mcQueUsr = retrieveMcQueUsr(userId); - - if (mcQueUsr != null) { - McSession mcSession = mcQueUsr.getMcSession(); - if (mcSession != null) { - Long usersToolSessionId = mcSession.getMcSessionId(); - - mcSession = getMcSessionById(usersToolSessionId); - mcSession.setSessionStatus(McSession.COMPLETED); - updateMcSession(mcSession); - - McContent mcContent = mcSession.getMcContent(); - - /** - * if all the sessions of this content is COMPLETED, unlock the content - * - */ - int countIncompleteSession = countIncompleteSession(mcContent); - - if (countIncompleteSession == 0) { - mcContent.setContentInUse(false); - updateMc(mcContent); - } - } else { - McServicePOJO.logger.error("WARNING!: retrieved mcSession is null."); - throw new McApplicationException("Fail to setAsForceComplete" + " based on null mcSession."); - } - } else { - McServicePOJO.logger.error("WARNING!: retrieved mcQueUsr is null."); - throw new McApplicationException("Fail to setAsForceComplete" + " based on null mcQueUsr."); - } - } - - /** * Implemented as part of the tool contract. Sets the defineLater to true on this content. setAsDefineLater(Long * toolContentId) throws DataMissingException, ToolException * Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java,v diff -u -r1.21 -r1.22 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java 12 Aug 2013 16:29:02 -0000 1.21 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java 26 Aug 2013 11:03:49 -0000 1.22 @@ -136,8 +136,8 @@ if (learner != null) { McMonitoringAction mcMonitoringAction = new McMonitoringAction(); - List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionDataForExportLearner(request, - content, mcService, mcSession, learner); + List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionDataForExportLearner(content, + mcService, mcSession, learner); request.getSession().setAttribute(LIST_MONITORED_ANSWERS_CONTAINER_DTO, listMonitoredAnswersContainerDTO); request.getSession().setAttribute(LEARNER_MARK, learner.getLastAttemptTotalMark()); @@ -179,10 +179,10 @@ McMonitoringAction mcMonitoringAction = new McMonitoringAction(); - List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionData(request, content, mcService); + List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionData(content, mcService); request.getSession().setAttribute(LIST_MONITORED_ANSWERS_CONTAINER_DTO, listMonitoredAnswersContainerDTO); - List listMonitoredMarksContainerDTO = MonitoringUtil.buildGroupsMarkData(request, content, mcService); + List listMonitoredMarksContainerDTO = MonitoringUtil.buildGroupsMarkData(content, mcService); request.getSession().setAttribute(LIST_MONITORED_MARKS_CONTAINER_DTO, listMonitoredMarksContainerDTO); request.getSession().setAttribute(PASSMARK, content.getPassMark().toString()); @@ -203,16 +203,12 @@ public void writeOutSessionData(HttpServletRequest request, HttpServletResponse response, McContent mcContent, IMcService mcService, String directoryName) { String fileName = "lams_mcq_All_" + toolContentID + ".xls"; - MessageService messageService = McServiceProxy.getMessageService(getServletContext()); OutputStream out = null; try { out = new FileOutputStream(directoryName + File.separator + fileName); - McMonitoringAction mcMonitoringAction = new McMonitoringAction(); - byte[] spreadsheet = mcMonitoringAction.prepareSessionDataSpreadsheet(request, response, mcContent, - mcService, messageService, "All"); - + byte[] spreadsheet = mcService.prepareSessionDataSpreadsheet(request, mcContent, "All"); out.write(spreadsheet); request.getSession().setAttribute(PORTFOLIO_EXPORT_DATA_FILENAME, fileName); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java,v diff -u -r1.52 -r1.53 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java 12 Aug 2013 16:29:02 -0000 1.52 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java 26 Aug 2013 11:03:49 -0000 1.53 @@ -22,7 +22,6 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.web; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; @@ -40,10 +39,6 @@ import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; -import org.apache.poi.hssf.usermodel.HSSFCell; -import org.apache.poi.hssf.usermodel.HSSFRow; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.struts.Globals; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; @@ -60,10 +55,7 @@ import org.lamsfoundation.lams.tool.mc.McGeneralAuthoringDTO; import org.lamsfoundation.lams.tool.mc.McGeneralLearnerFlowDTO; import org.lamsfoundation.lams.tool.mc.McGeneralMonitoringDTO; -import org.lamsfoundation.lams.tool.mc.McMonitoredAnswersDTO; import org.lamsfoundation.lams.tool.mc.McQuestionContentDTO; -import org.lamsfoundation.lams.tool.mc.McSessionMarkDTO; -import org.lamsfoundation.lams.tool.mc.McUserMarkDTO; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.ReflectionDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; @@ -141,7 +133,6 @@ McContent mcContent = mcService.retrieveMc(new Long(toolContentID)); if (currentMonitoredToolSession.equals("All")) { - List listMcAllSessionsDTO = new LinkedList(); // generate DTO for All sessions MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); @@ -186,8 +177,6 @@ } } - int maxIndex = mapOptionsContent.size(); - boolean isContentInUse = McUtils.isContentInUse(mcContent); mcGeneralMonitoringDTO.setIsMonitoredContentInUse(new Boolean(false).toString()); if (isContentInUse == true) { @@ -359,9 +348,6 @@ mcGeneralAuthoringDTO.setActivityInstructions(mcContent.getInstructions()); - /* determine whether the request is from Monitoring url Edit Activity */ - String sourceMcStarter = (String) request.getAttribute(SOURCE_MC_STARTER); - mcAuthoringForm.setDefineLaterInEditMode(new Boolean(true).toString()); mcGeneralAuthoringDTO.setDefineLaterInEditMode(new Boolean(true).toString()); @@ -448,7 +434,9 @@ } /* ... till here */ MonitoringUtil.setSessionUserCount(mcContent, mcGeneralMonitoringDTO); - MonitoringUtil.generateGroupsSessionData(request, mcService, mcContent); + + List listAllGroupsDTO = MonitoringUtil.buildGroupBasedSessionData(mcContent, mcService); + request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); @@ -488,7 +476,7 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); @@ -507,8 +495,6 @@ Map mapWeights = new TreeMap(new McComparator()); - String totalMarks = request.getParameter("totalMarks"); - Map mapMarks = AuthoringUtil.extractMapMarks(listQuestionContentDTO); Map mapCandidatesList = AuthoringUtil.extractMapCandidatesList(listQuestionContentDTO); @@ -525,13 +511,8 @@ McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); if (activeModule.equals(AUTHORING)) { - List attachmentListBackup = new ArrayList(); List attachmentList = (List) sessionMap.get(ATTACHMENT_LIST_KEY); - attachmentListBackup = attachmentList; - - List deletedAttachmentListBackup = new ArrayList(); List deletedAttachmentList = (List) sessionMap.get(DELETED_ATTACHMENT_LIST_KEY); - deletedAttachmentListBackup = deletedAttachmentList; String onlineInstructions = (String) sessionMap.get(ONLINE_INSTRUCTIONS_KEY); mcGeneralAuthoringDTO.setOnlineInstructions(onlineInstructions); @@ -686,7 +667,8 @@ } /* ... till here */ MonitoringUtil.setSessionUserCount(mcContent, mcGeneralMonitoringDTO); - MonitoringUtil.generateGroupsSessionData(request, mcService, mcContent); + List listAllGroupsDTO = MonitoringUtil.buildGroupBasedSessionData(mcContent, mcService); + request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); @@ -710,7 +692,7 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); @@ -886,7 +868,7 @@ * @param listQuestionContentDTO */ protected void commonSaveCode(HttpServletRequest request, McGeneralAuthoringDTO mcGeneralAuthoringDTO, - McAuthoringForm mcAuthoringForm, SessionMap sessionMap, String activeModule, String strToolContentID, + McAuthoringForm mcAuthoringForm, SessionMap sessionMap, String activeModule, String strToolContentID, String defaultContentIdStr, IMcService mcService, String httpSessionID, List listQuestionContentDTO) { String richTextTitle = request.getParameter(TITLE); String richTextInstructions = request.getParameter(INSTRUCTIONS); @@ -956,15 +938,13 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String totalMarks = request.getParameter("totalMarks"); String activeModule = request.getParameter(ACTIVE_MODULE); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -976,8 +956,6 @@ List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); List listAddableQuestionContentDTO = (List) sessionMap.get(NEW_ADDABLE_QUESTION_CONTENT_KEY); - McQuestionContentDTO mcQuestionContentDTONew = null; - int listSize = listQuestionContentDTO.size(); request.setAttribute(NEW_ADDABLE_QUESTION_CONTENT_LIST, listAddableQuestionContentDTO); @@ -1100,13 +1078,11 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); mcAuthoringForm.setContentFolderID(contentFolderID); - String totalMarks = request.getParameter("totalMarks"); - String activeModule = request.getParameter(ACTIVE_MODULE); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); @@ -1209,10 +1185,8 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - String totalMarks = request.getParameter("totalMarks"); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); @@ -1304,8 +1278,6 @@ String requestNewEditableQuestionBox = (String) request.getAttribute("requestNewEditableQuestionBox"); - String editQuestionBoxRequest = request.getParameter("editQuestionBoxRequest"); - String newQuestion = request.getParameter("newQuestion"); if ((requestNewEditableQuestionBox != null) && requestNewEditableQuestionBox.equals("true")) { @@ -1352,12 +1324,10 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); - String totalMarks = request.getParameter("totalMarks"); - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); McQuestionContentDTO mcQuestionContentDTO = null; @@ -1475,12 +1445,10 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); - String totalMarks = request.getParameter("totalMarks"); - List listQuestionContentDTO = (List) sessionMap.get(LIST_QUESTION_CONTENT_DTO_KEY); listQuestionContentDTO = AuthoringUtil.swapNodes(listQuestionContentDTO, questionIndex, "down"); @@ -1571,7 +1539,7 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); @@ -1585,14 +1553,12 @@ String activeModule = request.getParameter(ACTIVE_MODULE); String richTextTitle = request.getParameter(TITLE); - String totalMarks = request.getParameter("totalMarks"); String richTextInstructions = request.getParameter(INSTRUCTIONS); sessionMap.put(ACTIVITY_TITLE_KEY, richTextTitle); sessionMap.put(ACTIVITY_INSTRUCTIONS_KEY, richTextInstructions); String strToolContentID = request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); String defaultContentIdStr = new Long(mcService.getToolDefaultContentIdBySignature(MY_SIGNATURE)).toString(); - ; McContent mcContent = mcService.retrieveMc(new Long(strToolContentID)); McGeneralAuthoringDTO mcGeneralAuthoringDTO = new McGeneralAuthoringDTO(); mcGeneralAuthoringDTO.setContentFolderID(contentFolderID); @@ -1666,14 +1632,13 @@ String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); String candidateIndex = request.getParameter("candidateIndex"); mcAuthoringForm.setCandidateIndex(candidateIndex); - String totalMarks = request.getParameter("totalMarks"); AuthoringUtil authoringUtil = new AuthoringUtil(); boolean validateCandidateAnswersNotBlank = authoringUtil.validateCandidateAnswersNotBlank(request); ActionMessages errors = new ActionMessages(); @@ -1821,7 +1786,7 @@ IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); String httpSessionID = mcAuthoringForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); String questionIndex = request.getParameter("questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndex); @@ -3091,7 +3056,8 @@ /* ... till here */ MonitoringUtil.setSessionUserCount(mcContent, mcGeneralMonitoringDTO); - MonitoringUtil.generateGroupsSessionData(request, mcService, mcContent); + List listAllGroupsDTO = MonitoringUtil.buildGroupBasedSessionData(mcContent, mcService); + request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); MonitoringUtil.setupAllSessionsData(request, mcContent, mcService); } @@ -3121,8 +3087,7 @@ byte[] spreadsheet = null; try { - spreadsheet = prepareSessionDataSpreadsheet(request, response, mcContent, mcService, messageService, - currentMonitoredToolSession); + spreadsheet = mcService.prepareSessionDataSpreadsheet(request, mcContent, currentMonitoredToolSession); } catch (Exception e) { log.error("Error preparing spreadsheet: ", e); request.setAttribute("errorName", messageService.getMessage("error.monitoring.spreadsheet.download")); @@ -3154,115 +3119,6 @@ } /** - * prepareSessionDataSpreadsheet - * - * @param request - * @param response - * @param mcContent - * @param mcService - * @param currentMonitoredToolSession - * - * @return data to write out - */ - public byte[] prepareSessionDataSpreadsheet(HttpServletRequest request, HttpServletResponse response, - McContent mcContent, IMcService mcService, MessageService messageService, String currentMonitoredToolSession) - throws IOException, ServletException { - // create an empty excel file - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet sheet = wb.createSheet("Marks"); - - HSSFRow row; - HSSFCell cell; - - List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionData(request, mcContent, mcService); - List listMonitoredMarksContainerDTO = MonitoringUtil.buildGroupsMarkData(request, mcContent, mcService); - - int idx = 0; - - Iterator marksIterator = listMonitoredMarksContainerDTO.iterator(); - - while (marksIterator.hasNext()) { - - McSessionMarkDTO mcSessionMarkDTO = (McSessionMarkDTO) marksIterator.next(); - Map usersMarksMap = mcSessionMarkDTO.getUserMarks(); - - String currentSessionId = mcSessionMarkDTO.getSessionId(); - String currentSessionName = mcSessionMarkDTO.getSessionName(); - - if (currentMonitoredToolSession.equals("All") || currentMonitoredToolSession.equals(currentSessionId)) { - - row = sheet.createRow(idx++); - - cell = row.createCell(0); - cell.setCellValue(messageService.getMessage("group.label")); - - cell = row.createCell(1); - cell.setCellValue(currentSessionName); - - idx++; - int count = 0; - - row = sheet.createRow(idx++); - - cell = row.createCell(count++); - cell.setCellValue(messageService.getMessage("label.learner")); - - cell = row.createCell(count++); - cell.setCellValue(messageService.getMessage("label.monitoring.downloadMarks.username")); - - Iterator answersIterator = listMonitoredAnswersContainerDTO.iterator(); - - while (answersIterator.hasNext()) { - McMonitoredAnswersDTO mcMonitoredAnswersDTO = (McMonitoredAnswersDTO) answersIterator.next(); - - cell = row.createCell(count++); - cell.setCellValue(messageService.getMessage("label.monitoring.downloadMarks.question.mark", - new Object[] { count - 2, mcMonitoredAnswersDTO.getMark() })); - } - - cell = row.createCell(count++); - cell.setCellValue(messageService.getMessage("label.total")); - - Iterator userMarkIterator = usersMarksMap.values().iterator(); - - while (userMarkIterator.hasNext()) { - row = sheet.createRow(idx++); - count = 0; - - McUserMarkDTO userMark = (McUserMarkDTO) userMarkIterator.next(); - String currentUserSessionId = userMark.getSessionId(); - - cell = row.createCell(count++); - cell.setCellValue(userMark.getFullName()); - - cell = row.createCell(count++); - cell.setCellValue(userMark.getUserName()); - - Integer[] marks = userMark.getMarks(); - for (int i = 0; i < marks.length; i++) { - cell = row.createCell(count++); - Integer mark = (marks[i] == null) ? 0 : marks[i]; - cell.setCellValue(mark); - } - - cell = row.createCell(count++); - cell.setCellValue(userMark.getTotalMark()); - } - - idx++; - } - - } - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - wb.write(bos); - - byte[] data = bos.toByteArray(); - - return data; - } - - /** * Set Submission Deadline * * @param mapping Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java,v diff -u -r1.38 -r1.39 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java 12 Aug 2013 16:29:02 -0000 1.38 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java 26 Aug 2013 11:03:49 -0000 1.39 @@ -38,13 +38,15 @@ import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; import org.lamsfoundation.lams.tool.mc.McAllGroupsDTO; import org.lamsfoundation.lams.tool.mc.McAppConstants; +import org.lamsfoundation.lams.tool.mc.McCandidateAnswersDTO; import org.lamsfoundation.lams.tool.mc.McGeneralMonitoringDTO; import org.lamsfoundation.lams.tool.mc.McMonitoredAnswersDTO; import org.lamsfoundation.lams.tool.mc.McMonitoredUserDTO; import org.lamsfoundation.lams.tool.mc.McSessionMarkDTO; import org.lamsfoundation.lams.tool.mc.McStringComparator; import org.lamsfoundation.lams.tool.mc.McUserMarkDTO; import org.lamsfoundation.lams.tool.mc.pojos.McContent; +import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueContent; import org.lamsfoundation.lams.tool.mc.pojos.McQueUsr; import org.lamsfoundation.lams.tool.mc.pojos.McSession; @@ -72,48 +74,46 @@ * @param mcContent * @return List */ - public static List buildGroupsQuestionData(HttpServletRequest request, McContent mcContent, IMcService mcService) { + public static List buildGroupsQuestionData(McContent mcContent, IMcService mcService) { // will be building groups question data for content - List listQuestions = mcService.getAllQuestionEntries(mcContent.getUid()); + List questions = mcService.getAllQuestionEntries(mcContent.getUid()); - List listMonitoredAnswersContainerDTO = new LinkedList(); + List monitoredAnswersDTOs = new LinkedList(); - Iterator itListQuestions = listQuestions.iterator(); - while (itListQuestions.hasNext()) { - McQueContent mcQueContent = (McQueContent) itListQuestions.next(); + for (McQueContent question : questions) { - if (mcQueContent != null) { - McMonitoredAnswersDTO mcMonitoredAnswersDTO = new McMonitoredAnswersDTO(); - mcMonitoredAnswersDTO.setQuestionUid(mcQueContent.getUid().toString()); - mcMonitoredAnswersDTO.setQuestion(mcQueContent.getQuestion()); - mcMonitoredAnswersDTO.setMark(mcQueContent.getMark().toString()); + if (question != null) { + McMonitoredAnswersDTO monitoredAnswersDTO = new McMonitoredAnswersDTO(); + monitoredAnswersDTO.setQuestionUid(question.getUid().toString()); + monitoredAnswersDTO.setQuestion(question.getQuestion()); + monitoredAnswersDTO.setMark(question.getMark().toString()); - List listCandidateAnswersDTO = mcService.populateCandidateAnswersDTO(mcQueContent.getUid()); - mcMonitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); - - Map questionAttemptData = new TreeMap(new McStringComparator()); + List listCandidateAnswersDTO = mcService.populateCandidateAnswersDTO(question + .getUid()); + monitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); - Iterator sessionIterator = mcContent.getMcSessions().iterator(); - while (sessionIterator.hasNext()) { - McSession mcSession = (McSession) sessionIterator.next(); - Set listMcUsers = mcSession.getMcQueUsers(); + Map> questionAttemptData = new TreeMap>( + new McStringComparator()); + + for (McSession session : (Set) mcContent.getMcSessions()) { + Set users = session.getMcQueUsers(); List monitoredUserDTOs = new LinkedList(); - for (McQueUsr mcQueUsr : listMcUsers) { - McMonitoredUserDTO mcMonitoredUserDTO = getUserAttempt(request, mcService, mcQueUsr, mcSession, - mcQueContent.getUid()); - monitoredUserDTOs.add(mcMonitoredUserDTO); + for (McQueUsr user : users) { + McMonitoredUserDTO monitoredUserDTO = getUserAttempt(mcService, user, session, + question.getUid()); + monitoredUserDTOs.add(monitoredUserDTO); } - - questionAttemptData.put(mcSession.getSession_name(), monitoredUserDTOs); + + questionAttemptData.put(session.getSession_name(), monitoredUserDTOs); } - - mcMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); - listMonitoredAnswersContainerDTO.add(mcMonitoredAnswersDTO); + monitoredAnswersDTO.setQuestionAttempts(questionAttemptData); + monitoredAnswersDTOs.add(monitoredAnswersDTO); + } } - return listMonitoredAnswersContainerDTO; + return monitoredAnswersDTOs; } /** @@ -125,37 +125,37 @@ * @param mcQueUsr * @return */ - public static List buildGroupsQuestionDataForExportLearner(HttpServletRequest request, McContent mcContent, - IMcService mcService, McSession mcSession, McQueUsr mcQueUsr) { + public static List buildGroupsQuestionDataForExportLearner(McContent mcContent, IMcService mcService, + McSession mcSession, McQueUsr mcQueUsr) { - List listQuestions = mcService.getAllQuestionEntries(mcContent.getUid()); + List questions = mcService.getAllQuestionEntries(mcContent.getUid()); List listMonitoredAnswersContainerDTO = new LinkedList(); - Iterator itListQuestions = listQuestions.iterator(); + Iterator itListQuestions = questions.iterator(); while (itListQuestions.hasNext()) { - McQueContent mcQueContent = (McQueContent) itListQuestions.next(); + McQueContent question = itListQuestions.next(); - if (mcQueContent != null) { - McMonitoredAnswersDTO mcMonitoredAnswersDTO = new McMonitoredAnswersDTO(); - mcMonitoredAnswersDTO.setQuestionUid(mcQueContent.getUid().toString()); - mcMonitoredAnswersDTO.setQuestion(mcQueContent.getQuestion()); - mcMonitoredAnswersDTO.setMark(mcQueContent.getMark().toString()); + if (question != null) { + McMonitoredAnswersDTO monitoredAnswersDTO = new McMonitoredAnswersDTO(); + monitoredAnswersDTO.setQuestionUid(question.getUid().toString()); + monitoredAnswersDTO.setQuestion(question.getQuestion()); + monitoredAnswersDTO.setMark(question.getMark().toString()); - List listCandidateAnswersDTO = mcService.populateCandidateAnswersDTO(mcQueContent.getUid()); - mcMonitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); + List listCandidateAnswersDTO = mcService.populateCandidateAnswersDTO(question.getUid()); + monitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); // Get the attempts for this user. The maps must match the maps in buildGroupsAttemptData or the jsp // won't work. - McMonitoredUserDTO mcMonitoredUserDTO = getUserAttempt(request, mcService, mcQueUsr, mcSession, - mcQueContent.getUid()); + McMonitoredUserDTO mcMonitoredUserDTO = getUserAttempt(mcService, mcQueUsr, mcSession, + question.getUid()); List listMonitoredUserContainerDTO = new LinkedList(); listMonitoredUserContainerDTO.add(mcMonitoredUserDTO); Map questionAttemptData = new TreeMap(new McStringComparator()); questionAttemptData.put(mcSession.getSession_name(), listMonitoredUserContainerDTO); - mcMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); - listMonitoredAnswersContainerDTO.add(mcMonitoredAnswersDTO); + monitoredAnswersDTO.setQuestionAttempts(questionAttemptData); + listMonitoredAnswersContainerDTO.add(monitoredAnswersDTO); } } return listMonitoredAnswersContainerDTO; @@ -168,27 +168,27 @@ * @param mcService * @return */ - public static List buildGroupsMarkData(HttpServletRequest request, McContent mcContent, IMcService mcService) { - List listMonitoredMarksContainerDTO = new LinkedList(); - Set sessions = mcContent.getMcSessions(); - Iterator sessionsIterator = sessions.iterator(); + public static List buildGroupsMarkData(McContent mcContent, IMcService mcService) { + List listMonitoredMarksContainerDTO = new LinkedList(); + Set sessions = mcContent.getMcSessions(); + Iterator sessionsIterator = sessions.iterator(); int numQuestions = mcContent.getMcQueContents().size(); while (sessionsIterator.hasNext()) { - McSession mcSession = (McSession) sessionsIterator.next(); + McSession mcSession = sessionsIterator.next(); McSessionMarkDTO mcSessionMarkDTO = new McSessionMarkDTO(); mcSessionMarkDTO.setSessionId(mcSession.getMcSessionId().toString()); mcSessionMarkDTO.setSessionName(mcSession.getSession_name().toString()); - Set sessionUsers = mcSession.getMcQueUsers(); - Iterator usersIterator = sessionUsers.iterator(); + Set sessionUsers = mcSession.getMcQueUsers(); + Iterator usersIterator = sessionUsers.iterator(); - Map mapSessionUsersData = new TreeMap(new McStringComparator()); + Map mapSessionUsersData = new TreeMap(new McStringComparator()); Long mapIndex = new Long(1); while (usersIterator.hasNext()) { - McQueUsr user = (McQueUsr) usersIterator.next(); + McQueUsr user = usersIterator.next(); McUserMarkDTO mcUserMarkDTO = new McUserMarkDTO(); mcUserMarkDTO.setSessionId(mcSession.getMcSessionId().toString()); @@ -207,11 +207,11 @@ // than one in the future and if so, we don't want to count the mark twice hence // we need to check if we've already processed this question in the total. Integer[] userMarks = new Integer[numQuestions]; + String[] answeredOptions = new String[numQuestions]; Date attemptTime = null; - Iterator attemptIterator = mcService.getFinalizedUserAttempts(user).iterator(); + List finalizedUserAttempts = mcService.getFinalizedUserAttempts(user); long totalMark = 0; - while (attemptIterator.hasNext()) { - McUsrAttempt attempt = (McUsrAttempt) attemptIterator.next(); + for (McUsrAttempt attempt : finalizedUserAttempts) { Integer displayOrder = attempt.getMcQueContent().getDisplayOrder(); int arrayIndex = displayOrder != null && displayOrder.intValue() > 0 ? displayOrder.intValue() - 1 : 1; @@ -224,13 +224,26 @@ Integer mark = attempt.getMarkForShow(isRetries); userMarks[arrayIndex] = mark; totalMark += mark.intValue(); + + // find out the answered option's sequential letter - A,B,C... + String answeredOptionLetter = ""; + int optionCount = 1; + for (McOptsContent option : (Set) attempt.getMcQueContent().getMcOptionsContents()) { + if (attempt.getMcOptionsContent().getUid().equals(option.getUid())) { + answeredOptionLetter = String.valueOf((char) (optionCount + 'A' - 1)); + break; + } + optionCount++; + } + answeredOptions[arrayIndex] = answeredOptionLetter; } // get the attempt time, (NB all questions will have the same attempt time) // Not efficient, since we assign this value for each attempt attemptTime = attempt.getAttemptTime(); } mcUserMarkDTO.setMarks(userMarks); + mcUserMarkDTO.setAnsweredOptions(answeredOptions); mcUserMarkDTO.setAttemptTime(attemptTime); mcUserMarkDTO.setTotalMark(new Long(totalMark)); @@ -248,7 +261,7 @@ /** * */ - public static McMonitoredUserDTO getUserAttempt(HttpServletRequest request, IMcService mcService, McQueUsr mcQueUsr, + public static McMonitoredUserDTO getUserAttempt(IMcService mcService, McQueUsr mcQueUsr, McSession mcSession, Long questionUid) { McMonitoredUserDTO mcMonitoredUserDTO = new McMonitoredUserDTO(); @@ -348,21 +361,11 @@ /** * @param request - * @param mcService * @param mcContent - */ - public static void generateGroupsSessionData(HttpServletRequest request, IMcService mcService, McContent mcContent) { - List listAllGroupsDTO = buildGroupBasedSessionData(request, mcContent, mcService); - request.setAttribute(LIST_ALL_GROUPS_DTO, listAllGroupsDTO); - } - - /** - * @param request - * @param mcContent * @param mcService * @return */ - public static List buildGroupBasedSessionData(HttpServletRequest request, McContent mcContent, IMcService mcService) { + public static List buildGroupBasedSessionData(McContent mcContent, IMcService mcService) { List listQuestions = mcService.getAllQuestionEntries(mcContent.getUid()); List listAllGroupsContainerDTO = new LinkedList(); @@ -415,10 +418,10 @@ * @param mcService */ protected static void setupAllSessionsData(HttpServletRequest request, McContent mcContent, IMcService mcService) { - List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionData(request, mcContent, mcService); + List listMonitoredAnswersContainerDTO = MonitoringUtil.buildGroupsQuestionData(mcContent, mcService); request.setAttribute(LIST_MONITORED_ANSWERS_CONTAINER_DTO, listMonitoredAnswersContainerDTO); - List listMonitoredMarksContainerDTO = MonitoringUtil.buildGroupsMarkData(request, mcContent, mcService); + List listMonitoredMarksContainerDTO = MonitoringUtil.buildGroupsMarkData(mcContent, mcService); request.setAttribute(LIST_MONITORED_MARKS_CONTAINER_DTO, listMonitoredMarksContainerDTO); request.setAttribute(HR_COLUMN_COUNT, new Integer(mcContent.getMcQueContents().size() + 2).toString());