Skip to content

Commit

Permalink
Merge pull request #226 from ibi-group/flex-spec-upgrade
Browse files Browse the repository at this point in the history
Flex spec upgrade (separate location_id and group_id)
  • Loading branch information
sheldonabrown authored Dec 11, 2023
2 parents 61fdd07 + 1126535 commit e6f1a5d
Show file tree
Hide file tree
Showing 24 changed files with 20,419 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,31 @@ public StopLocation getStop() {
return stops[index];
}

@Override
public StopLocation getLocation() {
return stops[index];
}

@Override
public StopLocation getLocationGroup() {
return stops[index];
}

@Override
public void setStop(StopLocation stop) {
stops[index] = stop;
}

@Override
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 @@ -18,12 +18,6 @@
import java.util.HashSet;
import java.util.Set;

/**
* Location groups have been merged with Fares V2's stop areas.
*
* Please update your code now as this class will be removed soon.
*/
@Deprecated
public class LocationGroup extends IdentityBean<AgencyAndId> implements StopLocation {
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
import org.onebusaway.gtfs.serialization.mappings.DefaultAgencyIdFieldMappingFactory;
import org.onebusaway.gtfs.serialization.mappings.StopLocationFieldMappingFactory;

/**
* Location groups have been merged with Fares V2's stop areas.
*
* Please update your code now as this class will be removed soon.
*/
@Deprecated
@CsvFields(filename = "location_groups.txt", required = false, prefix = "location_group_")
public class LocationGroupElement extends IdentityBean<Integer> {

Expand All @@ -37,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 @@ -42,9 +42,19 @@ public final class StopTime extends IdentityBean<Integer> implements
@CsvField(name = "trip_id", mapping = EntityFieldMappingFactory.class)
private Trip trip;

@CsvField(name = "stop_id", mapping = StopLocationFieldMappingFactory.class)
/**
* This is optional because in flex you can also have location_id and location_group_id.
*/
@CsvField(name = "stop_id", optional = true, mapping = StopLocationFieldMappingFactory.class)
private StopLocation stop;

@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 @@ -192,6 +202,8 @@ public StopTime(StopTime st) {
this.shapeDistTraveled = st.shapeDistTraveled;
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 @@ -266,13 +278,49 @@ public void setToStopSequence(Integer toStopSequence) {
this.toStopSequence = toStopSequence;
}

@Override
public StopLocation getStop() {
if (proxy != null) {
return proxy.getStop();
}
return stop;
}

@Override
public StopLocation getLocation() {
if (proxy != null) {
return proxy.getLocation();
}
return location;
}

@Override
public StopLocation getLocationGroup() {
if (proxy != null) {
return proxy.getLocationGroup();
}
return locationGroup;
}

/**
* Returns possible entity for the stop location in this order:
* - stop
* - location
* - location group
*/
public StopLocation getStopLocation(){
if(stop != null){
return stop;
}
else if(location != null) {
return location;
}
else if(locationGroup != null){
return locationGroup;
}
return null;
}

public void setStop(StopLocation stop) {
if (proxy != null) {
proxy.setStop(stop);
Expand All @@ -281,6 +329,22 @@ public void setStop(StopLocation stop) {
this.stop = stop;
}

public void setLocation(StopLocation location) {
if (proxy != null) {
proxy.setLocation(location);
return;
}
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 Expand Up @@ -674,7 +738,7 @@ public String displayArrival() {

@Override
public String toString() {
return "StopTime(seq=" + getStopSequence() + " stop=" + (getStop()==null?"NuLl":getStop().getId())
return "StopTime(seq=" + getStopSequence() + " stop=" + (getStopLocation()==null?"NuLl":getStop().getId())
+ " trip=" + (getTrip()==null?"NuLl":getTrip().getId()) + " times="
+ StopTimeFieldMappingFactory.getSecondsAsString(getArrivalTime())
+ "-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ public interface StopTimeProxy {

public StopLocation getStop();

public StopLocation getLocation();
public StopLocation getLocationGroup();

public void setStop(StopLocation stop);

public void setLocation(StopLocation stop);

public void setLocationGroup(StopLocation stop);

public boolean isArrivalTimeSet();

public int getArrivalTime();
Expand Down Expand Up @@ -122,4 +129,5 @@ public interface StopTimeProxy {
public String getFreeRunningFlag();

public void setFreeRunningFlag(String freeRunningFlag);

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ private static String gtfsPath(String name) {

public static final String PIERCE_TRANSIT_FLEX = gtfsPath("piercetransit-stop-areas-flex");

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 @@ -77,10 +81,19 @@ public static File getTurlockFaresV2() {
public static File getMdotMetroFaresV2() {
return new File("src/test/resources", MDOT_FARES_V2);
}

public static File getPierceTransitFlex() {
return new File("src/test/resources", PIERCE_TRANSIT_FLEX);
}

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 @@ -16,6 +16,7 @@
package org.onebusaway.gtfs.serialization;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertSame;

import java.io.IOException;
Expand All @@ -27,9 +28,11 @@
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;
import org.onebusaway.gtfs.model.StopTime;

public class FlexReaderTest extends BaseGtfsTest {

Expand Down Expand Up @@ -82,6 +85,40 @@ public void pierceTransitStopAreas() throws CsvEntityIOException, IOException {

}

@Test
public void locationIdAsASeparateColumn() throws CsvEntityIOException, IOException {
var dao = processFeed(GtfsTestData.getBrownCountyFlex(), AGENCY_ID, false);
var trip = dao.getAllTrips().stream().filter(t -> t.getId().getId().equals("t_5374696_b_77497_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("4149546", first.getId().getId());
assertEquals(Stop.class, first.getClass());

var second = stopLocations.get(1);
assertEquals("radius_300_s_4149546_s_4149547", second.getId().getId());
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,,,,,,,,,
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
4870,https://www.co.brown.mn.us/heartland-express-transit?view=category&id=56,en,Brown County Heartland Express,,America/Chicago,,
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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_74362,2,,,14,08:00:00,1,15:00:00,,"Brown County Heartland Express provides door-to-door on-demand transportation. To request a ride, call 1-507-359-2717 or 1-800-707-2717 by 3pm at least one business day ahead of your trip. ",,,(507) 359-2717,https://www.co.brown.mn.us/heartland-express-transit,
booking_route_74513,0,,,,,,,,Hermann Express may deviate 1-2 blocks from the route to drop off passengers. Please coordinate with the driver to request a deviated drop-off; deviations are limited to keep the bus on schedule.,,,(507) 359-2717,https://www.co.brown.mn.us/heartland-express-transit,
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: 03-Oct-2023 15:38,,[email protected],http://support.trilliumtransit.com,20231003,20241001,browncounty-mn-us
Loading

0 comments on commit e6f1a5d

Please sign in to comment.