Skip to content

Commit 60124ee

Browse files
committed
fix(validator): add fare transfer duration validator
re #167
1 parent d0f849c commit 60124ee

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/main/java/com/conveyal/gtfs/error/NewGTFSErrorType.java

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public enum NewGTFSErrorType {
1212
LANGUAGE_FORMAT(Priority.LOW, "Language should be specified with a valid BCP47 tag."),
1313
ILLEGAL_FIELD_VALUE(Priority.MEDIUM, "Fields may not contain tabs, carriage returns or new lines."),
1414
INTEGER_FORMAT(Priority.MEDIUM, "Incorrect integer format."),
15+
FARE_TRANSFER_MISMATCH(Priority.MEDIUM, "A fare that does not permit transfers has a non-zero transfer duration."),
1516
FLOATING_FORMAT(Priority.MEDIUM, "Incorrect floating point number format."),
1617
COLUMN_NAME_UNSAFE(Priority.HIGH, "Column header contains characters not safe in SQL, it was renamed."),
1718
NUMBER_PARSING(Priority.MEDIUM, "Unable to parse number from value."),

src/main/java/com/conveyal/gtfs/loader/Feed.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class Feed {
3535
public final TableReader<Agency> agencies;
3636
public final TableReader<Calendar> calendars;
3737
public final TableReader<CalendarDate> calendarDates;
38-
// public final TableReader<Fare> fares;
38+
public final TableReader<FareAttribute> fareAttributes;
3939
public final TableReader<Route> routes;
4040
public final TableReader<Stop> stops;
4141
public final TableReader<Trip> trips;
@@ -57,7 +57,7 @@ public Feed (DataSource dataSource, String tablePrefix) {
5757
if (tablePrefix != null && !tablePrefix.endsWith(".")) tablePrefix += ".";
5858
this.tablePrefix = tablePrefix == null ? "" : tablePrefix;
5959
agencies = new JDBCTableReader(Table.AGENCY, dataSource, tablePrefix, EntityPopulator.AGENCY);
60-
// fares = new JDBCTableReader(Table.FARES, dataSource, tablePrefix, EntityPopulator.FARE);
60+
fareAttributes = new JDBCTableReader(Table.FARE_ATTRIBUTES, dataSource, tablePrefix, EntityPopulator.FARE_ATTRIBUTE);
6161
calendars = new JDBCTableReader(Table.CALENDAR, dataSource, tablePrefix, EntityPopulator.CALENDAR);
6262
calendarDates = new JDBCTableReader(Table.CALENDAR_DATES, dataSource, tablePrefix, EntityPopulator.CALENDAR_DATE);
6363
routes = new JDBCTableReader(Table.ROUTES, dataSource, tablePrefix, EntityPopulator.ROUTE);
@@ -89,6 +89,7 @@ public ValidationResult validate () {
8989
List<FeedValidator> feedValidators = Arrays.asList(
9090
new MisplacedStopValidator(this, errorStorage, validationResult),
9191
new DuplicateStopsValidator(this, errorStorage),
92+
new FaresValidator(this, errorStorage),
9293
new TimeZoneValidator(this, errorStorage),
9394
new NewTripTimesValidator(this, errorStorage),
9495
new NamesValidator(this, errorStorage));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.conveyal.gtfs.validator;
2+
3+
import com.conveyal.gtfs.error.NewGTFSErrorType;
4+
import com.conveyal.gtfs.error.SQLErrorStorage;
5+
import com.conveyal.gtfs.loader.Feed;
6+
import com.conveyal.gtfs.model.FareAttribute;
7+
8+
/**
9+
* Validator for fares that currently just checks that the transfers and transfer_duration fields are harmonious.
10+
*/
11+
public class FaresValidator extends FeedValidator {
12+
public FaresValidator(Feed feed, SQLErrorStorage errorStorage) {
13+
super(feed, errorStorage);
14+
}
15+
16+
@Override
17+
public void validate() {
18+
for (FareAttribute fareAttribute : feed.fareAttributes) {
19+
if (fareAttribute.transfers == 0 && fareAttribute.transfer_duration > 0) {
20+
// If a fare does not permit transfers, but defines a duration for which a transfer is valid, register
21+
// an error.
22+
registerError(fareAttribute, NewGTFSErrorType.FARE_TRANSFER_MISMATCH);
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)