Skip to content

Commit

Permalink
conf scheduling: filter constraints + add languages view
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Mar 6, 2018
1 parent ab54c0f commit d262316
Showing 1 changed file with 64 additions and 14 deletions.
Expand Up @@ -883,6 +883,7 @@ public Workbook write() {
writeAudienceTypesView(); writeAudienceTypesView();
writeAudienceLevelsView(); writeAudienceLevelsView();
writeContentsView(); writeContentsView();
writeLanguagesView();
writeScoreView(); writeScoreView();
return workbook; return workbook;
} }
Expand Down Expand Up @@ -1226,6 +1227,12 @@ private void writeRoomsView() {


private void writeSpeakersView() { private void writeSpeakersView() {
nextSheet("Speakers view", 1, 2, true); nextSheet("Speakers view", 1, 2, true);
String[] filteredConstraintNames = {
SPEAKER_UNAVAILABLE_TIMESLOT, SPEAKER_CONFLICT,
SPEAKER_REQUIRED_TIMESLOT_TAG, SPEAKER_PROHIBITED_TIMESLOT_TAG,
SPEAKER_PREFERRED_TIMESLOT_TAG, SPEAKER_UNDESIRED_TIMESLOT_TAG,
SPEAKER_REQUIRED_ROOM_TAG, SPEAKER_PROHIBITED_ROOM_TAG,
SPEAKER_PREFERRED_ROOM_TAG, SPEAKER_UNDESIRED_ROOM_TAG};
nextRow(); nextRow();
nextHeaderCell(""); nextHeaderCell("");
writeTimeslotDaysHeaders(); writeTimeslotDaysHeaders();
Expand All @@ -1242,14 +1249,15 @@ private void writeSpeakersView() {
List<Talk> talkList = timeslotTalkList.stream() List<Talk> talkList = timeslotTalkList.stream()
.filter(talk -> talk.getTimeslot() == timeslot).collect(toList()); .filter(talk -> talk.getTimeslot() == timeslot).collect(toList());
boolean unavailable = speaker.getUnavailableTimeslotSet().contains(timeslot); boolean unavailable = speaker.getUnavailableTimeslotSet().contains(timeslot);
nextTalkListCell(unavailable, talkList); nextTalkListCell(unavailable, talkList, filteredConstraintNames);
} }
} }
autoSizeColumnsWithHeader(); autoSizeColumnsWithHeader();
} }


private void writeThemeTracksView() { private void writeThemeTracksView() {
nextSheet("Theme tracks view", 1, 2, true); nextSheet("Theme tracks view", 1, 2, true);
String[] filteredConstraintNames = {THEME_TRACK_CONFLICT, AUDIENCE_TYPE_THEME_TRACK_CONFLICT};
nextRow(); nextRow();
nextHeaderCell(""); nextHeaderCell("");
writeTimeslotDaysHeaders(); writeTimeslotDaysHeaders();
Expand All @@ -1268,14 +1276,15 @@ private void writeThemeTracksView() {
Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue(); Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue();
for (Timeslot timeslot : solution.getTimeslotList()) { for (Timeslot timeslot : solution.getTimeslotList()) {
List<Talk> talkList = timeslotToTalkListMap.get(timeslot); List<Talk> talkList = timeslotToTalkListMap.get(timeslot);
nextTalkListCell(talkList); nextTalkListCell(talkList, filteredConstraintNames);
} }
} }
autoSizeColumnsWithHeader(); autoSizeColumnsWithHeader();
} }


private void writeSectorsView() { private void writeSectorsView() {
nextSheet("Sectors view", 1, 2, true); nextSheet("Sectors view", 1, 2, true);
String[] filteredConstraintNames = {SECTOR_CONFLICT};
nextRow(); nextRow();
nextHeaderCell(""); nextHeaderCell("");
writeTimeslotDaysHeaders(); writeTimeslotDaysHeaders();
Expand All @@ -1294,14 +1303,15 @@ private void writeSectorsView() {
Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue(); Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue();
for (Timeslot timeslot : solution.getTimeslotList()) { for (Timeslot timeslot : solution.getTimeslotList()) {
List<Talk> talkList = timeslotToTalkListMap.get(timeslot); List<Talk> talkList = timeslotToTalkListMap.get(timeslot);
nextTalkListCell(talkList); nextTalkListCell(talkList, filteredConstraintNames);
} }
} }
autoSizeColumnsWithHeader(); autoSizeColumnsWithHeader();
} }


