Skip to content

Commit

Permalink
Merge pull request #11 from radford-transit/change-shift-change-time
Browse files Browse the repository at this point in the history
Change shift change time
  • Loading branch information
zbeach authored Jun 7, 2020
2 parents bc1c1ea + 017426c commit 4ae0156
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 28 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
53 changes: 39 additions & 14 deletions src/main/java/main/ShiftChange.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,81 @@
package main;

public class ShiftChange implements Comparable {
/** Hour of the shift change */
public int hour;
/** Start time of the shift change */
public TimePoint startTime;
/** End time of the shift change */
public TimePoint endTime;
/** ID of the shift change */
public ShiftChangeID id;

/**
* Constructs a ShiftChange object
*
* @param hour The hour of the shift change
* @param startTime The start time of the shift change
* @param endTime The end time of the shift change
* @param id The ShiftChangeID to assign to the shift change
*/
public ShiftChange(int hour, ShiftChangeID id) {
this.hour = hour;
public ShiftChange(TimePoint startTime, TimePoint endTime, ShiftChangeID id) {
this.startTime = startTime;
this.endTime = endTime;
this.id = id;
}

/**
* Constructs a ShiftChange object
*
* @param startHour The start hour of the shift change
* @param startMinute The start minute of the shift change
* @param endHour The end hour of the shift change
* @param endMinute The end minute of the shift change
* @param id The ShiftChangeID to assign to the shift change
*/
public ShiftChange(int startHour, int startMinute, int endHour, int endMinute, ShiftChangeID id) {
this(new TimePoint(startHour, startMinute), new TimePoint(endHour, endMinute), id);
}

/**
* Constructs a ShiftChange object
*
* @param time The time of the shift change
* @param id The ShiftChangeID to assign to the shift change
*/
public ShiftChange(TimePoint time, ShiftChangeID id) {
this.hour = time.hour;
this.id = id;
this(time, new TimePoint(time.hour, 50), id);
}

/**
* Constructs a ShiftChange object
*
* @param hour The hour of the shift change
* @param id The ShiftChangeID to assign to the shift change
*/
public ShiftChange(int hour, ShiftChangeID id) {
this(new TimePoint(hour, 10), id);
}

/** {@inheritDoc} */
@Override
public String toString() {
return new TimePoint(this.hour, 15).toString()
+ " - "
+ new TimePoint(this.hour + 1, 0).toString();
return startTime.toString() + " - " + endTime.toString();
}

/** {@inheritDoc} */
@Override
public int compareTo(Object other) {
if (other instanceof ShiftChange)
return (this.hour < ((ShiftChange) other).hour
? -1
: this.hour == ((ShiftChange) other).hour ? 0 : 1);
return this.startTime.compareTo(((ShiftChange) other).startTime);
return -2;
}

/** {@inheritDoc} */
@Override
public boolean equals(Object other) {
if (other instanceof ShiftChange)
return this.hour == ((ShiftChange) other).hour && this.id == ((ShiftChange) other).id;
return this.startTime.equals(((ShiftChange) other).startTime)
&& this.endTime.equals(((ShiftChange) other).endTime)
&& this.id == ((ShiftChange) other).id
;
return false;
}
}
9 changes: 9 additions & 0 deletions src/main/java/main/TimePoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@ public int compareTo(TimePoint other) {
? (this.minute < other.minute) ? -1 : (this.minute == other.minute) ? 0 : 1
: 1);
}

/** {@inheritDoc} */
@Override
public boolean equals(Object other) {
return
this.hour == ((TimePoint) other).hour
&& this.minute == ((TimePoint) other).minute
;
}
}

0 comments on commit 4ae0156

Please sign in to comment.