Skip to content

Commit a7c4121

Browse files
authored
Merge pull request #599 from ibi-group/feature/DT-423-rename-stop-areas-location-groups
Flex spec v2
2 parents 300c981 + 10d924c commit a7c4121

File tree

20 files changed

+53
-94
lines changed

20 files changed

+53
-94
lines changed

pom.xml

+6-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
<dependency>
272272
<groupId>com.github.ibi-group</groupId>
273273
<artifactId>gtfs-lib</artifactId>
274-
<version>2bd924c6e5f5244a279c9d94298c14c0b3d47b35</version>
274+
<version>c9908447dad0720cd606c3c753752e6850f7b572</version>
275275
<!-- Latest dev-flex build on jitpack.io -->
276276
<!-- Exclusions added in order to silence SLF4J warnings about multiple bindings:
277277
http://www.slf4j.org/codes.html#multiple_bindings
@@ -455,6 +455,11 @@
455455
<artifactId>gson</artifactId>
456456
<version>2.8.9</version>
457457
</dependency>
458+
<dependency>
459+
<groupId>org.apache.commons</groupId>
460+
<artifactId>commons-lang3</artifactId>
461+
<version>3.17.0</version>
462+
</dependency>
458463
</dependencies>
459464

460465
</project>

src/main/java/com/conveyal/datatools/manager/DataManager.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,11 @@ static void registerRoutes() throws IOException {
210210
// NOTE: fare_attributes controller handles updates to nested table fare_rules.
211211
new EditorControllerImpl(EDITOR_API_PREFIX, Table.FARE_ATTRIBUTES, DataManager.GTFS_DATA_SOURCE);
212212
new EditorControllerImpl(EDITOR_API_PREFIX, Table.FEED_INFO, DataManager.GTFS_DATA_SOURCE);
213-
// NOTE: AREA and STOP_AREAS are additions for GTFS Flex but belong to the Fares v2 specification:
214-
new EditorControllerImpl(EDITOR_API_PREFIX, Table.STOP_AREAS, DataManager.GTFS_DATA_SOURCE);
215-
new EditorControllerImpl(EDITOR_API_PREFIX, Table.AREA, DataManager.GTFS_DATA_SOURCE);
216213
// NOTE: Booking rules, locations and location shapes are GTFS Flex additions.
217214
new EditorControllerImpl(EDITOR_API_PREFIX, Table.BOOKING_RULES, DataManager.GTFS_DATA_SOURCE);
218215
new EditorControllerImpl(EDITOR_API_PREFIX, Table.LOCATIONS, DataManager.GTFS_DATA_SOURCE);
216+
new EditorControllerImpl(EDITOR_API_PREFIX, Table.LOCATION_GROUP, DataManager.GTFS_DATA_SOURCE);
217+
new EditorControllerImpl(EDITOR_API_PREFIX, Table.LOCATION_GROUP_STOPS, DataManager.GTFS_DATA_SOURCE);
219218
new EditorControllerImpl(EDITOR_API_PREFIX, Table.LOCATION_SHAPES, DataManager.GTFS_DATA_SOURCE);
220219
new EditorControllerImpl(EDITOR_API_PREFIX, Table.ROUTES, DataManager.GTFS_DATA_SOURCE);
221220
// NOTE: Patterns controller handles updates to nested tables shapes, pattern stops, and frequencies.

src/main/java/com/conveyal/datatools/manager/jobs/feedmerge/MergeFeedsResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class MergeFeedsResult implements Serializable {
4040
* Track various table ids for resolving foreign references.
4141
*/
4242
public Set<String> stopIds = new HashSet<>();
43-
public Set<String> stopAreaIds = new HashSet<>();
43+
public Set<String> locationGroupStopIds = new HashSet<>();
4444

4545
/**
4646
* Track the set of route IDs to end up in the merged feed in order to determine which route_attributes

src/main/java/com/conveyal/datatools/manager/jobs/feedmerge/MergeLineContext.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ private void setForeignReferenceKeyValues() {
246246
case "stops":
247247
mergeFeedsResult.stopIds.add(getIdWithScope(keyValue));
248248
break;
249-
case "stop_areas":
250-
mergeFeedsResult.stopAreaIds.add(getIdWithScope(keyValue));
249+
case "location_group_stops":
250+
mergeFeedsResult.locationGroupStopIds.add(getIdWithScope(keyValue));
251251
break;
252252
default:
253253
// nothing.
@@ -272,16 +272,10 @@ private Table getReferenceTable(FieldContext fieldContext, Field field) {
272272
getTableScopedValue(Table.CALENDAR_DATES, fieldContext.getValue())
273273
);
274274
case STOP_TIMES_STOP_ID_KEY:
275-
return ReferenceTableDiscovery.getStopTimeStopIdReferenceTable(
275+
case LOCATION_GROUP_STOPS_STOP_ID_KEY:
276+
return ReferenceTableDiscovery.getStopReferenceTable(
276277
fieldContext.getValueToWrite(),
277-
mergeFeedsResult,
278-
feedMergeContext.locationIds
279-
);
280-
case STOP_AREA_STOP_ID_KEY:
281-
return ReferenceTableDiscovery.getStopAreaAreaIdReferenceTable(
282-
fieldContext.getValueToWrite(),
283-
mergeFeedsResult,
284-
feedMergeContext.locationIds
278+
mergeFeedsResult
285279
);
286280
default:
287281
return null;

src/main/java/com/conveyal/datatools/manager/jobs/feedmerge/ReferenceTableDiscovery.java

+6-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.conveyal.gtfs.loader.Field;
44
import com.conveyal.gtfs.loader.Table;
55

6-
import java.util.Set;
76
import java.util.stream.Collectors;
87

98
import static com.conveyal.datatools.manager.jobs.feedmerge.MergeLineContext.SERVICE_ID;
@@ -27,23 +26,20 @@ public enum ReferenceTableKey {
2726
Table.SCHEDULE_EXCEPTIONS.name
2827
)
2928
),
30-
STOP_AREA_STOP_ID_KEY(
29+
LOCATION_GROUP_STOPS_STOP_ID_KEY(
3130
String.join(
3231
REF_TABLE_SEPARATOR,
33-
Table.STOP_AREAS.name,
32+
Table.LOCATION_GROUP_STOPS.name,
3433
"stop_id",
35-
Table.STOPS.name,
36-
Table.LOCATIONS.name
34+
Table.STOPS.name
3735
)
3836
),
3937
STOP_TIMES_STOP_ID_KEY(
4038
String.join(
4139
REF_TABLE_SEPARATOR,
4240
Table.STOP_TIMES.name,
4341
"stop_id",
44-
Table.STOPS.name,
45-
Table.LOCATIONS.name,
46-
Table.STOP_AREAS.name
42+
Table.STOPS.name
4743
)
4844
);
4945

@@ -112,35 +108,11 @@ public static Table getTripServiceIdReferenceTable(
112108
}
113109

114110
/**
115-
* Define the reference table for a stop area's area id. This will either be a stop or location.
111+
* Defines the reference table as a stop if the field value matches a stop id.
116112
*/
117-
public static Table getStopAreaAreaIdReferenceTable(
118-
String fieldValue,
119-
MergeFeedsResult mergeFeedsResult,
120-
Set<String> locationIds
121-
) {
122-
if (mergeFeedsResult.stopIds.contains(fieldValue)) {
123-
return Table.STOPS;
124-
} else if (locationIds.contains(fieldValue)) {
125-
return Table.LOCATIONS;
126-
}
127-
return null;
128-
}
129-
130-
/**
131-
* Define the reference table for a stop time's stop id. This will either be a stop, location or stop area.
132-
*/
133-
public static Table getStopTimeStopIdReferenceTable(
134-
String fieldValue,
135-
MergeFeedsResult mergeFeedsResult,
136-
Set<String> locationIds
137-
) {
113+
public static Table getStopReferenceTable(String fieldValue, MergeFeedsResult mergeFeedsResult) {
138114
if (mergeFeedsResult.stopIds.contains(fieldValue)) {
139115
return Table.STOPS;
140-
} else if (locationIds.contains(fieldValue)) {
141-
return Table.LOCATIONS;
142-
} else if (mergeFeedsResult.stopAreaIds.contains(fieldValue)) {
143-
return Table.STOP_AREAS;
144116
}
145117
return null;
146118
}

src/test/java/com/conveyal/datatools/manager/jobs/FlexMergeFeedsJobTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ void canMergeRegional() throws SQLException {
9797

9898
// Ensure the feed has the row counts we expect.
9999
assertRowCount(r1.agency, r2.agency, merged.agency, "Agency");
100-
assertRowCount(r1.area, r2.area, merged.area, "Area");
101100
assertRowCount(r1.attributions, r2.attributions, merged.attributions, "Attributions");
102101
assertRowCount(r1.bookingRules, r2.bookingRules, merged.bookingRules, "Booking rules");
103102
assertRowCount(r1.calendar, r2.calendar, merged.calendar, "Calendar");
@@ -106,11 +105,12 @@ void canMergeRegional() throws SQLException {
106105
assertRowCount(r1.fareRules, r2.fareRules, merged.fareRules, "Fare rules");
107106
assertRowCount(r1.frequencies, r2.frequencies, merged.frequencies, "Frequencies");
108107
assertRowCount(r1.locations, r2.locations, merged.locations, "Locations");
108+
assertRowCount(r1.locationGroup, r2.locationGroup, merged.locationGroup, "Location Groups");
109+
assertRowCount(r1.locationGroupStops, r2.locationGroupStops, merged.locationGroupStops, "Location Group Stops");
109110
assertRowCount(r1.locationShapes, r2.locationShapes, merged.locationShapes, "Location shapes");
110111
assertRowCount(r1.routes, r2.routes, merged.routes, "Routes");
111112
assertRowCount(r1.shapes, r2.shapes, merged.shapes, "Shapes");
112113
assertRowCount(r1.stops, r2.stops, merged.stops, "Stops");
113-
assertRowCount(r1.stopAreas, r2.stopAreas, merged.stopAreas, "Stop areas");
114114
assertRowCount(r1.stopTimes, r2.stopTimes, merged.stopTimes, "Stop times");
115115
assertRowCount(r1.trips, r2.trips, merged.trips, "Trips");
116116
assertRowCount(r1.translations, r2.translations, merged.translations, "Translations");

src/test/java/com/conveyal/datatools/manager/jobs/NormalizeFieldTransformJobTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ void canNormalizeField(TransformationCase transformationCase) throws IOException
102102
private static Stream<Arguments> createNormalizedFieldCases() {
103103
return Stream.of(
104104
Arguments.of(new TransformationCase("routes", "route_long_name", "Route", "Rte")),
105-
Arguments.of(new TransformationCase("booking_rules", "pickup_message", "Message", "Msg")),
106-
Arguments.of(new TransformationCase("areas", "area_name", "Area", "Place"))
105+
Arguments.of(new TransformationCase("booking_rules", "pickup_message", "Message", "Msg"))
107106
);
108107
}
109108

src/test/resources/com/conveyal/datatools/gtfs/fake-agency-for-field-normalizing/areas.txt

-2
This file was deleted.

src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-flex-version-1/areas.txt

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
location_group_id,stop_id
2+
1,123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
location_group_id,location_group_name
2+
1,"Area referencing a stop"

src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-flex-version-1/locations.geojson

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "area_1469-2",
66
"properties": {
77
"stop_name": "Templeboy to Ballisodare",
8-
"stop_desc": "Templeboy to Ballisodare Door-to-door pickup area"
8+
"stop_desc": "Templeboy to Ballisodare Door-to-door pickup locationGroup"
99
},
1010
"type": "Feature",
1111
"geometry": {
@@ -25,7 +25,7 @@
2525
"id": "area_1469-1",
2626
"properties": {
2727
"stop_name": "Dromore West to Templeboy",
28-
"stop_desc": "Dromore West to Templeboy Door-to-door pickup area"
28+
"stop_desc": "Dromore West to Templeboy Door-to-door pickup locationGroup"
2929
},
3030
"type": "Feature",
3131
"geometry": {
@@ -172,7 +172,7 @@
172172
"id": "area_246",
173173
"properties": {
174174
"stop_name": "Moville to Letterkenny",
175-
"stop_desc": "Moville to Letterkenny Door-to-door pickup area"
175+
"stop_desc": "Moville to Letterkenny Door-to-door pickup locationGroup"
176176
},
177177
"type": "Feature",
178178
"geometry": {
@@ -187,7 +187,7 @@
187187
"id": "area_251",
188188
"properties": {
189189
"stop_name": "Muff to Moville",
190-
"stop_desc": "Muff to Moville Door-to-door pickup area"
190+
"stop_desc": "Muff to Moville Door-to-door pickup locationGroup"
191191
},
192192
"type": "Feature",
193193
"geometry": {

src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-flex-version-1/stop_areas.txt

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,continuous_pickup,continuous_drop_off,shape_dist_traveled,timepoint,pickup_booking_rule_id,drop_off_booking_rule_id,start_pickup_drop_off_window,end_pickup_drop_off_window,mean_duration_factor,mean_duration_offset,safe_duration_factor,safe_duration_offset
2-
a30277f8-e50a-4a85-9141-b1e0da9d429d,07:00:00,07:00:00,4u6g,1,Test stop headsign,0,0,1,1,0.0000000,1,"1","1",07:00:00,07:00:00,1,60,1,60
3-
a30277f8-e50a-4a85-9141-b1e0da9d429d,07:01:00,07:01:00,johv,2,Test stop headsign 2,0,0,1,1,341.4491961,1,"1","1",07:01:00,07:01:00,1,60,1,60
4-
frequency-trip,08:00:00,08:00:00,4u6g,1,Test stop headsign frequency trip,0,0,1,1,0.0000000,1,"1","1",07:02:00,07:02:00,1,60,1,60
5-
frequency-trip,08:29:00,08:29:00,1234,2,Test stop headsign frequency trip,0,0,1,1,341.4491961,1,"1","1",07:03:00,07:03:00,1,60,1,60
6-
frequency-trip,08:31:00,08:31:00,area_251,3,,0,0,1,1,341.4491961,1,"1","1",07:03:00,07:03:00,1,60,1,60
7-
frequency-trip,,,3,4,,1,1,1,1,341.4491961,1,"1","1",07:04:00,07:05:00,1,60,1,60
1+
trip_id,arrival_time,departure_time,stop_id,location_group_id,location_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,continuous_pickup,continuous_drop_off,shape_dist_traveled,timepoint,pickup_booking_rule_id,drop_off_booking_rule_id,start_pickup_drop_off_window,end_pickup_drop_off_window
2+
a30277f8-e50a-4a85-9141-b1e0da9d429d,07:00:00,07:00:00,4u6g,,,1,Test stop headsign,0,0,1,1,0.0000000,1,"1","1",07:00:00,07:00:00,1
3+
a30277f8-e50a-4a85-9141-b1e0da9d429d,07:01:00,07:01:00,johv,,,2,Test stop headsign 2,0,0,1,1,341.4491961,1,"1","1",07:01:00,07:01:00
4+
frequency-trip,08:00:00,08:00:00,4u6g,,,1,Test stop headsign frequency trip,0,0,1,1,0.0000000,1,"1","1",07:02:00,07:02:00
5+
frequency-trip,08:29:00,08:29:00,1234,,,2,Test stop headsign frequency trip,0,0,1,1,341.4491961,1,"1","1",07:03:00,07:03:00
6+
frequency-trip,08:31:00,08:31:00,,,area_251,3,,0,0,1,1,341.4491961,1,"1","1",07:03:00,07:03:00
7+
frequency-trip,,,,1,,4,,1,1,1,1,341.4491961,1,"1","1",07:04:00,07:05:00

src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-flex-version-2/areas.txt

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
location_group_id,stop_id
2+
1,123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
location_group_id,location_group_name
2+
1,"Area referencing a stop"

src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-flex-version-2/locations.geojson

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "area_1469-2",
66
"properties": {
77
"stop_name": "Templeboy to Ballisodare",
8-
"stop_desc": "Templeboy to Ballisodare Door-to-door pickup area"
8+
"stop_desc": "Templeboy to Ballisodare Door-to-door pickup locationGroup"
99
},
1010
"type": "Feature",
1111
"geometry": {
@@ -25,7 +25,7 @@
2525
"id": "area_1469-1",
2626
"properties": {
2727
"stop_name": "Dromore West to Templeboy",
28-
"stop_desc": "Dromore West to Templeboy Door-to-door pickup area"
28+
"stop_desc": "Dromore West to Templeboy Door-to-door pickup locationGroup"
2929
},
3030
"type": "Feature",
3131
"geometry": {
@@ -172,7 +172,7 @@
172172
"id": "area_246",
173173
"properties": {
174174
"stop_name": "Moville to Letterkenny",
175-
"stop_desc": "Moville to Letterkenny Door-to-door pickup area"
175+
"stop_desc": "Moville to Letterkenny Door-to-door pickup locationGroup"
176176
},
177177
"type": "Feature",
178178
"geometry": {
@@ -187,7 +187,7 @@
187187
"id": "area_251",
188188
"properties": {
189189
"stop_name": "Muff to Moville",
190-
"stop_desc": "Muff to Moville Door-to-door pickup area"
190+
"stop_desc": "Muff to Moville Door-to-door pickup locationGroup"
191191
},
192192
"type": "Feature",
193193
"geometry": {

src/test/resources/com/conveyal/datatools/gtfs/fake-agency-with-flex-version-2/stop_areas.txt

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,continuous_pickup,continuous_drop_off,shape_dist_traveled,timepoint,pickup_booking_rule_id,drop_off_booking_rule_id,start_pickup_drop_off_window,end_pickup_drop_off_window,mean_duration_factor,mean_duration_offset,safe_duration_factor,safe_duration_offset
2-
a30277f8-e50a-4a85-9141-b1e0da9d429d,07:00:00,07:00:00,4u6g,1,Test stop headsign,0,0,1,1,0.0000000,1,"1","1",07:00:00,07:00:00,1,60,1,60
3-
a30277f8-e50a-4a85-9141-b1e0da9d429d,07:01:00,07:01:00,johv,2,Test stop headsign 2,0,0,1,1,341.4491961,1,"1","1",07:01:00,07:01:00,1,60,1,60
4-
frequency-trip,08:00:00,08:00:00,4u6g,1,Test stop headsign frequency trip,0,0,1,1,0.0000000,1,"1","1",07:02:00,07:02:00,1,60,1,60
5-
frequency-trip,08:29:00,08:29:00,1234,2,Test stop headsign frequency trip,0,0,1,1,341.4491961,1,"1","1",07:03:00,07:03:00,1,60,1,60
6-
frequency-trip,08:31:00,08:31:00,area_251,3,,0,0,1,1,341.4491961,1,"1","1",07:03:00,07:03:00,1,60,1,60
7-
frequency-trip,,,3,4,,1,1,1,1,341.4491961,1,"1","1",07:04:00,07:05:00,1,60,1,60
1+
trip_id,arrival_time,departure_time,stop_id,location_group_id,location_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,continuous_pickup,continuous_drop_off,shape_dist_traveled,timepoint,pickup_booking_rule_id,drop_off_booking_rule_id,start_pickup_drop_off_window,end_pickup_drop_off_window
2+
a30277f8-e50a-4a85-9141-b1e0da9d429d,07:00:00,07:00:00,4u6g,,,1,Test stop headsign,0,0,1,1,0.0000000,1,"1","1",07:00:00,07:00:00,1
3+
a30277f8-e50a-4a85-9141-b1e0da9d429d,07:01:00,07:01:00,johv,,,2,Test stop headsign 2,0,0,1,1,341.4491961,1,"1","1",07:01:00,07:01:00
4+
frequency-trip,08:00:00,08:00:00,4u6g,,,1,Test stop headsign frequency trip,0,0,1,1,0.0000000,1,"1","1",07:02:00,07:02:00
5+
frequency-trip,08:29:00,08:29:00,1234,,,2,Test stop headsign frequency trip,0,0,1,1,341.4491961,1,"1","1",07:03:00,07:03:00
6+
frequency-trip,08:31:00,08:31:00,,,area_251,3,,0,0,1,1,341.4491961,1,"1","1",07:03:00,07:03:00
7+
frequency-trip,,,,1,,4,,1,1,1,1,341.4491961,1,"1","1",07:04:00,07:05:00

0 commit comments

Comments
 (0)