use of org.onebusaway.gtfs.model.Trip 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);
}
use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.
the class WSFScheduleService method setBlockIdsFromSchedResponse.
private void setBlockIdsFromSchedResponse(SchedResponse resp) {
List<SchedTerminalCombo> combos = resp.getTerminalCombos().getValue().getSchedTerminalCombo();
for (SchedTerminalCombo stc : combos) {
String depart = stc.getDepartingTerminalID().toString();
String arrive = stc.getArrivingTerminalID().toString();
for (SchedTime sched : schedTime(stc)) {
long time = ts(sched.getDepartingTime());
Trip trip = _tripResolutionService.resolve(depart, time, arrive);
if (trip != null) {
trip.setBlockId(sched.getVesselID().toString());
} else {
_log.warn("Skipping schedTime due to no matching trip {}", sched.toString());
}
}
}
}
use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.
the class MergeRouteFromReferenceStrategyById method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
ArrayList<Route> routesToRemove = new ArrayList();
HashMap<String, Route> referenceRoutes = new HashMap<>();
for (Route route : reference.getAllRoutes()) {
referenceRoutes.put(route.getId().getId(), route);
}
_log.info("Routes: {}, Trips: {}", dao.getAllRoutes().size(), dao.getAllTrips().size());
for (Route route : dao.getAllRoutes()) {
String identifier = route.getId().getId();
Route refRoute = referenceRoutes.get(identifier);
if (refRoute != null) {
setRoute(route, refRoute);
} else {
// if yes, check if it matches w/out LTD
if (identifier.contains("-LTD")) {
identifier = identifier.replace("-LTD", "");
refRoute = referenceRoutes.get(identifier);
if (refRoute != null) {
updateTripHeadsign(dao, route);
// dao.getRouteForId only works with route ids that have not changed at all from input
if (dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), refRoute.getId().getId())) != null) {
routesToRemove.add(route);
for (Trip trip : dao.getTripsForRoute(route)) {
trip.setRoute(dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), refRoute.getId().getId())));
}
} else // otherwise, update the route id etc
{
setLTDRoute(route, refRoute);
}
} else if (identifier.equals("Q6")) {
refRoute = referenceRoutes.get("Q06");
if (refRoute != null) {
updateTripHeadsign(dao, route);
if (dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), "Q6")) != null) {
routesToRemove.add(route);
for (Trip trip : dao.getTripsForRoute(route)) {
trip.setRoute(dao.getRouteForId(new AgencyAndId(route.getId().getAgencyId(), "Q6")));
}
}
}
} else {
_log.info("No reference route for route: " + route.getId().getId());
}
}
}
}
_log.info("Routes to remove: " + routesToRemove.size());
for (Route route : routesToRemove) {
dao.removeEntity(route);
}
_log.info("Routes: {}, Trips: {}", dao.getAllRoutes().size(), dao.getAllTrips().size());
}
use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.
the class InterpolateStopTimesFromTimePointsStrategy method interpolateArrivalAndDepartureTimes.
private void interpolateArrivalAndDepartureTimes(GtfsMutableRelationalDao dao, Map<String, List<Trip>> tripsByBlockId) {
for (List<Trip> trips : tripsByBlockId.values()) {
for (Trip trip : trips) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
double[] distanceTraveled = getDistanceTraveledForStopTimes(stopTimes);
int[] arrivalTimes = new int[stopTimes.size()];
int[] departureTimes = new int[stopTimes.size()];
interpolateArrivalAndDepartureTimes(dao, stopTimes, distanceTraveled, arrivalTimes, departureTimes);
// arrival and departure times represent adjusted values
// set them back on the dao
int sequence = 0;
for (StopTime stopTime : stopTimes) {
stopTime.setArrivalTime(arrivalTimes[sequence]);
stopTime.setDepartureTime(departureTimes[sequence]);
sequence++;
dao.updateEntity(stopTime);
}
}
}
}
use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.
the class LastStopToHeadsignStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
for (Trip trip : dao.getAllTrips()) {
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
StopLocation lastStop = stopTimes.get(stopTimes.size() - 1).getStop();
trip.setTripHeadsign(lastStop.getName());
}
}
Aggregations