Skip to content

Commit

Permalink
Update for new shift change times
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeach committed Jun 7, 2020
1 parent 9ee5c17 commit 017426c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
14 changes: 11 additions & 3 deletions src/main/java/main/CSVReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/main/Runsheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShiftChange> 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;
}

Expand All @@ -483,7 +483,7 @@ private static boolean hourIsInShiftChanges(int hour, ArrayList<ShiftChange> shi
*/
private static ShiftChange shiftChangeAtHour(int hour, ArrayList<ShiftChange> 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;
}

Expand Down
37 changes: 28 additions & 9 deletions src/main/java/main/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ private ArrayList<ShiftChange> 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(
Expand All @@ -193,27 +193,46 @@ 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;
shiftChanges.add(
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
)
)
);
}
}
}
}
Expand Down

0 comments on commit 017426c

Please sign in to comment.