Skip to content

Commit

Permalink
refactor(st interpolation): Update calculation method, respond to com…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
philip-cline committed Nov 20, 2023
1 parent 8a1fe2a commit 36f3043
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/main/java/com/conveyal/gtfs/loader/JdbcTableWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ public String update(Integer id, String json, boolean autoCommit) throws SQLExce
}
}

/**
* Deprecated method to normalize stop times before stop time interpolation. Defaults to
* false for interpolation.
*/
public int normalizeStopTimesForPattern(int id, int beginWithSequence) throws SQLException {
return normalizeStopTimesForPattern(id, beginWithSequence, false);
}
/**
* For a given pattern id and starting stop sequence (inclusive), normalize all stop times to match the pattern
* stops' travel times.
Expand Down Expand Up @@ -817,6 +824,7 @@ private int updateStopTimesForPatternStops(List<PatternStop> patternStops, boole
for (String tripId : timesForTripIds.keySet()) {
// Initialize travel time with previous stop time value.
int cumulativeTravelTime = timesForTripIds.get(tripId);
int cumulativeInterpolatedTime = cumulativeTravelTime;
int timepointNumber = 0;
double previousShapeDistTraveled = 0; // Used for calculating timepoint speed for interpolation
for (PatternStop patternStop : patternStops) {
Expand All @@ -832,10 +840,19 @@ private int updateStopTimesForPatternStops(List<PatternStop> patternStops, boole
int dwellTime = patternStop.default_dwell_time == Entity.INT_MISSING ? 0 : patternStop.default_dwell_time;
int oneBasedIndex = 1;
// Increase travel time by current pattern stop's travel and dwell times (and set values for update).
cumulativeTravelTime += travelTime;
updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeTravelTime);
cumulativeTravelTime += dwellTime;
updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeTravelTime);
if (!isTimepoint && interpolateStopTimes) {
// We don't want to increment the true cumulative travel time because that adjusts the timepoint
// times later in the pattern.
// TODO? We ignore dwell times in interpolation calculations right now.
cumulativeInterpolatedTime += travelTime;
updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeInterpolatedTime);
updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeInterpolatedTime);
} else {
cumulativeTravelTime += travelTime;
updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeTravelTime);
cumulativeTravelTime += dwellTime;
updateStopTimeStatement.setInt(oneBasedIndex++, cumulativeTravelTime);
}
updateStopTimeStatement.setString(oneBasedIndex++, tripId);
updateStopTimeStatement.setInt(oneBasedIndex++, patternStop.stop_sequence);
stopTimesTracker.addBatch();
Expand Down
12 changes: 10 additions & 2 deletions src/test/java/com/conveyal/gtfs/loader/JDBCTableWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,15 @@ public void canCreateUpdateAndDeleteFrequencyTripForFrequencyPattern() throws IO
));
}

private static String normalizeStopsForPattern(PatternStopDTO[] patternStops, int updatedStopSequence, boolean interpolateStopTimes, int initialTravelTime, int updatedTravelTime, int startTime, String patternId) throws SQLException, InvalidNamespaceException, IOException {
private static String normalizeStopsForPattern(
PatternStopDTO[] patternStops,
int updatedStopSequence,
boolean interpolateStopTimes,
int initialTravelTime,
int updatedTravelTime,
int startTime,
String patternId
) throws SQLException, InvalidNamespaceException, IOException {
final Table tripsTable = Table.TRIPS;

PatternDTO pattern = createRouteAndPattern(newUUID(),
Expand Down Expand Up @@ -875,7 +883,7 @@ private static String normalizeStopsForPattern(PatternStopDTO[] patternStops, in
* Checks that {@link JdbcTableWriter#normalizeStopTimesForPattern(int, int, boolean)} can interpolate stop times between timepoints.
*/
@Test
public void canInterpolatePatternStopTimes() throws IOException, SQLException, InvalidNamespaceException {
private void canInterpolatePatternStopTimes() throws IOException, SQLException, InvalidNamespaceException {
// Parameters are shared with canNormalizePatternStopTimes, but maintained for test flexibility.
int startTime = 6 * 60 * 60; // 6AM
int initialTravelTime = 60; // seconds
Expand Down

0 comments on commit 36f3043

Please sign in to comment.