use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsRelationalDaoImplTest method testBart.
@Test
public void testBart() throws IOException {
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getBartGtfs(), "BART");
List<String> tripAgencyIds = dao.getTripAgencyIdsReferencingServiceId(new AgencyAndId("BART", "WKDY"));
assertEquals(1, tripAgencyIds.size());
assertEquals("BART", tripAgencyIds.get(0));
Agency agency = dao.getAgencyForId("BART");
List<Route> routes = dao.getRoutesForAgency(agency);
assertEquals(10, routes.size());
agency = dao.getAgencyForId("AirBART");
routes = dao.getRoutesForAgency(agency);
assertEquals(1, routes.size());
Route route = dao.getRouteForId(new AgencyAndId("BART", "01"));
List<Trip> trips = dao.getTripsForRoute(route);
assertEquals(225, trips.size());
Trip trip = dao.getTripForId(new AgencyAndId("BART", "15PB1"));
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
assertEquals(12, stopTimes.size());
// Ensure the stopTimes are in stop sequence order
for (int i = 0; i < stopTimes.size() - 1; i++) assertTrue(stopTimes.get(i).getStopSequence() < stopTimes.get(i + 1).getStopSequence());
Stop stop = dao.getStopForId(new AgencyAndId("BART", "DBRK"));
stopTimes = dao.getStopTimesForStop(stop);
assertEquals(584, stopTimes.size());
List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(new AgencyAndId("BART", "airbart-dn.csv"));
assertEquals(50, shapePoints.size());
for (int i = 0; i < shapePoints.size() - 1; i++) assertTrue(shapePoints.get(i).getSequence() < shapePoints.get(i + 1).getSequence());
trip = dao.getTripForId(new AgencyAndId("AirBART", "M-FSAT1DN"));
List<Frequency> frequencies = dao.getFrequenciesForTrip(trip);
assertEquals(1, frequencies.size());
Frequency frequency = frequencies.get(0);
assertEquals(5 * 60 * 60, frequency.getStartTime());
assertEquals(6 * 60 * 60, frequency.getEndTime());
assertEquals(trip, frequency.getTrip());
assertEquals(1200, frequency.getHeadwaySecs());
ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("BART", "WKDY"));
assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
List<ServiceCalendarDate> calendarDates = dao.getCalendarDatesForServiceId(new AgencyAndId("BART", "WKDY"));
assertEquals(7, calendarDates.size());
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class MTASubwayShuttleRouteStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
Map<Route, Route> shuttleRoutes = new HashMap<>();
for (Trip trip : dao.getAllTrips()) {
if (trip.getTripHeadsign().endsWith(SHUTTLE_HEADSIGN_SUFFIX)) {
Route shuttleRoute = shuttleRoutes.computeIfAbsent(trip.getRoute(), r -> getShuttleRoute(dao, r));
trip.setRoute(shuttleRoute);
dao.updateEntity(trip);
}
}
// Shuttle stops share mta_stop_id with non-shuttle version
Map<String, String> parentStopByMtaStopId = new HashMap<>();
for (Stop stop : dao.getAllStops()) {
if (!stop.getName().endsWith(SHUTTLE_STOP_SUFFIX) && stop.getParentStation() != null) {
parentStopByMtaStopId.put(stop.getMtaStopId(), stop.getParentStation());
}
}
for (Stop stop : dao.getAllStops()) {
if (stop.getName().endsWith(SHUTTLE_STOP_SUFFIX)) {
String parent = parentStopByMtaStopId.get(stop.getMtaStopId());
if (parent == null) {
_log.info("No parent for shuttle stop {}", stop.getId());
}
stop.setParentStation(parent);
dao.updateEntity(stop);
}
}
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class MergeRouteFromReferenceStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
HashMap<String, Route> referenceRoutes = new HashMap<>();
for (Route route : reference.getAllRoutes()) {
referenceRoutes.put(route.getId().getId(), route);
}
for (Route route : dao.getAllRoutes()) {
String identifier = route.getId().getId();
if (identifier.length() > 2) {
identifier = identifier.substring(0, 2);
}
Route refRoute = referenceRoutes.get(identifier);
if (refRoute != null) {
route.setShortName(refRoute.getShortName());
route.setLongName(refRoute.getLongName());
route.setType(refRoute.getType());
route.setDesc(refRoute.getDesc());
route.setUrl(refRoute.getUrl());
route.setColor(refRoute.getColor());
route.setTextColor(refRoute.getTextColor());
route.setId(refRoute.getId());
}
}
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class MergeRouteFromReferenceStrategyByLongName method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
HashMap<String, Route> referenceRoutes = new HashMap<>();
for (Route route : reference.getAllRoutes()) {
referenceRoutes.put(route.getId().getId(), route);
}
/* use the initial characters in the longname to match up with the shortname
in the reference route. If the longname is null, try the shortname
*/
for (Route route : dao.getAllRoutes()) {
String longname = route.getLongName();
String identifier = "";
if (longname != null) {
if (longname.contains(" -")) {
String[] parts = longname.split(" -");
identifier = parts[0];
if (identifier.length() > 2) {
identifier = identifier.substring(0, 2);
}
}
} else {
identifier = route.getShortName();
}
Route refRoute = referenceRoutes.get(identifier);
if (refRoute != null) {
route.setShortName(refRoute.getShortName());
route.setLongName(refRoute.getLongName());
route.setType(refRoute.getType());
route.setDesc(refRoute.getDesc());
route.setUrl(refRoute.getUrl());
route.setColor(refRoute.getColor());
route.setTextColor(refRoute.getTextColor());
}
}
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class PierceTransitTripHeadsignCleanupModStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao, Object entity) {
if (!(entity instanceof Trip))
return;
Trip trip = (Trip) entity;
String headsign = trip.getTripHeadsign();
Route route = trip.getRoute();
String shortName = route.getShortName();
if (headsign == null || shortName == null)
return;
headsign = headsign.replaceAll("^" + shortName + "\\s+", "");
headsign = headsign.replaceAll("-\\s+" + shortName + "\\s+", "- ");
trip.setTripHeadsign(headsign);
}
Aggregations