Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java,v diff -u -r1.11 -r1.12 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java 19 Oct 2012 12:08:12 -0000 1.11 +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java 8 Nov 2012 16:44:25 -0000 1.12 @@ -704,6 +704,7 @@ //clone it so it doesn't interfere with values from other sessions ScratchieAnswer answer = (ScratchieAnswer) dbAnswer.clone(); + answer.setUid(dbAnswer.getUid()); int[] attempts = new int[answers.size()]; answer.setAttempts(attempts); answerMap.put(dbAnswer.getUid(), answer); @@ -728,7 +729,40 @@ groupSummary.setAnswers(sortedAnswers); groupSummaryList.add(groupSummary); } + + //show total groupSummary if there is more than 1 group available + if (sessionList.size() > 1) { + Long sessionId = new Long(0); + GroupSummary groupSummaryTotal = new GroupSummary(sessionId, "Summary"); + Map answerMapTotal = new HashMap(); + for (ScratchieAnswer dbAnswer : (Set) answers) { + // clone it so it doesn't interfere with values from other sessions + ScratchieAnswer answer = (ScratchieAnswer) dbAnswer.clone(); + int[] attempts = new int[answers.size()]; + answer.setAttempts(attempts); + answerMapTotal.put(dbAnswer.getUid(), answer); + } + + for (GroupSummary groupSummary : groupSummaryList) { + Collection sortedAnswers = groupSummary.getAnswers(); + for (ScratchieAnswer sortedAnswer : sortedAnswers) { + int[] attempts = sortedAnswer.getAttempts(); + + ScratchieAnswer answerTotal = answerMapTotal.get(sortedAnswer.getUid()); + int[] attemptsTotal = answerTotal.getAttempts(); + for (int i = 0; i < attempts.length; i++) { + attemptsTotal[i] += attempts[i]; + } + } + } + + Collection sortedAnswers = new TreeSet(new ScratchieAnswerComparator()); + sortedAnswers.addAll(answerMapTotal.values()); + groupSummaryTotal.setAnswers(sortedAnswers); + groupSummaryList.add(0, groupSummaryTotal); + } + return groupSummaryList; }