|
3 | 3 | import com.conveyal.gtfs.error.SQLErrorStorage;
|
4 | 4 | import com.conveyal.gtfs.loader.Feed;
|
5 | 5 | import com.conveyal.gtfs.model.Route;
|
| 6 | +import com.conveyal.gtfs.model.Stop; |
| 7 | +import com.conveyal.gtfs.model.Trip; |
6 | 8 |
|
7 | 9 | import static com.conveyal.gtfs.error.NewGTFSErrorType.*;
|
8 | 10 |
|
@@ -41,7 +43,41 @@ public void validate() {
|
41 | 43 | // TODO we want some additional checking for extended route types.
|
42 | 44 | }
|
43 | 45 | }
|
44 |
| - // TODO Check trips and all other tables. |
| 46 | + // Check stops |
| 47 | + for (Stop stop : feed.stops) { |
| 48 | + String name = normalize(stop.stop_name); |
| 49 | + String desc = normalize(stop.stop_desc); |
| 50 | + // Stops must be named. |
| 51 | + if (name.isEmpty()) { |
| 52 | + registerError(stop, STOP_NAME_MISSING); |
| 53 | + } |
| 54 | + // If provided, the description of a stop should be more informative than its name. |
| 55 | + if (!desc.isEmpty() && desc.equals(name)) { |
| 56 | + registerError(stop, STOP_DESCRIPTION_SAME_AS_NAME, desc); |
| 57 | + } |
| 58 | + } |
| 59 | + // Check trips |
| 60 | + for (Trip trip : feed.trips) { |
| 61 | + String headsign = normalize(trip.trip_headsign); |
| 62 | + // TODO: check trip short name? |
| 63 | +// String shortName = normalize(trip.trip_short_name); |
| 64 | + Route route = feed.routes.get(trip.route_id); |
| 65 | + String routeShortName = "", routeLongName = ""; |
| 66 | + if (route != null) { |
| 67 | + routeShortName = normalize(route.route_short_name); |
| 68 | + routeLongName = normalize(route.route_long_name); |
| 69 | + } |
| 70 | + // Trip headsign should not duplicate route name. |
| 71 | + if (!headsign.isEmpty() && (headsign.contains(routeShortName) || headsign.contains(routeLongName))) { |
| 72 | + registerError(trip, TRIP_HEADSIGN_CONTAINS_ROUTE_NAME, headsign); |
| 73 | + } |
| 74 | + // Trip headsign should not begin with "to" or "towards" (note: headsign normalized to lowercase). Headsigns |
| 75 | + // should follow one of the patterns defined in the best practices: http://gtfs.org/best-practices#tripstxt |
| 76 | + if (headsign.startsWith("to ") || headsign.startsWith("towards ")) { |
| 77 | + registerError(trip, TRIP_HEADSIGN_SHOULD_DESCRIBE_DESTINATION_OR_WAYPOINTS, headsign); |
| 78 | + } |
| 79 | + } |
| 80 | + // TODO Are there other tables we're not checking? |
45 | 81 | }
|
46 | 82 |
|
47 | 83 | /** @return a non-null String that is lower case and has no leading or trailing whitespace */
|
|
0 commit comments