From 69102244b3774acb2a2a2f2600a97c662320b366 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Mon, 4 Dec 2023 23:12:10 +0100 Subject: [PATCH] Add support for separate location_group column --- .../onebusaway/gtfs/impl/StopTimeArray.java | 5 +++ .../gtfs/model/LocationGroupElement.java | 2 +- .../org/onebusaway/gtfs/model/StopTime.java | 25 +++++++++++++-- .../onebusaway/gtfs/model/StopTimeProxy.java | 2 ++ .../org/onebusaway/gtfs/GtfsTestData.java | 6 ++++ .../gtfs/serialization/FlexReaderTest.java | 18 +++++++++++ .../gtfs/auburn-transit-flex/agency.txt | 2 ++ .../auburn-transit-flex/booking_rules.txt | 2 ++ .../gtfs/auburn-transit-flex/calendar.txt | 2 ++ .../gtfs/auburn-transit-flex/feed_info.txt | 2 ++ .../auburn-transit-flex/location_groups.txt | 31 +++++++++++++++++++ .../gtfs/auburn-transit-flex/routes.txt | 2 ++ .../gtfs/auburn-transit-flex/stop_times.txt | 3 ++ .../gtfs/auburn-transit-flex/stops.txt | 31 +++++++++++++++++++ .../gtfs/auburn-transit-flex/trips.txt | 2 ++ 15 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/agency.txt create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/booking_rules.txt create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/calendar.txt create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/feed_info.txt create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/location_groups.txt create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/routes.txt create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/stop_times.txt create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/stops.txt create mode 100644 onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/trips.txt diff --git a/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/impl/StopTimeArray.java b/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/impl/StopTimeArray.java index c03a8e1c7..4a68d8be7 100644 --- a/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/impl/StopTimeArray.java +++ b/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/impl/StopTimeArray.java @@ -273,6 +273,11 @@ public void setLocation(StopLocation location) { stops[index] = location; } + @Override + public void setLocationGroup(StopLocation group) { + stops[index] = group; + } + @Override public boolean isArrivalTimeSet() { return arrivalTimes[index] != StopTime.MISSING_VALUE; diff --git a/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/LocationGroupElement.java b/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/LocationGroupElement.java index 05cba1665..f12f17c08 100644 --- a/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/LocationGroupElement.java +++ b/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/LocationGroupElement.java @@ -31,7 +31,7 @@ public class LocationGroupElement extends IdentityBean { @CsvField(name = "location_group_id", mapping = DefaultAgencyIdFieldMappingFactory.class) private AgencyAndId locationGroupId; - @CsvField(name = "location_id", mapping = StopLocationFieldMappingFactory.class) + @CsvField(name = "stop_id", mapping = StopLocationFieldMappingFactory.class) private StopLocation location; @CsvField(optional = true) diff --git a/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/StopTime.java b/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/StopTime.java index 20430db1a..650a349d3 100644 --- a/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/StopTime.java +++ b/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/StopTime.java @@ -16,7 +16,6 @@ */ package org.onebusaway.gtfs.model; -import java.util.Objects; import org.onebusaway.csv_entities.schema.annotations.CsvField; import org.onebusaway.csv_entities.schema.annotations.CsvFields; import org.onebusaway.gtfs.serialization.mappings.EntityFieldMappingFactory; @@ -52,6 +51,9 @@ public final class StopTime extends IdentityBean implements @CsvField(name = "location_id", optional = true, mapping = StopLocationFieldMappingFactory.class) private StopLocation location; + @CsvField(name = "location_group_id", optional = true, mapping = StopLocationFieldMappingFactory.class) + private StopLocation locationGroup; + @CsvField(optional = true, mapping = StopTimeFieldMappingFactory.class) private int arrivalTime = MISSING_VALUE; @@ -201,6 +203,7 @@ public StopTime(StopTime st) { this.farePeriodId = st.farePeriodId; this.stop = st.stop; this.location = st.location; + this.locationGroup = st.locationGroup; this.stopHeadsign = st.stopHeadsign; this.stopSequence = st.stopSequence; this.toStopSequence = st.toStopSequence; @@ -293,9 +296,19 @@ public StopLocation getLocation() { * Returns possible entity for the stop location in this order: * - stop * - location + * - location group */ public StopLocation getStopLocation(){ - return Objects.requireNonNullElseGet(getStop(), this::getLocation); + if(stop != null){ + return stop; + } + else if(location != null) { + return location; + } + else if(locationGroup != null){ + return locationGroup; + } + return null; } public void setStop(StopLocation stop) { @@ -314,6 +327,14 @@ public void setLocation(StopLocation location) { this.location = location; } + public void setLocationGroup(StopLocation group) { + if (proxy != null) { + proxy.setLocationGroup(group); + return; + } + this.locationGroup = group; + } + public boolean isArrivalTimeSet() { if (proxy != null) { return proxy.isArrivalTimeSet(); diff --git a/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/StopTimeProxy.java b/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/StopTimeProxy.java index 1cbc75afa..8c15531ac 100644 --- a/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/StopTimeProxy.java +++ b/onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/StopTimeProxy.java @@ -51,6 +51,8 @@ public interface StopTimeProxy { public void setLocation(StopLocation stop); + public void setLocationGroup(StopLocation stop); + public boolean isArrivalTimeSet(); public int getArrivalTime(); diff --git a/onebusaway-gtfs/src/test/java/org/onebusaway/gtfs/GtfsTestData.java b/onebusaway-gtfs/src/test/java/org/onebusaway/gtfs/GtfsTestData.java index 37c7981a3..4e21dea45 100644 --- a/onebusaway-gtfs/src/test/java/org/onebusaway/gtfs/GtfsTestData.java +++ b/onebusaway-gtfs/src/test/java/org/onebusaway/gtfs/GtfsTestData.java @@ -49,6 +49,8 @@ private static String gtfsPath(String name) { public static final String BROWN_COUNTY_FLEX = gtfsPath("brown-county-flex"); + public static final String AUBURN_TRANSIT_FLEX = gtfsPath("auburn-transit-flex"); + public static final String LOCATIONS_GEOJSON = gtfsPath("locations.geojson"); public static File getCaltrainGtfs() { @@ -88,6 +90,10 @@ public static File getBrownCountyFlex() { return new File("src/test/resources", BROWN_COUNTY_FLEX); } + public static File getAuburnTransitFlex() { + return new File("src/test/resources", AUBURN_TRANSIT_FLEX); + } + public static void readGtfs(T entityStore, File resourcePath, String defaultAgencyId) throws IOException { diff --git a/onebusaway-gtfs/src/test/java/org/onebusaway/gtfs/serialization/FlexReaderTest.java b/onebusaway-gtfs/src/test/java/org/onebusaway/gtfs/serialization/FlexReaderTest.java index 12d7fcd37..79557807a 100644 --- a/onebusaway-gtfs/src/test/java/org/onebusaway/gtfs/serialization/FlexReaderTest.java +++ b/onebusaway-gtfs/src/test/java/org/onebusaway/gtfs/serialization/FlexReaderTest.java @@ -28,6 +28,7 @@ import org.onebusaway.csv_entities.exceptions.CsvEntityIOException; import org.onebusaway.gtfs.GtfsTestData; import org.onebusaway.gtfs.model.Location; +import org.onebusaway.gtfs.model.LocationGroup; import org.onebusaway.gtfs.model.Stop; import org.onebusaway.gtfs.model.StopArea; import org.onebusaway.gtfs.model.StopLocation; @@ -101,6 +102,23 @@ public void locationIdAsASeparateColumn() throws CsvEntityIOException, IOExcepti assertEquals(Location.class, second.getClass()); } + @Test + public void locationGroupIdAsSeparateColumn() throws CsvEntityIOException, IOException { + var dao = processFeed(GtfsTestData.getAuburnTransitFlex(), AGENCY_ID, false); + var trip = dao.getAllTrips().stream().filter(t -> t.getId().getId().equals("t_5756013_b_33000_tn_0")).findAny().get(); + var stopTimes = dao.getStopTimesForTrip(trip); + stopTimes.forEach(st -> assertNotNull(st.getStopLocation())); + + var stopLocations = stopTimes.stream().map(StopTime::getStopLocation).collect(Collectors.toList()); + var first = stopLocations.get(0); + assertEquals("4230479", first.getId().getId()); + assertEquals(LocationGroup.class, first.getClass()); + + var second = stopLocations.get(1); + assertEquals("4230479", second.getId().getId()); + assertEquals(LocationGroup.class, second.getClass()); + } + private static StopArea getArea(List stopAreas, String id) { return stopAreas.stream().filter(a -> a.getId().toString().equals(id)).findAny().get(); } diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/agency.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/agency.txt new file mode 100644 index 000000000..98b463871 --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/agency.txt @@ -0,0 +1,2 @@ +agency_id,agency_url,agency_lang,agency_name,agency_phone,agency_timezone,agency_fare_url,tts_agency_name +1593,https://www.auburn.ca.gov/192/Transit-Services,en,Auburn Transit,(530) 906-3700,America/Los_Angeles,, diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/booking_rules.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/booking_rules.txt new file mode 100644 index 000000000..e9ef19c28 --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/booking_rules.txt @@ -0,0 +1,2 @@ +booking_rule_id,booking_type,prior_notice_duration_min,prior_notice_duration_max,prior_notice_start_day,prior_notice_start_time,prior_notice_last_day,prior_notice_last_time,prior_notice_service_id,message,pickup_message,drop_off_message,phone_number,info_url,booking_url +booking_route_32372,0,,,,,,,,"Auburn Transit provides transportation to and from any Auburn Loop bus stop as well as deviations up to ½ mile throughout the City and parts of surrounding Placer County. To request a ride, call 530-906-3171. Booking through the TransLoc app is available as well.",,,530-906-3171,https://www.auburn.ca.gov/584/Auburn-Loop, diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/calendar.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/calendar.txt new file mode 100644 index 000000000..3cd13126d --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/calendar.txt @@ -0,0 +1,2 @@ +service_id,service_name,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date +c_23810_b_33000_d_63,Loop year round (No Sunday),1,1,1,1,1,1,0,20231001,20241001 diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/feed_info.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/feed_info.txt new file mode 100644 index 000000000..ae3fc4403 --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/feed_info.txt @@ -0,0 +1,2 @@ +feed_publisher_url,feed_publisher_name,feed_lang,feed_version,feed_license,feed_contact_email,feed_contact_url,feed_start_date,feed_end_date,feed_id +http://www.trilliumtransit.com,"Trillium Solutions, Inc.",en,UTC: 27-Nov-2023 16:52,,support+test+auburntransit-ca-us@trilliumtransit.com,http://support.trilliumtransit.com,20231127,20241001,auburntransit-ca-us diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/location_groups.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/location_groups.txt new file mode 100644 index 000000000..7fcf9b6d2 --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/location_groups.txt @@ -0,0 +1,31 @@ +location_group_id,stop_id,location_group_name +4230479,2583236,Aurburn Loop Stops +4230479,2583237,Aurburn Loop Stops +4230479,2583238,Aurburn Loop Stops +4230479,2583242,Aurburn Loop Stops +4230479,2583244,Aurburn Loop Stops +4230479,2583246,Aurburn Loop Stops +4230479,2583249,Aurburn Loop Stops +4230479,2583250,Aurburn Loop Stops +4230479,2583251,Aurburn Loop Stops +4230479,2583252,Aurburn Loop Stops +4230479,2583253,Aurburn Loop Stops +4230479,2583254,Aurburn Loop Stops +4230479,2583255,Aurburn Loop Stops +4230479,2583256,Aurburn Loop Stops +4230479,2583259,Aurburn Loop Stops +4230479,2583260,Aurburn Loop Stops +4230479,2583262,Aurburn Loop Stops +4230479,2583263,Aurburn Loop Stops +4230479,2583266,Aurburn Loop Stops +4230479,2583268,Aurburn Loop Stops +4230479,2583271,Aurburn Loop Stops +4230479,2583276,Aurburn Loop Stops +4230479,2583280,Aurburn Loop Stops +4230479,2583281,Aurburn Loop Stops +4230479,2583282,Aurburn Loop Stops +4230479,2583284,Aurburn Loop Stops +4230479,2583285,Aurburn Loop Stops +4230479,2751414,Aurburn Loop Stops +4230479,3446932,Aurburn Loop Stops +4230479,3446933,Aurburn Loop Stops diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/routes.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/routes.txt new file mode 100644 index 000000000..6db29bf1c --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/routes.txt @@ -0,0 +1,2 @@ +agency_id,route_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color,route_sort_order,min_headway_minutes,eligibility_restricted,continuous_pickup,continuous_drop_off,tts_route_short_name,tts_route_long_name +1593,32372,,Auburn Loop,,3,https://www.auburn.ca.gov/584/Auburn-Loop,bf3c39,ffffff,0,60,0,1,1,, diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/stop_times.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/stop_times.txt new file mode 100644 index 000000000..c8394e636 --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/stop_times.txt @@ -0,0 +1,3 @@ +trip_id,arrival_time,departure_time,stop_id,location_id,location_group_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,shape_dist_traveled,timepoint,continuous_pickup,continuous_drop_off,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,tts_stop_headsign +t_5756013_b_33000_tn_0,,,,,4230479,1,,2,1,,0,1,1,booking_route_32372,booking_route_32372,09:00:00,17:00:00,1,5.0,1,10.0, +t_5756013_b_33000_tn_0,,,,,4230479,2,,1,2,,0,1,1,booking_route_32372,booking_route_32372,09:00:00,17:00:00,1,5.0,1,10.0, \ No newline at end of file diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/stops.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/stops.txt new file mode 100644 index 000000000..00a4bfcec --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/stops.txt @@ -0,0 +1,31 @@ +stop_id,stop_code,platform_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,stop_timezone,position,direction,wheelchair_boarding,tts_stop_name +2583236,,,East Street,,38.89778,-121.07521,,,0,,America/Los_Angeles,,,0, +2583237,,,Auburn Palms,,38.9115,-121.07476,,,0,,America/Los_Angeles,,,0, +2583238,,,Luther Road/Teal Court,,38.92783,-121.07329,,,0,,America/Los_Angeles,,,0, +2583242,,,Auburn Townhomes,,38.91388,-121.06111,,,0,,America/Los_Angeles,,,0, +2583244,,,Boardman Street,,38.89948,-121.06572,,,0,,America/Los_Angeles,,,0, +2583246,,,Grocery Outlet,,38.90537,-121.07483,,,0,,America/Los_Angeles,,,0, +2583249,,,Nevada Station,,38.90333,-121.08272,,,0,,America/Los_Angeles,,,0, +2583250,,,Monkey Cat Restaurant,,38.90056,-121.0677,,,0,,America/Los_Angeles,,,0, +2583251,,,Savemart Shopping Center,,38.90575,-121.07379,,,0,,America/Los_Angeles,,,0, +2583252,,,Dairy Road/Incline Drive,,38.92185,-121.07193,,,0,,America/Los_Angeles,,,0, +2583253,,,Auburn Ravine Road/Dairy Road,,38.91524,-121.07249,,,0,,America/Los_Angeles,,,0, +2583254,,,Alta Vista School,,38.90957,-121.06419,,,0,,America/Los_Angeles,,,0, +2583255,,,Vista Care/Bowman Road,,38.93206,-121.05636,,,0,,America/Los_Angeles,,,0, +2583256,,,Valley Oaks,,38.91028,-121.07434,,,0,,America/Los_Angeles,,,0, +2583259,,,Dairy Road/Dairy Lane,,38.92483,-121.07223,,,0,,America/Los_Angeles,,,0, +2583260,,,Auburn Crossing,,38.92175,-121.05712,,,0,,America/Los_Angeles,,,0, +2583262,,,Macauley Meadows,,38.87837,-121.0796,,,0,,America/Los_Angeles,,,0, +2583263,,,Luther Road/Garth Lane,,38.92821,-121.05809,,,0,,America/Los_Angeles,,,0, +2583266,,,Sacramento/Pacific,,38.88622,-121.0759,,,0,,America/Los_Angeles,,,0, +2583268,,,Borland Avenue,,38.89978,-121.0646,,,0,,America/Los_Angeles,,,0, +2583271,,,Raley's Shopping Center,,38.92357,-121.05455,,,0,,America/Los_Angeles,,,0, +2583276,,,Courthouse,,38.89712,-121.07753,,,0,,America/Los_Angeles,,,0, +2583280,,,Sacramento Street 7-11,,38.8897,-121.07612,,,0,,America/Los_Angeles,,,0, +2583281,,,Reamer Street/High Street,,38.90169,-121.06872,,,0,,America/Los_Angeles,,,0, +2583282,,,Old Town,,38.8957,-121.07827,,,0,,America/Los_Angeles,,,0, +2583284,,,Elders,,38.89871,-121.07141,,,0,,America/Los_Angeles,,,0, +2583285,,,Foothill Market,,38.91602,-121.06076,,,0,,America/Los_Angeles,,,0, +2751414,,,Gold Country Fairgrounds,,38.8936,-121.07532,,,0,,America/Los_Angeles,,,0, +3446932,,,Roadway Inn,,38.92748,-121.05575,,,0,,America/Los_Angeles,,,0, +3446933,,,Depot Bay,,38.90066,-121.0691,,,0,,America/Los_Angeles,,,0, diff --git a/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/trips.txt b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/trips.txt new file mode 100644 index 000000000..d97b19cfa --- /dev/null +++ b/onebusaway-gtfs/src/test/resources/org/onebusaway/gtfs/auburn-transit-flex/trips.txt @@ -0,0 +1,2 @@ +route_id,service_id,trip_id,trip_short_name,trip_headsign,direction_id,block_id,shape_id,bikes_allowed,wheelchair_accessible,trip_type,continuous_pickup_message,continuous_drop_off_message,tts_trip_headsign,tts_trip_short_name +32372,c_23810_b_33000_d_63,t_5756013_b_33000_tn_0,,,0,,,,,,,,,