Skip to content

Commit

Permalink
refactor(JdbcGtfsExporter.java): Reinstated merged updates which were…
Browse files Browse the repository at this point in the history
… previously removed
  • Loading branch information
Robin Beer authored and Robin Beer committed Jul 14, 2023
1 parent 073924b commit 890bb29
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main/java/com/conveyal/gtfs/loader/JdbcGtfsExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

Expand Down Expand Up @@ -74,6 +75,17 @@ public JdbcGtfsExporter(String feedId, String outFile, DataSource dataSource, bo
this.fromEditor = fromEditor;
}

/**
* Utility method to check if an exception uses a specific service.
*/
public Boolean exceptionInvolvesService(ScheduleException ex, String serviceId) {
return (
ex.addedService.contains(serviceId) ||
ex.removedService.contains(serviceId) ||
ex.customSchedule.contains(serviceId)
);
}

/**
* Export primary entity tables as well as Pattern and PatternStops tables.
*
Expand Down Expand Up @@ -145,7 +157,10 @@ public FeedLoadResult exportTables() {
for (Calendar cal : calendars) {
Service service = new Service(cal.service_id);
service.calendar = cal;
for (ScheduleException ex : exceptions) {
for (ScheduleException ex : exceptions.stream()
.filter(ex -> exceptionInvolvesService(ex, cal.service_id))
.collect(Collectors.toList())
) {
if (ex.exemplar.equals(ScheduleException.ExemplarServiceDescriptor.SWAP) &&
(!ex.addedService.contains(cal.service_id) && !ex.removedService.contains(cal.service_id))) {
// Skip swap exception if cal is not referenced by added or removed service.
Expand All @@ -163,7 +178,7 @@ public FeedLoadResult exportTables() {
calendarDate.date = date;
calendarDate.service_id = cal.service_id;
calendarDate.exception_type = ex.serviceRunsOn(cal) ? 1 : 2;
LOG.info("Adding exception {} (type={}) for calendar {} on date {}", ex.name, calendarDate.exception_type, cal.service_id, date.toString());
LOG.info("Adding exception {} (type={}) for calendar {} on date {}", ex.name, calendarDate.exception_type, cal.service_id, date);

if (service.calendar_dates.containsKey(date))
throw new IllegalArgumentException("Duplicate schedule exceptions on " + date.toString());
Expand Down

0 comments on commit 890bb29

Please sign in to comment.