Add trip handling strategies for MTC feed merge#376
Conversation
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsResult.java
Outdated
Show resolved
Hide resolved
| /** | ||
| * If service_ids and trip_ids in active feed are the same as future feed then the service end date for the | ||
| * merged feed shall match with future feed’s service end date and the service start date for the merged feed | ||
| * should be the merged date. All files from the future feed only shall be used in the merged feed. |
There was a problem hiding this comment.
It is unclear from this comment what "merged date" is. If a reference to either the active or future feed's dates could be made, that would make it explicit.
There was a problem hiding this comment.
It sounds like the "reconciled" start and end date of the entry in the calendar table, but I agree that rewording this term would help.
| /** | ||
| * If service_ids in active and future feed exactly match but only some of the trip_ids match then the merge | ||
| * strategy shall handle the following three cases: | ||
| * - *trip_id in both feeds*: The service shall start from the data merge date and end at the future feed’s service |
There was a problem hiding this comment.
Can you be more explicit on what the data merge date would be here?
| * - *trip_id in past feed*: A new service shall be created starting from the merge date and expiring at the end | ||
| * of active service period. |
There was a problem hiding this comment.
Please clarify what "merge date" is and it'd be good to stick with the same terminology for past/active/future feed. Past is always active, right?
src/main/java/com/conveyal/datatools/manager/jobs/MergeStrategy.java
Outdated
Show resolved
Hide resolved
| CsvReader csvReader = table.getCsvReader(zipFile, null); | ||
| if (csvReader == null) { | ||
| LOG.warn("Table {} not found in zip file: {}", table.name, zipFile.getName()); | ||
| return ids; | ||
| } | ||
| Field[] fieldsFoundInZip = table.getFieldsFromFieldHeaders(csvReader.getHeaders(), null); | ||
| // Get the key field (id value) for each row. | ||
| int keyFieldIndex = getFieldIndex(fieldsFoundInZip, keyField); | ||
| while (csvReader.readRecord()) ids.add(csvReader.get(keyFieldIndex)); | ||
| csvReader.close(); |
There was a problem hiding this comment.
Please ensure this CsvReader is always closed. Maybe use a try-with-resources block.
There was a problem hiding this comment.
I don't think try with resources can be used because the class does not implement AutoCloseable. Are there scenarios you've seen where this is not getting closed?
There was a problem hiding this comment.
If there's any exception that occurs before the reader is closed, then the reader will be left open. You're right about CsvReader not implementing Closeable, so better wrap all this with try-finally.
There was a problem hiding this comment.
Looks like this still needs to be implemented.
src/main/java/com/conveyal/datatools/manager/utils/MergeFeedUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/utils/MergeFeedUtils.java
Outdated
Show resolved
Hide resolved
| ); | ||
| } | ||
|
|
||
| // /** |
There was a problem hiding this comment.
Can you add a comment for why there is a big comment block here?
| pastServiceIds.addAll(currentFeed.idsForTable.get(Table.CALENDAR)); | ||
| pastServiceIds.addAll(currentFeed.idsForTable.get(Table.CALENDAR_DATES)); |
There was a problem hiding this comment.
Is it past or current. It'd be really helpful to pick one thing to call this thing to avoid confusion.
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
binh-dam-ibigroup
left a comment
There was a problem hiding this comment.
Please see the formatting and refactoring suggestions for now.
| /** | ||
| * If service_ids and trip_ids in active feed are the same as future feed then the service end date for the | ||
| * merged feed shall match with future feed’s service end date and the service start date for the merged feed | ||
| * should be the merged date. All files from the future feed only shall be used in the merged feed. |
There was a problem hiding this comment.
It sounds like the "reconciled" start and end date of the entry in the calendar table, but I agree that rewording this term would help.
| Field[] fieldsFoundInZip = table.getFieldsFromFieldHeaders(csvReader.getHeaders(), null); | ||
| // Get the key field (id value) for each row. | ||
| int keyFieldIndex = getFieldIndex(fieldsFoundInZip, keyField); | ||
| while (csvReader.readRecord()) ids.add(csvReader.get(keyFieldIndex)); |
There was a problem hiding this comment.
Put the body of the while loop on a separate line and in brackets, please.
src/main/java/com/conveyal/datatools/manager/utils/MergeFeedUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
src/test/java/com/conveyal/datatools/manager/jobs/MergeFeedsJobTest.java
Show resolved
Hide resolved
src/test/java/com/conveyal/datatools/manager/jobs/MergeFeedsJobTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/conveyal/datatools/manager/jobs/MergeFeedsJobTest.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
src/main/java/com/conveyal/datatools/manager/jobs/MergeFeedsJob.java
Outdated
Show resolved
Hide resolved
evansiroky
left a comment
There was a problem hiding this comment.
This MergeFeedsJob is becoming really complex to the point where it's kind of unclear what all is going on without doing a deep dive into it. To help with this, each step should be thoroughly commented and also, I think it'd really help to have consistent terminology about what past/current/future feeds are.
…alendar_attributes.
…tial table write.
binh-dam-ibigroup
left a comment
There was a problem hiding this comment.
Approving following client approval.
Checklist
devbefore they can be merged tomaster)Description
This PR implements changes to MTC's service period merge feature as defined here: https://docs.google.com/document/d/1mx9s3XfWfPB7SSXDwCbnRF7F2zLDU2ED4gK-W6eXL9o/edit
This PR also fixes #244.
Notable changes include:
FeedToMergeclass and util methods) to new files to clean things up.MergeStrategyenum to mimic strategies in google doc.StopTime#hashCodemethod.