Skip to content

Commit

Permalink
Add support for separate location_group column
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Dec 4, 2023
1 parent ec92c6b commit 6910224
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class LocationGroupElement extends IdentityBean<Integer> {
@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +51,9 @@ public final class StopTime extends IdentityBean<Integer> 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public interface StopTimeProxy {

public void setLocation(StopLocation stop);

public void setLocationGroup(StopLocation stop);

public boolean isArrivalTimeSet();

public int getArrivalTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 <T extends GenericMutableDao> void readGtfs(T entityStore,
File resourcePath, String defaultAgencyId) throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<StopArea> stopAreas, String id) {
return stopAreas.stream().filter(a -> a.getId().toString().equals(id)).findAny().get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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,,
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,,[email protected],http://support.trilliumtransit.com,20231127,20241001,auburntransit-ca-us
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,,
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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,,,,,,,,,

0 comments on commit 6910224

Please sign in to comment.