Skip to content

Commit

Permalink
conf scheduling: Show indictments in all views
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Jan 29, 2018
1 parent 1928816 commit b62909b
Showing 1 changed file with 42 additions and 37 deletions.
Expand Up @@ -929,14 +929,10 @@ private void writeRoomsView() {
.filter(talk -> talk.getRoom() == room) .filter(talk -> talk.getRoom() == room)
.collect(toList()); .collect(toList());
for (Timeslot timeslot : solution.getTimeslotList()) { for (Timeslot timeslot : solution.getTimeslotList()) {
List<Talk> talkList = roomTalkList.stream().filter(talk -> talk.getTimeslot() == timeslot) List<Talk> talkList = roomTalkList.stream()
.collect(toList()); .filter(talk -> talk.getTimeslot() == timeslot).collect(toList());
boolean pinnedByUser = talkList.stream().anyMatch(Talk::isPinnedByUser); nextTalkListCell(talkList,
HardSoftScore score = (HardSoftScore) talkList.stream().map(indictmentMap::get).filter(Objects::nonNull) room.getUnavailableTimeslotSet().contains(timeslot) ? unavailableStyle : null);
.map(Indictment::getScoreTotal).reduce(Score::add).orElse(HardSoftScore.ZERO);
CellStyle style = pinnedByUser ? pinnedStyle
: room.getUnavailableTimeslotSet().contains(timeslot) ? unavailableStyle : null;
nextCellWithScore(score, style).setCellValue(talkList.stream().map(Talk::getCode).collect(joining(", ")));
} }
} }
autoSizeColumnsWithHeader(); autoSizeColumnsWithHeader();
Expand All @@ -953,16 +949,14 @@ private void writeSpeakersView() {
for (Speaker speaker : solution.getSpeakerList()) { for (Speaker speaker : solution.getSpeakerList()) {
nextRow(); nextRow();
nextCell().setCellValue(speaker.getName()); nextCell().setCellValue(speaker.getName());
List<Talk> talkList = solution.getTalkList().stream() List<Talk> timeslotTalkList = solution.getTalkList().stream()
.filter(talk -> talk.getSpeakerList().contains(speaker)) .filter(talk -> talk.getSpeakerList().contains(speaker))
.collect(toList()); .collect(toList());
for (Timeslot timeslot : solution.getTimeslotList()) { for (Timeslot timeslot : solution.getTimeslotList()) {
List<Talk> filteredTalkList = talkList.stream().filter(talk -> talk.getTimeslot() == timeslot) List<Talk> talkList = timeslotTalkList.stream()
.collect(toList()); .filter(talk -> talk.getTimeslot() == timeslot).collect(toList());
HardSoftScore score = (HardSoftScore) filteredTalkList.stream().map(indictmentMap::get).filter(Objects::nonNull) nextTalkListCell(talkList,
.map(Indictment::getScoreTotal).reduce(Score::add).orElse(HardSoftScore.ZERO); speaker.getUnavailableTimeslotSet().contains(timeslot) ? unavailableStyle : null);
nextCellWithScore(score, speaker.getUnavailableTimeslotSet().contains(timeslot) ? unavailableStyle : null)
.setCellValue(filteredTalkList.stream().map(Talk::getCode).collect(joining(", ")));
} }
} }
autoSizeColumnsWithHeader(); autoSizeColumnsWithHeader();
Expand Down Expand Up @@ -991,7 +985,7 @@ private void writeThemeTracksView() {
if (talkList == null) { if (talkList == null) {
nextCell(); nextCell();
} else { } else {
nextCellWithIndictmentComment(talkList).setCellValue(talkList.stream().map(Talk::getCode).collect(joining(", "))); nextTalkListCell(talkList);
} }
} }
} }
Expand Down Expand Up @@ -1021,7 +1015,7 @@ private void writeSectorsView() {
if (talkList == null) { if (talkList == null) {
nextCell(); nextCell();
} else { } else {
nextCellWithIndictmentComment(talkList).setCellValue(talkList.stream().map(Talk::getCode).collect(joining(", "))); nextTalkListCell(talkList);
} }
} }
} }
Expand Down Expand Up @@ -1051,8 +1045,8 @@ private void writeContentsView() {
if (talkList == null) { if (talkList == null) {
nextCell(); nextCell();
} else { } else {
nextCellWithIndictmentComment(talkList).setCellValue(talkList.stream() nextTalkListCell(talkList,
.map(talk -> "(" + talk.getAudienceLevel() + ") " + talk.getCode()).collect(joining(", "))); talk -> "(" + talk.getAudienceLevel() + ") " + talk.getCode());
} }
} }
} }
Expand Down Expand Up @@ -1106,47 +1100,58 @@ protected void nextHeaderCell(String value) {
headerCellCount++; headerCellCount++;
} }


