Skip to content

Commit

Permalink
refactor(JdbcGtfsExporter.java): Update to tie exceptions to a calend…
Browse files Browse the repository at this point in the history
…ar based on service id
  • Loading branch information
Robin Beer authored and Robin Beer committed Jul 7, 2023
1 parent ba747df commit 59b568a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/conveyal/gtfs/loader/JdbcGtfsExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

Expand Down Expand Up @@ -163,7 +164,12 @@ public FeedLoadResult exportTables() {
for (Calendar cal : calendars) {
Service service = new Service(cal.service_id);
service.calendar = cal;
for (ScheduleException ex : calendarExceptions) {
List<ScheduleException> exceptionsForCalendar = calendarExceptions.stream().filter(ex ->
ex.addedService.contains(cal.service_id) ||
ex.removedService.contains(cal.service_id) ||
ex.customSchedule.contains(cal.service_id)
).collect(Collectors.toList());
for (ScheduleException ex : exceptionsForCalendar) {

for (LocalDate date : ex.dates) {
if (date.isBefore(cal.start_date) || date.isAfter(cal.end_date)) {
Expand All @@ -175,7 +181,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);
Expand Down

0 comments on commit 59b568a

Please sign in to comment.