Skip to content

Commit

Permalink
fix(validator): add fare transfer duration validator
Browse files Browse the repository at this point in the history
re #167
  • Loading branch information
landonreed committed May 24, 2019
1 parent d0f849c commit 60124ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum NewGTFSErrorType {
LANGUAGE_FORMAT(Priority.LOW, "Language should be specified with a valid BCP47 tag."),
ILLEGAL_FIELD_VALUE(Priority.MEDIUM, "Fields may not contain tabs, carriage returns or new lines."),
INTEGER_FORMAT(Priority.MEDIUM, "Incorrect integer format."),
FARE_TRANSFER_MISMATCH(Priority.MEDIUM, "A fare that does not permit transfers has a non-zero transfer duration."),
FLOATING_FORMAT(Priority.MEDIUM, "Incorrect floating point number format."),
COLUMN_NAME_UNSAFE(Priority.HIGH, "Column header contains characters not safe in SQL, it was renamed."),
NUMBER_PARSING(Priority.MEDIUM, "Unable to parse number from value."),
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/conveyal/gtfs/loader/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Feed {
public final TableReader<Agency> agencies;
public final TableReader<Calendar> calendars;
public final TableReader<CalendarDate> calendarDates;
// public final TableReader<Fare> fares;
public final TableReader<FareAttribute> fareAttributes;
public final TableReader<Route> routes;
public final TableReader<Stop> stops;
public final TableReader<Trip> trips;
Expand All @@ -57,7 +57,7 @@ public Feed (DataSource dataSource, String tablePrefix) {
if (tablePrefix != null && !tablePrefix.endsWith(".")) tablePrefix += ".";
this.tablePrefix = tablePrefix == null ? "" : tablePrefix;
agencies = new JDBCTableReader(Table.AGENCY, dataSource, tablePrefix, EntityPopulator.AGENCY);
// fares = new JDBCTableReader(Table.FARES, dataSource, tablePrefix, EntityPopulator.FARE);
fareAttributes = new JDBCTableReader(Table.FARE_ATTRIBUTES, dataSource, tablePrefix, EntityPopulator.FARE_ATTRIBUTE);
calendars = new JDBCTableReader(Table.CALENDAR, dataSource, tablePrefix, EntityPopulator.CALENDAR);
calendarDates = new JDBCTableReader(Table.CALENDAR_DATES, dataSource, tablePrefix, EntityPopulator.CALENDAR_DATE);
routes = new JDBCTableReader(Table.ROUTES, dataSource, tablePrefix, EntityPopulator.ROUTE);
Expand Down Expand Up @@ -89,6 +89,7 @@ public ValidationResult validate () {
List<FeedValidator> feedValidators = Arrays.asList(
new MisplacedStopValidator(this, errorStorage, validationResult),
new DuplicateStopsValidator(this, errorStorage),
new FaresValidator(this, errorStorage),
new TimeZoneValidator(this, errorStorage),
new NewTripTimesValidator(this, errorStorage),
new NamesValidator(this, errorStorage));
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/conveyal/gtfs/validator/FaresValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.conveyal.gtfs.validator;

import com.conveyal.gtfs.error.NewGTFSErrorType;
import com.conveyal.gtfs.error.SQLErrorStorage;
import com.conveyal.gtfs.loader.Feed;
import com.conveyal.gtfs.model.FareAttribute;

/**
* Validator for fares that currently just checks that the transfers and transfer_duration fields are harmonious.
*/
public class FaresValidator extends FeedValidator {
public FaresValidator(Feed feed, SQLErrorStorage errorStorage) {
super(feed, errorStorage);
}

@Override
public void validate() {
for (FareAttribute fareAttribute : feed.fareAttributes) {
if (fareAttribute.transfers == 0 && fareAttribute.transfer_duration > 0) {
// If a fare does not permit transfers, but defines a duration for which a transfer is valid, register
// an error.
registerError(fareAttribute, NewGTFSErrorType.FARE_TRANSFER_MISMATCH);
}
}
}
}

0 comments on commit 60124ee

Please sign in to comment.