From 017426ce857b62249a1ddb069ff079bee0e83add Mon Sep 17 00:00:00 2001 From: Zack Beach Date: Sun, 7 Jun 2020 17:53:34 -0400 Subject: [PATCH] Update for new shift change times --- src/main/java/main/CSVReader.java | 14 +++++++++--- src/main/java/main/Runsheet.java | 4 ++-- src/main/java/main/Schedule.java | 37 +++++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/main/java/main/CSVReader.java b/src/main/java/main/CSVReader.java index b7317b8..c70f124 100644 --- a/src/main/java/main/CSVReader.java +++ b/src/main/java/main/CSVReader.java @@ -200,11 +200,19 @@ public static ShiftChange[] getPossibleShiftChangesOnDate(Date date) { for (int i = 1; i < CSVReader.csvRecords.size(); i++) { CSVRecord csvRecord = CSVReader.csvRecords.get(i); try { + ShiftChange possibleShiftChange = new ShiftChange( + (new TimePoint(csvRecord.get(Header.START_TIME))).hour, + 10, + (new TimePoint(csvRecord.get(Header.START_TIME))).hour, + 50, + null + ); if (new Date(csvRecord.get(Header.DATE)).equals(date) && CSVReader.recordDescribesRouteDrivingShift(csvRecord) - && !shiftChanges.contains( - new ShiftChange(new TimePoint(csvRecord.get(Header.START_TIME)), null))) - shiftChanges.add(new ShiftChange(new TimePoint(csvRecord.get(Header.START_TIME)), null)); + && !shiftChanges.contains(possibleShiftChange) + ) { + shiftChanges.add(possibleShiftChange); + } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/main/java/main/Runsheet.java b/src/main/java/main/Runsheet.java index 16e3cf8..384d607 100644 --- a/src/main/java/main/Runsheet.java +++ b/src/main/java/main/Runsheet.java @@ -470,7 +470,7 @@ private int writeShiftChangeRow(int row, ShiftChange shiftChange) { * @return true if the provided hour is the hour of one of the shift changes, or false otherwise */ private static boolean hourIsInShiftChanges(int hour, ArrayList shiftChanges) { - for (int i = 0; i < shiftChanges.size(); i++) if (shiftChanges.get(i).hour == hour) return true; + for (int i = 0; i < shiftChanges.size(); i++) if (shiftChanges.get(i).startTime.hour == hour) return true; return false; } @@ -483,7 +483,7 @@ private static boolean hourIsInShiftChanges(int hour, ArrayList shi */ private static ShiftChange shiftChangeAtHour(int hour, ArrayList shiftChanges) { for (int i = 0; i < shiftChanges.size(); i++) - if (shiftChanges.get(i).hour == hour) return shiftChanges.get(i); + if (shiftChanges.get(i).startTime.hour == hour) return shiftChanges.get(i); return null; } diff --git a/src/main/java/main/Schedule.java b/src/main/java/main/Schedule.java index 76c12ff..1a885d4 100644 --- a/src/main/java/main/Schedule.java +++ b/src/main/java/main/Schedule.java @@ -175,13 +175,13 @@ private ArrayList shiftChanges(ShiftChange firstShiftChange) { if (this.routeDrivingShifts.size() == 0) return shiftChanges; else if (this.routeDrivingShifts.size() == 1) { - if (this.routeDrivingShifts.get(0).time.start.hour >= firstShiftChange.hour) + if (this.routeDrivingShifts.get(0).time.start.hour >= firstShiftChange.startTime.hour) shiftChanges.add( new ShiftChange( this.routeDrivingShifts.get(0).time.start.hour, new ShiftChangeID(this.routeDrivingShifts.get(0).period, 1))); } else { // this.routeDrivingShifts.size() > 1 - if (this.routeDrivingShifts.get(0).time.start.hour >= firstShiftChange.hour) + if (this.routeDrivingShifts.get(0).time.start.hour >= firstShiftChange.startTime.hour) // Add first shift change shiftChanges.add( new ShiftChange( @@ -193,7 +193,7 @@ else if (this.routeDrivingShifts.size() == 1) { char currentPeriod = this.routeDrivingShifts.get(0).period; for (int i = 1; i < this.routeDrivingShifts.size(); i++) { - if (this.routeDrivingShifts.get(i).time.start.hour == firstShiftChange.hour + if (this.routeDrivingShifts.get(i).time.start.hour == firstShiftChange.startTime.hour && this.routeDrivingShifts.get(i).time.start.hour != this.routeDrivingShifts.get(i - 1).time.start.hour) { currentPeriod = this.routeDrivingShifts.get(i).period; @@ -201,19 +201,38 @@ else if (this.routeDrivingShifts.size() == 1) { new ShiftChange( this.routeDrivingShifts.get(i).time.start.hour, new ShiftChangeID(this.routeDrivingShifts.get(i).period, 1))); - } else if (this.routeDrivingShifts.get(i).time.start.hour > firstShiftChange.hour) { + } else if (this.routeDrivingShifts.get(i).time.start.hour > firstShiftChange.startTime.hour) { if (this.routeDrivingShifts.get(i).time.start.hour > this.routeDrivingShifts.get(i - 1).time.start.hour) { - if (this.routeDrivingShifts.get(i).period == currentPeriod) nthShiftChangeInPeriod++; + if (this.routeDrivingShifts.get(i).period == currentPeriod) { + nthShiftChangeInPeriod++; + } else { currentPeriod = this.routeDrivingShifts.get(i).period; nthShiftChangeInPeriod = 1; } - shiftChanges.add( + // Default behavior + if (this.routeDrivingShifts.get(i).route.id != 35) { + shiftChanges.add( + new ShiftChange( + this.routeDrivingShifts.get(i).time.start.hour, + new ShiftChangeID( + this.routeDrivingShifts.get(i).period, nthShiftChangeInPeriod))); + } + // 35 route exception + else { + shiftChanges.add( new ShiftChange( - this.routeDrivingShifts.get(i).time.start.hour, - new ShiftChangeID( - this.routeDrivingShifts.get(i).period, nthShiftChangeInPeriod))); + this.routeDrivingShifts.get(i).time.start.hour, + 00, + this.routeDrivingShifts.get(i).time.start.hour, + 10, + new ShiftChangeID( + this.routeDrivingShifts.get(i).period, nthShiftChangeInPeriod + ) + ) + ); + } } } }