Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/dto/GroupSummary.java =================================================================== diff -u -r97d962379745efc8be6cd313f8dfe640f9edcbf2 -r9745b1195865df088e1203cae362ae60fb78fcbd --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/dto/GroupSummary.java (.../GroupSummary.java) (revision 97d962379745efc8be6cd313f8dfe640f9edcbf2) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/dto/GroupSummary.java (.../GroupSummary.java) (revision 9745b1195865df088e1203cae362ae60fb78fcbd) @@ -22,6 +22,8 @@ package org.lamsfoundation.lams.tool.peerreview.dto; +import org.lamsfoundation.lams.tool.peerreview.model.PeerreviewSession; + public class GroupSummary implements Comparable { private Long sessionId; @@ -54,24 +56,9 @@ @Override public int compareTo(GroupSummary o) { - String name1 = this.sessionName.toLowerCase(); - String name2 = o.sessionName.toLowerCase(); - String nameWithoutNumbers1 = name1.replaceAll("\\d+", ""); - String nameWithoutNumbers2 = name2.replaceAll("\\d+", ""); - if (!nameWithoutNumbers1.equals(nameWithoutNumbers2)) { - return name1.compareTo(name2); + if (o == null) { + return 1; } - String numbers1 = name1.replaceAll("\\D+", ""); - String numbers2 = name2.replaceAll("\\D+", ""); - if (numbers1.length() == 0 || numbers2.length() == 0) { - return name1.compareTo(name2); - } - try { - Long num1 = Long.parseLong(numbers1); - Long num2 = Long.parseLong(numbers2); - return num1.compareTo(num2); - } catch (Exception e) { - return name1.compareTo(name2); - } + return PeerreviewSession.SESSION_NAME_COMPARATOR.compare(sessionName, o.getSessionName()); } } \ No newline at end of file Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/model/PeerreviewSession.java =================================================================== diff -u -r91082736703fb64b4b0024953bb394371119c89a -r9745b1195865df088e1203cae362ae60fb78fcbd --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/model/PeerreviewSession.java (.../PeerreviewSession.java) (revision 91082736703fb64b4b0024953bb394371119c89a) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/model/PeerreviewSession.java (.../PeerreviewSession.java) (revision 9745b1195865df088e1203cae362ae60fb78fcbd) @@ -23,7 +23,10 @@ package org.lamsfoundation.lams.tool.peerreview.model; +import org.lamsfoundation.lams.tool.peerreview.util.SessionNameComparator; + import javax.persistence.*; +import java.util.Comparator; import java.util.Date; /** @@ -33,8 +36,10 @@ */ @Entity @Table(name = "tl_laprev11_session") -public class PeerreviewSession { +public class PeerreviewSession implements Comparable { + public static final Comparator SESSION_NAME_COMPARATOR = new SessionNameComparator(); + @Id @Column @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -155,4 +160,12 @@ public void setEmailsSent(boolean emailsSent) { this.emailsSent = emailsSent; } + + @Override + public int compareTo(PeerreviewSession o) { + if (o == null) { + return 1; + } + return SESSION_NAME_COMPARATOR.compare(this.getSessionName(), o.getSessionName()); + } } \ No newline at end of file Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/util/SpreadsheetBuilder.java =================================================================== diff -u -r98de145a554d7e654e65f11c8e04d9c8c8d98b20 -r9745b1195865df088e1203cae362ae60fb78fcbd --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/util/SpreadsheetBuilder.java (.../SpreadsheetBuilder.java) (revision 98de145a554d7e654e65f11c8e04d9c8c8d98b20) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/util/SpreadsheetBuilder.java (.../SpreadsheetBuilder.java) (revision 9745b1195865df088e1203cae362ae60fb78fcbd) @@ -1,17 +1,5 @@ package org.lamsfoundation.lams.tool.peerreview.util; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.math.RoundingMode; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.stream.Collectors; - import org.apache.commons.lang.StringEscapeUtils; import org.apache.poi.ss.usermodel.IndexedColors; import org.lamsfoundation.lams.rating.dto.ItemRatingCriteriaDTO; @@ -30,11 +18,23 @@ import org.lamsfoundation.lams.util.excel.ExcelSheet; import org.springframework.util.StringUtils; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + /** - * Creates a Spreadsheet that reports the averages, with each team/group shown on a separate worksheet. - * Calculates averages for each rating and for each user. The SPA factor then calculates the user's overall average - * against the team average. - * Has a empty Mark column so that the teacher can add a manual mark if they want. + * Creates a Spreadsheet that reports the averages, with each team/group shown on a separate worksheet. Calculates + * averages for each rating and for each user. The SPA factor then calculates the user's overall average against the + * team average. Has a empty Mark column so that the teacher can add a manual mark if they want. */ public class SpreadsheetBuilder { private Peerreview peerreview; @@ -67,7 +67,7 @@ // populate the header row generateTitleRow(); - List sessions = peerreviewSessionDao.getByContentId(peerreview.getContentId()); + Set sessions = new TreeSet<>(peerreviewSessionDao.getByContentId(peerreview.getContentId())); ExcelSheet allLearnersSheet = null; if (sessions.size() > 1) { @@ -80,7 +80,7 @@ List allLearnersTitleCells = new LinkedList<>(); for (ExcelCell cell : titleRow.getCells()) { - if (allLearnersTitleCells.size() == 2) { + if (allLearnersTitleCells.size() == 3) { // same cells as in groups' tab header row, plus Group column ExcelCell groupCell = new ExcelCell(service.getLocalisedMessage("label.group", null), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); @@ -100,7 +100,7 @@ for (ExcelRow userRow : userRows) { List allLearnersUserCells = new LinkedList<>(); for (ExcelCell cell : userRow.getCells()) { - if (allLearnersUserCells.size() == 2) { + if (allLearnersUserCells.size() == 3) { // same cells as in groups' tab header row, plus Group column ExcelCell groupCell = new ExcelCell(session.getSessionName()); allLearnersUserCells.add(groupCell); @@ -123,6 +123,8 @@ */ private void generateTitleRow() { titleRow = new ExcelRow(); + titleRow.addCell(service.getLocalisedMessage("label.user.name", null), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); titleRow.addCell(service.getLocalisedMessage("label.first.name", null), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); titleRow.addCell(service.getLocalisedMessage("label.last.name", null), true, @@ -135,7 +137,8 @@ // for each rubrics we separate its rows with a left border Integer ratingCriteriaGroupId = criteria.getRatingCriteriaGroupId(); int[] borders = null; - if (ratingCriteriaGroupId == null ? previousRatingCriteriaGroupId != null + if (ratingCriteriaGroupId == null + ? previousRatingCriteriaGroupId != null : !ratingCriteriaGroupId.equals(previousRatingCriteriaGroupId)) { borders = new int[] { ExcelCell.BORDER_STYLE_BOTTOM_THIN, ExcelCell.BORDER_STYLE_LEFT_THIN }; } else { @@ -200,8 +203,8 @@ for (ItemRatingCriteriaDTO itemRatingCriteriaDTO : ratingDto.getCriteriaDtos()) { if (itemRatingCriteriaDTO.getAverageRatingAsNumber() != null && !itemRatingCriteriaDTO.getAverageRatingAsNumber().equals(0)) { - Integer criteriaIndex = criteriaIndexMap - .get(itemRatingCriteriaDTO.getRatingCriteria().getRatingCriteriaId()); + Integer criteriaIndex = criteriaIndexMap.get( + itemRatingCriteriaDTO.getRatingCriteria().getRatingCriteriaId()); double db = itemRatingCriteriaDTO.getAverageRatingAsNumber().doubleValue(); userRowData[criteriaIndex] = roundTo2Places(db); criteriaMarkSum[criteriaIndex] += db; @@ -214,6 +217,7 @@ Long userId = ratingDto.getItemId(); PeerreviewUser user = userMap.get(userId); + userRow.addCell(StringEscapeUtils.escapeCsv(user.getLoginName())); userRow.addCell(StringEscapeUtils.escapeCsv(user.getFirstName())); userRow.addCell(StringEscapeUtils.escapeCsv(user.getLastName())); @@ -229,6 +233,7 @@ ExcelRow avgRow = new ExcelRow(); avgRow.addCell(service.getLocalisedMessage("label.average", null), true); avgRow.addEmptyCell(); + avgRow.addEmptyCell(); double averageMarkSum = 0D; for (int i = 0; i < criteriaMarkSum.length - 1; i++) { if (criteriaMarkCount[i] > 0) { @@ -239,23 +244,23 @@ avgRow.addEmptyCell(); } } - Double finalGroupAverage = countNonCommentCriteria > 0 - ? roundTo2Places(averageMarkSum / countNonCommentCriteria) - : 0D; + Double finalGroupAverage = + countNonCommentCriteria > 0 ? roundTo2Places(averageMarkSum / countNonCommentCriteria) : 0D; avgRow.addCell(finalGroupAverage, true); // the map is: itemId (who was rated) -> userId (who rated) -> rating from all categories - Map>> ratings = ratingService - .getRatingsByCriteriasAndItems(criteriaIndexMap.keySet(), userMap.keySet()).stream() - .filter(rating -> rating.getRating() != null) - .collect(Collectors.groupingBy(Rating::getItemId, Collectors - .groupingBy(rating -> rating.getLearner().getUserId().longValue(), Collectors.toSet()))); + Map>> ratings = ratingService.getRatingsByCriteriasAndItems( + criteriaIndexMap.keySet(), userMap.keySet()).stream().filter(rating -> rating.getRating() != null) + .collect(Collectors.groupingBy(Rating::getItemId, + Collectors.groupingBy(rating -> rating.getLearner().getUserId().longValue(), + Collectors.toSet()))); // Combine rated rows with rows with users not yet rated, to make up complete list, and write out to rowList. for (PeerreviewUser user : users) { ExcelRow userRow = userRowMap.get(user.getUserId()); if (userRow == null) { userRow = sessionSheet.initRow(); + userRow.addCell(StringEscapeUtils.escapeCsv(user.getLoginName())); userRow.addCell(StringEscapeUtils.escapeCsv(user.getFirstName())); userRow.addCell(StringEscapeUtils.escapeCsv(user.getLastName())); } else { @@ -289,11 +294,11 @@ pa = peerRatingCriteriaCount == 0 ? null : roundTo2Places(sumPeerRatings / peerRatingCriteriaCount); if (peerreview.isSelfReview()) { - sa = selfRatingCriteriaCount == 0 ? null + sa = selfRatingCriteriaCount == 0 + ? null : roundTo2Places(sumSelfRatings / selfRatingCriteriaCount); - sapa = sumPeerRatings > 0 - ? roundTo2Places(Math.sqrt(sumSelfRatings / (sumPeerRatings / peerRatingCount))) - : 0; + sapa = sumPeerRatings > 0 ? roundTo2Places( + Math.sqrt(sumSelfRatings / (sumPeerRatings / peerRatingCount))) : 0; } } @@ -363,6 +368,7 @@ ExcelRow commentRow = sessionSheet.initRow(); Long commentingUserId = ((BigInteger) comment[0]).longValue(); PeerreviewUser commentingUser = userMap.get(commentingUserId); + commentRow.addCell(StringEscapeUtils.escapeCsv(commentingUser.getLoginName())); commentRow.addCell(StringEscapeUtils.escapeCsv(commentingUser.getFirstName())); commentRow.addCell(StringEscapeUtils.escapeCsv(commentingUser.getLastName())); commentRow.addCell(StringUtils.replace((String) comment[1], "
", "\n")); @@ -379,4 +385,4 @@ bd = bd.setScale(2, RoundingMode.HALF_UP); return bd.doubleValue(); } -} +} \ No newline at end of file