Skip to content

Commit

Permalink
Merge pull request #322 from conveyal/gtfs-spec-updates-qbd
Browse files Browse the repository at this point in the history
Add stop_times linked fields continuous_pickup, continuous_drop_off.
  • Loading branch information
Robin Beer committed Jul 21, 2021
2 parents 0864f82 + ab6dfe7 commit a45e6f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/conveyal/gtfs/loader/JdbcTableWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ private String updateChildTable(
"timepoint",
"drop_off_type",
"pickup_type",
"continuous_pickup",
"continuous_drop_off",
"shape_dist_traveled"
);
}
Expand Down
38 changes: 32 additions & 6 deletions src/test/java/com/conveyal/gtfs/loader/JDBCTableWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,19 @@ public void canCreateUpdateAndDeleteScheduleExceptions() throws IOException, SQL
}

/**
* This test verifies that stop_times#shape_dist_traveled (and other "linked fields") are updated when a pattern
* This test verifies that stop_times#shape_dist_traveled and other linked fields are updated when a pattern
* is updated.
*/
@Test
public void shouldUpdateStopTimeShapeDistTraveledOnPatternStopUpdate() throws IOException, SQLException, InvalidNamespaceException {
public void shouldUpdateStopTimeOnPatternStopUpdate() throws IOException, SQLException, InvalidNamespaceException {
final String[] STOP_TIMES_LINKED_FIELDS = new String[] {
"shape_dist_traveled",
"timepoint",
"drop_off_type",
"pickup_type",
"continuous_pickup",
"continuous_drop_off"
};
String routeId = newUUID();
String patternId = newUUID();
int startTime = 6 * 60 * 60; // 6 AM
Expand Down Expand Up @@ -459,10 +467,12 @@ public void shouldUpdateStopTimeShapeDistTraveledOnPatternStopUpdate() throws IO
assertNotNull(uuid);
// Check that trip exists.
assertThatSqlQueryYieldsRowCount(getColumnsForId(createdTrip.id, Table.TRIPS), 1);
// Check the stop_time's initial shape_dist_traveled value. TODO test that other linked fields are updated?

// Check the stop_time's initial shape_dist_traveled value and other linked fields.
PreparedStatement statement = testDataSource.getConnection().prepareStatement(
String.format(
"select shape_dist_traveled from %s.stop_times where stop_sequence=1 and trip_id='%s'",
"select %s from %s.stop_times where stop_sequence=1 and trip_id='%s'",
String.join(", ", STOP_TIMES_LINKED_FIELDS),
testNamespace,
createdTrip.trip_id
)
Expand All @@ -471,18 +481,34 @@ public void shouldUpdateStopTimeShapeDistTraveledOnPatternStopUpdate() throws IO
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
// First stop_time shape_dist_traveled should be zero.
assertThat(resultSet.getInt(1), equalTo(0));
// Other linked fields should be interpreted as zero too.
for (int i = 1; i <= STOP_TIMES_LINKED_FIELDS.length; i++) {
assertThat(resultSet.getInt(i), equalTo(0));
}
}

// Update pattern_stop#shape_dist_traveled and check that the stop_time's shape_dist value is updated.
final double updatedShapeDistTraveled = 45.5;
pattern.pattern_stops[1].shape_dist_traveled = updatedShapeDistTraveled;
PatternStopDTO pattern_stop = pattern.pattern_stops[1];
pattern_stop.shape_dist_traveled = updatedShapeDistTraveled;
// Assign an arbitrary value (the order of appearance in STOP_TIMES_LINKED_FIELDS) for the other linked fields.
pattern_stop.timepoint = 2;
pattern_stop.drop_off_type = 3;
pattern_stop.pickup_type = 4;
pattern_stop.continuous_pickup = 5;
pattern_stop.continuous_drop_off = 6;
JdbcTableWriter patternUpdater = createTestTableWriter(Table.PATTERNS);
String updatedPatternOutput = patternUpdater.update(pattern.id, mapper.writeValueAsString(pattern), true);
LOG.info("Updated pattern: {}", updatedPatternOutput);
ResultSet resultSet2 = statement.executeQuery();
while (resultSet2.next()) {
// First stop_time shape_dist_traveled should be updated.
assertThat(resultSet2.getDouble(1), equalTo(updatedShapeDistTraveled));

// Other linked fields should be as set above.
for (int i = 2; i <= STOP_TIMES_LINKED_FIELDS.length; i++) {
assertThat(resultSet2.getInt(i), equalTo(i));
}
}
}

Expand Down

0 comments on commit a45e6f9

Please sign in to comment.