Skip to content

Commit b299745

Browse files
author
Rob Gregg
committed
feat(gtfs.yml and validation.js): Updated GTFS Spec for stops.txt and agency.txt
#663
1 parent 4e7b8ea commit b299745

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

gtfs.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@
151151
columnWidth: 12
152152
helpContent: "The stop_desc field contains a description of a stop. Please provide useful, quality information. Do not simply duplicate the name of the stop."
153153
- name: "stop_lat"
154-
required: true
154+
required: false
155155
inputType: LATITUDE
156156
columnWidth: 6
157157
helpContent: "The stop_lat field contains the latitude of a stop or station. The field value must be a valid WGS 84 latitude."
158158
- name: "stop_lon"
159-
required: true
159+
required: false
160160
inputType: LONGITUDE
161161
columnWidth: 6
162162
helpContent: "The stop_lon field contains the longitude of a stop or station. The field value must be a valid WGS 84 longitude value from -180 to 180."
@@ -180,6 +180,12 @@
180180
text: Stop (0)
181181
- value: '1'
182182
text: Station (1)
183+
- value: '2'
184+
text: Entrance/Exit (2)
185+
- value: '3'
186+
text: Generic Node (3)
187+
- value: '4'
188+
text: Boarding Area (4)
183189
columnWidth: 12
184190
helpContent: "The location_type field identifies whether this stop ID represents a stop or station. If no location type is specified, or the location_type is blank, stop IDs are treated as stops. Stations may have different properties from stops when they are represented on a map or used in trip planning."
185191
- name: "parent_station"

lib/editor/util/validation.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function doesNotExist (value: any): boolean {
2525
* Returns false if the value is ok.
2626
* Returns an EditorValidationIssue object if the value is not ok.
2727
*/
28+
// eslint-disable-next-line complexity
2829
export function validate (
2930
field: GtfsSpecField,
3031
value: any,
@@ -36,8 +37,8 @@ export function validate (
3637
const valueDoesNotExist = doesNotExist(value)
3738
const isRequiredButEmpty = required && valueDoesNotExist
3839
const isOptionalAndEmpty = !required && valueDoesNotExist
39-
let reason = 'Required field must not be empty'
4040
const agencies = getTableById(tableData, 'agency')
41+
let reason = 'Required field must not be empty'
4142

4243
// setting as a variable here because of eslint bug
4344
type CheckPositiveOutput = {
@@ -100,12 +101,19 @@ export function validate (
100101
(indices.length > 1 ||
101102
(indices.length > 0 && entities[indices[0]].id !== entity.id))
102103
)
104+
console.log(idList.length)
105+
console.log({entity})
106+
if (agencies.length > 1 && entity.agency_id === null) {
107+
reason = 'Identifier is required if more than one agency exists'
108+
return {field: name, invalid: isRequiredButEmpty, reason}
109+
}
103110
if (isRequiredButEmpty || isNotUnique) {
104111
if (isNotUnique) {
105112
reason = 'Identifier must be unique'
106113
}
107114
return {field: name, invalid: isRequiredButEmpty || isNotUnique, reason}
108-
} else {
115+
}
116+
else {
109117
return false
110118
}
111119
case 'TEXT':
@@ -175,21 +183,29 @@ export function validate (
175183
}
176184
case 'LATITUDE':
177185
const isNotLat = value > 90 || value < -90
178-
if (isRequiredButEmpty || isNotLat) {
179-
if (isNotLat) {
180-
reason = 'Field must be valid latitude.'
186+
if (isNotLat) {
187+
reason = 'Field must be valid latitude.'
188+
return {field: name, invalid: isOptionalAndEmpty || isNotLat, reason}
189+
}
190+
if (entity && entity.location_type >= 2) {
191+
if (isOptionalAndEmpty) {
192+
reason = '1 Latitude and Longitude are required for your current location type'
193+
return {field: name, invalid: isOptionalAndEmpty || isNotLat, reason}
181194
}
182-
return {field: name, invalid: isRequiredButEmpty || isNotLat, reason}
183195
} else {
184196
return false
185197
}
186198
case 'LONGITUDE':
187199
const isNotLng = value > 180 || value < -180
188-
if (isRequiredButEmpty || isNotLng) {
189-
if (isNotLng) {
190-
reason = 'Field must be valid longitude.'
200+
if (isNotLng) {
201+
reason = 'Field must be valid longitude.'
202+
return {field: name, invalid: isOptionalAndEmpty || isNotLng, reason}
203+
}
204+
if (entity && entity.location_type >= 2) {
205+
if (isOptionalAndEmpty) {
206+
reason = '1 Latitude and Longitude are required for your current location type'
207+
return {field: name, invalid: isOptionalAndEmpty || isNotLng, reason}
191208
}
192-
return {field: name, invalid: isRequiredButEmpty || isNotLng, reason}
193209
} else {
194210
return false
195211
}

0 commit comments

Comments
 (0)