private void writeAudienceTypesView() { private void writeAudienceTypesView() {
nextSheet("Audience types view", 1, 2, true); nextSheet("Audience types view", 1, 2, true);
String[] filteredConstraintNames = {AUDIENCE_TYPE_DIVERSITY, AUDIENCE_TYPE_THEME_TRACK_CONFLICT};
nextRow(); nextRow();
nextHeaderCell(""); nextHeaderCell("");
writeTimeslotDaysHeaders(); writeTimeslotDaysHeaders();
Expand All @@ -1320,39 +1330,41 @@ private void writeAudienceTypesView() {
Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue(); Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue();
for (Timeslot timeslot : solution.getTimeslotList()) { for (Timeslot timeslot : solution.getTimeslotList()) {
List<Talk> talkList = timeslotToTalkListMap.get(timeslot); List<Talk> talkList = timeslotToTalkListMap.get(timeslot);
nextTalkListCell(talkList); nextTalkListCell(talkList, filteredConstraintNames);
} }
} }
autoSizeColumnsWithHeader(); autoSizeColumnsWithHeader();
} }


private void writeAudienceLevelsView() { private void writeAudienceLevelsView() {
nextSheet("Audience levels view", 1, 2, true); nextSheet("Audience levels view", 1, 2, true);
String[] filteredConstraintNames = {AUDIENCE_LEVEL_DIVERSITY, AUDIENCE_LEVEL_FLOW_PER_CONTENT_VIOLATION};
nextRow(); nextRow();
nextHeaderCell(""); nextHeaderCell("");
writeTimeslotDaysHeaders(); writeTimeslotDaysHeaders();
nextRow(); nextRow();
nextHeaderCell("Audience level"); nextHeaderCell("Audience level");
writeTimeslotHoursHeaders(); writeTimeslotHoursHeaders();


Map<Integer, Map<Timeslot, List<Talk>>> tagToTimeslotToTalkListMap = solution.getTalkList().stream() Map<Integer, Map<Timeslot, List<Talk>>> levelToTimeslotToTalkListMap = solution.getTalkList().stream()
.filter(talk -> talk.getTimeslot() != null) .filter(talk -> talk.getTimeslot() != null)
.map(talk -> Pair.of(talk.getAudienceLevel(), Pair.of(talk.getTimeslot(), talk))) .map(talk -> Pair.of(talk.getAudienceLevel(), Pair.of(talk.getTimeslot(), talk)))
.collect(groupingBy(Pair::getLeft, groupingBy(o -> o.getRight().getLeft(), mapping(o -> o.getRight().getRight(), toList())))); .collect(groupingBy(Pair::getLeft, groupingBy(o -> o.getRight().getLeft(), mapping(o -> o.getRight().getRight(), toList()))));
for (Map.Entry<Integer, Map<Timeslot, List<Talk>>> entry : tagToTimeslotToTalkListMap.entrySet()) { for (Map.Entry<Integer, Map<Timeslot, List<Talk>>> entry : levelToTimeslotToTalkListMap.entrySet()) {
nextRow(); nextRow();
nextHeaderCell(Integer.toString(entry.getKey())); nextHeaderCell(Integer.toString(entry.getKey()));
Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue(); Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue();
for (Timeslot timeslot : solution.getTimeslotList()) { for (Timeslot timeslot : solution.getTimeslotList()) {
List<Talk> talkList = timeslotToTalkListMap.get(timeslot); List<Talk> talkList = timeslotToTalkListMap.get(timeslot);
nextTalkListCell(talkList); nextTalkListCell(talkList, filteredConstraintNames);
} }
} }
autoSizeColumnsWithHeader(); autoSizeColumnsWithHeader();
} }