protected Cell nextCell() { protected void nextTalkListCell(List<Talk> talkList) {
return nextCell(null); nextTalkListCell(talkList, Talk::getCode, null);
}

protected void nextTalkListCell(List<Talk> talkList, CellStyle cellStyle) {
nextTalkListCell(talkList, Talk::getCode, cellStyle);
} }


protected Cell nextCellWithScore(HardSoftScore score) { protected void nextTalkListCell(List<Talk> talkList, Function<Talk, String> stringFunction) {
return nextCellWithScore(score, null); nextTalkListCell(talkList, stringFunction, null);
} }


protected Cell nextCellWithIndictmentComment(List<Talk> talkList) { protected void nextTalkListCell(List<Talk> talkList, Function<Talk, String> stringFunction, CellStyle cellStyle) {
List<Indictment> indictmentList = talkList.stream().map(indictmentMap::get).filter(Objects::nonNull).collect(Collectors.toList()); List<Indictment> indictmentList = talkList.stream().map(indictmentMap::get).filter(Objects::nonNull).collect(Collectors.toList());
HardSoftScore score = (HardSoftScore) indictmentList.stream().map(Indictment::getScoreTotal) HardSoftScore score = (HardSoftScore) indictmentList.stream().map(Indictment::getScoreTotal)
.reduce(Score::add).orElse(HardSoftScore.ZERO); .reduce(Score::add).orElse(HardSoftScore.ZERO);
Cell cell = nextCellWithScore(score); Cell cell;
if (talkList.stream().anyMatch(Talk::isPinnedByUser)) {
cell = nextCell(pinnedStyle);
} else if (!score.isFeasible()) {
cell = nextCell(hardPenaltyStyle);
} else if (cellStyle != null) {
cell = nextCell(cellStyle);
} else if (score.getSoftScore() < 0) {
cell = nextCell(softPenaltyStyle);
} else {
cell = nextCell();
}
if (!indictmentList.isEmpty()) { if (!indictmentList.isEmpty()) {
ClientAnchor anchor = creationHelper.createClientAnchor(); ClientAnchor anchor = creationHelper.createClientAnchor();
anchor.setCol1(cell.getColumnIndex()); anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 5); anchor.setCol2(cell.getColumnIndex() + 5);
anchor.setRow1(currentRow.getRowNum()); anchor.setRow1(currentRow.getRowNum());
anchor.setRow2(currentRow.getRowNum() + 5); anchor.setRow2(currentRow.getRowNum() + 5);
Comment comment = currentDrawing.createCellComment(anchor); Comment comment = currentDrawing.createCellComment(anchor);
comment.setString(creationHelper.createRichTextString(indictmentList.stream() comment.setString(creationHelper.createRichTextString(
.flatMap(indictment -> indictment.getConstraintMatchSet().stream()) "Constraint matches:\n "
+ indictmentList.stream().flatMap(indictment -> indictment.getConstraintMatchSet().stream())
.map(constraintMatch -> constraintMatch.getConstraintName() + " (" .map(constraintMatch -> constraintMatch.getConstraintName() + " ("
+ constraintMatch.getJustificationList().stream() + constraintMatch.getJustificationList().stream()
.filter(o -> o instanceof Talk).map(o -> ((Talk) o).getCode()) .filter(o -> o instanceof Talk).map(o -> ((Talk) o).getCode())
.collect(joining(", ")) .collect(joining(", "))
+ "): " + constraintMatch.getScore().toShortString()) + "): " + constraintMatch.getScore().toShortString())
.collect(joining("\n")))); .collect(joining("\n "))));
comment.setAuthor("OptaPlanner"); comment.setAuthor("OptaPlanner");
cell.setCellComment(comment); cell.setCellComment(comment);
} }
return cell; cell.setCellValue(talkList.stream().map(stringFunction).collect(joining(", ")));
} }
protected Cell nextCellWithScore(HardSoftScore score, CellStyle cellStyle) {
if (!score.isFeasible()) { protected Cell nextCell() {
return nextCell(hardPenaltyStyle); return nextCell(null);
} else if (score.getSoftScore() < 0) {
return nextCell(softPenaltyStyle);
} else {
return nextCell(cellStyle);
}
} }


protected Cell nextCell(CellStyle cellStyle) { protected Cell nextCell(CellStyle cellStyle) {
Expand Down

0 comments on commit b62909b

Please sign in to comment.