Skip to content

Commit

Permalink
Merge pull request #387 from conveyal/allow-exception-range-overlap
Browse files Browse the repository at this point in the history
Allow exception overlap
  • Loading branch information
philip-cline authored Jul 13, 2023
2 parents f2ceb59 + e51456e commit b0b94e4
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 @@ -30,6 +30,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 @@ -67,6 +68,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 @@ -135,7 +147,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 @@ -153,7 +168,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 b0b94e4

Please sign in to comment.