private void writeContentsView() { private void writeContentsView() {
nextSheet("Contents view", 1, 2, true); nextSheet("Contents view", 1, 2, true);
String[] filteredConstraintNames = {AUDIENCE_LEVEL_FLOW_PER_CONTENT_VIOLATION, CONTENT_CONFLICT};
nextRow(); nextRow();
nextHeaderCell(""); nextHeaderCell("");
writeTimeslotDaysHeaders(); writeTimeslotDaysHeaders();
Expand All @@ -1372,7 +1384,34 @@ private void writeContentsView() {
for (Timeslot timeslot : solution.getTimeslotList()) { for (Timeslot timeslot : solution.getTimeslotList()) {
List<Talk> talkList = timeslotToTalkListMap.get(timeslot); List<Talk> talkList = timeslotToTalkListMap.get(timeslot);
nextTalkListCell(talkList, nextTalkListCell(talkList,
talk -> talk.getCode() + " (level " + talk.getAudienceLevel() + ")"); talk -> talk.getCode() + " (level " + talk.getAudienceLevel() + ")",
filteredConstraintNames);
}
}
autoSizeColumnsWithHeader();
}

private void writeLanguagesView() {
nextSheet("Languages view", 1, 2, true);
String[] filteredConstraintNames = {LANGUAGE_DIVERSITY};
nextRow();
nextHeaderCell("");
writeTimeslotDaysHeaders();
nextRow();
nextHeaderCell("Language");
writeTimeslotHoursHeaders();

Map<String, Map<Timeslot, List<Talk>>> languageToTimeslotToTalkListMap = solution.getTalkList().stream()
.filter(talk -> talk.getTimeslot() != null)
.map(talk -> Pair.of(talk.getLanguage(), Pair.of(talk.getTimeslot(), talk)))
.collect(groupingBy(Pair::getLeft, groupingBy(o -> o.getRight().getLeft(), mapping(o -> o.getRight().getRight(), toList()))));
for (Map.Entry<String, Map<Timeslot, List<Talk>>> entry : languageToTimeslotToTalkListMap.entrySet()) {
nextRow();
nextHeaderCell(entry.getKey());
Map<Timeslot, List<Talk>> timeslotToTalkListMap = entry.getValue();
for (Timeslot timeslot : solution.getTimeslotList()) {
List<Talk> talkList = timeslotToTalkListMap.get(timeslot);
nextTalkListCell(talkList, filteredConstraintNames);
} }
} }
autoSizeColumnsWithHeader(); autoSizeColumnsWithHeader();
Expand Down Expand Up @@ -1459,26 +1498,37 @@ protected void nextHeaderCell(String value) {
headerCellCount++; headerCellCount++;
} }


protected void nextTalkListCell(List<Talk> talkList) { protected void nextTalkListCell(List<Talk> talkList, String[] filteredConstraintNames) {
nextTalkListCell(false, talkList); nextTalkListCell(false, talkList, filteredConstraintNames);
} }


protected void nextTalkListCell(boolean unavailable, List<Talk> talkList) { protected void nextTalkListCell(boolean unavailable, List<Talk> talkList, String[] filteredConstraintNames) {
nextTalkListCell(unavailable, talkList, nextTalkListCell(unavailable, talkList,
talk -> talk.getCode() + " @ " + (talk.getRoom() == null ? "No room" : talk.getRoom().getName())); talk -> talk.getCode() + " @ " + (talk.getRoom() == null ? "No room" : talk.getRoom().getName()),
filteredConstraintNames);
} }


protected void nextTalkListCell(List<Talk> talkList, Function<Talk, String> stringFunction) { protected void nextTalkListCell(List<Talk> talkList, Function<Talk, String> stringFunction, String[] filteredConstraintNames) {
nextTalkListCell(false, talkList, stringFunction); nextTalkListCell(false, talkList, stringFunction, filteredConstraintNames);
} }


protected void nextTalkListCell(boolean unavailable, List<Talk> talkList, Function<Talk, String> stringFunction) { protected void nextTalkListCell(boolean unavailable, List<Talk> talkList, Function<Talk, String> stringFunction) {
nextTalkListCell(unavailable, talkList, stringFunction, null);
}

protected void nextTalkListCell(boolean unavailable, List<Talk> talkList, Function<Talk, String> stringFunction,
String[] filteredConstraintNames) {
List<String> filteredConstraintNameList = (filteredConstraintNames == null) ? null
: Arrays.asList(filteredConstraintNames);
if (talkList == null) { if (talkList == null) {
talkList = Collections.emptyList(); talkList = Collections.emptyList();
} }
HardSoftScore score = talkList.stream() HardSoftScore score = talkList.stream()
.map(indictmentMap::get).filter(Objects::nonNull) .map(indictmentMap::get).filter(Objects::nonNull)
.flatMap(indictment -> indictment.getConstraintMatchSet().stream()) .flatMap(indictment -> indictment.getConstraintMatchSet().stream())
// Filter out filtered constraints
.filter(constraintMatch -> filteredConstraintNameList == null
|| filteredConstraintNameList.contains(constraintMatch.getConstraintName()))
.map(constraintMatch -> (HardSoftScore) constraintMatch.getScore()) .map(constraintMatch -> (HardSoftScore) constraintMatch.getScore())
// Filter out positive constraints // Filter out positive constraints
.filter(indictmentScore -> !(indictmentScore.getHardScore() >= 0 && indictmentScore.getSoftScore() >= 0)) .filter(indictmentScore -> !(indictmentScore.getHardScore() >= 0 && indictmentScore.getSoftScore() >= 0))
Expand Down

0 comments on commit d262316

Please sign in to comment.