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

Mixed calendar definition fix ltr #288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/main/java/com/conveyal/gtfs/loader/JdbcGtfsSnapshotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private TableLoadResult createScheduleExceptionsTable() {
Iterable<CalendarDate> calendarDates = calendarDatesReader.getAll();

// Keep track of calendars by service id in case we need to add dummy calendar entries.
Map<String, Calendar> calendarsByServiceId = new HashMap<>();
Map<String, Calendar> dummyCalendarsByServiceId = new HashMap<>();

// Iterate through calendar dates to build up to get maps from exceptions to their dates.
Multimap<String, String> removedServiceForDate = HashMultimap.create();
Expand All @@ -243,15 +243,15 @@ private TableLoadResult createScheduleExceptionsTable() {
addedServiceForDate.put(date, calendarDate.service_id);
// create (if needed) and extend range of dummy calendar that would need to be created if we are
// copying from a feed that doesn't have the calendar.txt file
Calendar calendar = calendarsByServiceId.getOrDefault(calendarDate.service_id, new Calendar());
Calendar calendar = dummyCalendarsByServiceId.getOrDefault(calendarDate.service_id, new Calendar());
calendar.service_id = calendarDate.service_id;
if (calendar.start_date == null || calendar.start_date.isAfter(calendarDate.date)) {
calendar.start_date = calendarDate.date;
}
if (calendar.end_date == null || calendar.end_date.isBefore(calendarDate.date)) {
calendar.end_date = calendarDate.date;
}
calendarsByServiceId.put(calendarDate.service_id, calendar);
dummyCalendarsByServiceId.put(calendarDate.service_id, calendar);
} else {
removedServiceForDate.put(date, calendarDate.service_id);
}
Expand Down Expand Up @@ -289,7 +289,8 @@ private TableLoadResult createScheduleExceptionsTable() {
calendarServiceIds.add(calendar.service_id);
}

// add auto-generated entries to the calendar table that only existed in the calendar_dates table
// For service_ids that only existed in the calendar_dates table, insert auto-generated, "blank"
// (no days of week specified) calendar entries.
sql = String.format(
"insert into %s (service_id, description, start_date, end_date, " +
"monday, tuesday, wednesday, thursday, friday, saturday, sunday)" +
Expand All @@ -301,23 +302,23 @@ private TableLoadResult createScheduleExceptionsTable() {
"calendar",
calendarStatement
);
for (Calendar calendar : calendarsByServiceId.values()) {
if (calendarServiceIds.contains(calendar.service_id)) {
for (Calendar dummyCalendar : dummyCalendarsByServiceId.values()) {
if (calendarServiceIds.contains(dummyCalendar.service_id)) {
// This service_id already exists in the calendar table. No need to create auto-generated entry.
continue;
}
calendarStatement.setString(1, calendar.service_id);
calendarStatement.setString(1, dummyCalendar.service_id);
calendarStatement.setString(
2,
String.format("%s (auto-generated)", calendar.service_id)
String.format("%s (auto-generated)", dummyCalendar.service_id)
);
calendarStatement.setString(
3,
calendar.start_date.format(DateTimeFormatter.BASIC_ISO_DATE)
dummyCalendar.start_date.format(DateTimeFormatter.BASIC_ISO_DATE)
);
calendarStatement.setString(
4,
calendar.end_date.format(DateTimeFormatter.BASIC_ISO_DATE)
dummyCalendar.end_date.format(DateTimeFormatter.BASIC_ISO_DATE)
);
calendarsTracker.addBatch();
}
Expand Down
17 changes: 10 additions & 7 deletions src/test/java/com/conveyal/gtfs/GTFSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,7 @@ private boolean runIntegrationTestOnZipFile(
// There should be no schema records matching the deleted namespace.
assertThat(schemaCount, is(0));
} catch (SQLException | InvalidNamespaceException e) {
LOG.error("An error occurred while deleting a schema!");
e.printStackTrace();
LOG.error("An error occurred while deleting a schema!", e);
TestUtils.dropDB(testDBName);
return false;
} catch (AssertionError e) {
Expand Down Expand Up @@ -730,12 +729,13 @@ private void assertThatImportedGtfsMeetsExpectations(
String namespace,
PersistenceExpectation[] persistenceExpectations,
ErrorExpectation[] errorExpectations,
boolean editorDatabase
boolean isEditorDatabase
) throws SQLException {
// Store field mismatches here (to provide assertion statements with more details).
Multimap<String, ValuePair> fieldsWithMismatches = ArrayListMultimap.create();
// Check that no validators failed during validation in non-editor databases.
if (!editorDatabase) {
// Check that no validators failed during validation in non-editor databases only (validators do not run
// when creating an editor database).
if (!isEditorDatabase) {
assertThat(
"One or more validators failed during GTFS import.",
countValidationErrorsOfType(connection, namespace, NewGTFSErrorType.VALIDATOR_FAILED),
Expand All @@ -745,7 +745,7 @@ private void assertThatImportedGtfsMeetsExpectations(
// run through testing expectations
LOG.info("testing expectations of record storage in the database");
for (PersistenceExpectation persistenceExpectation : persistenceExpectations) {
if (persistenceExpectation.appliesToEditorDatabaseOnly && !editorDatabase) continue;
if (persistenceExpectation.appliesToEditorDatabaseOnly && !isEditorDatabase) continue;
// select all entries from a table
String sql = String.format(
"select * from %s.%s",
Expand Down Expand Up @@ -817,7 +817,10 @@ private void assertThatImportedGtfsMeetsExpectations(
);
}
// Skip error expectation analysis on editor database
if (editorDatabase) return;
if (isEditorDatabase) {
LOG.info("Skipping error expectations for non-editor database.");
return;
}
// Expect zero errors if errorExpectations is null.
if (errorExpectations == null) errorExpectations = new ErrorExpectation[]{};
// Check that error expectations match errors stored in database.
Expand Down