Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update trip#shape_id and frequency stop_times on pattern updates #164

Merged
merged 11 commits into from
Jan 4, 2019

Conversation

landonreed
Copy link
Contributor

@landonreed landonreed commented Dec 18, 2018

In addition to some formatting tweaks and added comments, this seeks to address the underlying cause for ibi-group/datatools-ui#385. It is another example of updates for "exemplar" fields not making their way back to the referencing entities (#109).

It also fixes #165, where stop_time arrivals and departures were not kept in sync with updates to the underlying pattern travel times. This is only a concern with frequency-based patterns, but the same method could potentially be utilized for updating travel times in timetable-based trips if needed in the future.

Finally, it adds some tests to JdbcTableWriter for creating frequency trips and fixes #173, which was discovered in the process of writing these tests.

@codecov-io
Copy link

codecov-io commented Dec 18, 2018

Codecov Report

Merging #164 into dev will increase coverage by 2.96%.
The diff coverage is 66.17%.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev     #164      +/-   ##
============================================
+ Coverage     55.21%   58.17%   +2.96%     
- Complexity      734      827      +93     
============================================
  Files           143      144       +1     
  Lines          7178     7596     +418     
  Branches        830      939     +109     
============================================
+ Hits           3963     4419     +456     
+ Misses         2876     2823      -53     
- Partials        339      354      +15
Impacted Files Coverage Δ Complexity Δ
src/main/java/com/conveyal/gtfs/loader/Table.java 85.22% <ø> (+1.37%) 75 <0> (+1) ⬆️
...a/com/conveyal/gtfs/graphql/GraphQLGtfsSchema.java 98.25% <100%> (ø) 1 <0> (ø) ⬇️
...java/com/conveyal/gtfs/loader/JdbcTableWriter.java 51.45% <65.67%> (+15.69%) 87 <7> (+30) ⬆️
...in/java/com/conveyal/gtfs/validator/Validator.java 68.18% <0%> (-13.64%) 6% <0%> (+2%)
src/main/java/com/conveyal/gtfs/GTFS.java 43.91% <0%> (-2.54%) 20% <0%> (+10%)
...java/com/conveyal/gtfs/error/NewGTFSErrorType.java 100% <0%> (ø) 3% <0%> (+1%) ⬆️
...ava/com/conveyal/gtfs/validator/TripValidator.java 100% <0%> (ø) 2% <0%> (+1%) ⬆️
.../java/com/conveyal/gtfs/loader/SnapshotResult.java 100% <0%> (ø) 1% <0%> (?)
...java/com/conveyal/gtfs/loader/EntityPopulator.java 71.71% <0%> (+0.65%) 18% <0%> (+1%) ⬆️
...ava/com/conveyal/gtfs/loader/JdbcGtfsExporter.java 83.43% <0%> (+1.18%) 23% <0%> (+1%) ⬆️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce68dc6...37fb468. Read the comment docs.

@landonreed landonreed changed the title Update trip#shape_id if pattern value changes Update trip#shape_id and frequency stop_times on pattern updates Dec 18, 2018
tablePrefix,
tablePrefix,
"pattern_id",
"stop_sequence"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are hardcoded strings, they should be included in the base string.

statement.setInt(oneBasedIndex++, arrivalTime + dwellTime);
// Set "where clause" with value for pattern_id and stop_sequence
statement.setString(oneBasedIndex++, patternStop.get("pattern_id").asText());
statement.setInt(oneBasedIndex++, patternStop.get("stop_sequence").asInt());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a variable for the prepared statement variable index seems a little too fancy. Since the variables aren't dynamically created and the length of the parameters isn't varying, I think it may be best to simply hardcode the field position number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems more maintainable and less error-prone to me to use an incrementing variable. As long as the you're setting the parameters in the correct order, adding a new parameter is simply a matter of inserting it in the right spot and using the same oneBasedIndex. If we were to use hardcoded numbers, updating the statement could involve updating multiple numbers one by one if the new parameter is placed anywhere except the end.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I don't have a super strong opinion on this, so go ahead.

Copy link
Contributor

@evansiroky evansiroky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to addressing the other comments, it would be great if this PR included creating a test for CRUD'ing patterns with frequencies in JDBCTableWriterTest.

@evansiroky evansiroky assigned landonreed and unassigned evansiroky Dec 21, 2018
…r trips

This refactor includes a check for Pattern#useFrequency when either a pattern is updated or trips
are updated in order to appropriately trigger other behaviors (for example, keeping stop times in
sync with patter stops travel times or disallowing frequency entries for timetable-based patterns).

fixes #173
@landonreed landonreed removed their assignment Jan 3, 2019
* which is a prerequisite for creating a frequency trip with stop times.
*/
@Test
public void canCreateFrequencyForFrequencyPattern() throws IOException, SQLException, InvalidNamespaceException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start! This should be renamed to indicate that it also does some checking of the updating and deleting of some trips.

Copy link
Contributor

@evansiroky evansiroky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved assuming #164 (comment) is addressed.

@evansiroky evansiroky assigned landonreed and unassigned evansiroky Jan 3, 2019
@landonreed landonreed merged commit 7062076 into dev Jan 4, 2019
@landonreed landonreed deleted the update-trip-shape_id branch January 4, 2019 15:47
@landonreed
Copy link
Contributor Author

🎉 This PR is included in version 4.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants