use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsRelationalDaoImplTest method testSyntheticGetTripAgencyIdsReferencingServiceId.
@Test
public void testSyntheticGetTripAgencyIdsReferencingServiceId() {
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
AgencyAndId serviceId = new AgencyAndId("C", "serviceId");
Trip tripA = new Trip();
tripA.setId(new AgencyAndId("A", "tripId"));
tripA.setServiceId(serviceId);
dao.saveEntity(tripA);
Trip tripB = new Trip();
tripB.setId(new AgencyAndId("B", "tripId"));
tripB.setServiceId(serviceId);
dao.saveEntity(tripB);
List<String> agencyIds = dao.getTripAgencyIdsReferencingServiceId(serviceId);
assertEquals(2, agencyIds.size());
assertTrue(agencyIds.contains("A"));
assertTrue(agencyIds.contains("B"));
}
use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.
the class EnsureDirectionIdExists method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
Collection<Trip> trips = dao.getAllTrips();
for (Trip trip : trips) {
if (trip.getDirectionId() != null) {
continue;
}
trip.setDirectionId(getDirectionForTrip(dao, trip));
dao.saveOrUpdateEntity(trip);
}
}
use of org.onebusaway.gtfs.model.Trip 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.Trip in project onebusaway-gtfs-modules by OneBusAway.
the class AnomalyCheckFutureTripCounts method getDateTripMap.
private Map<Date, Integer> getDateTripMap(GtfsMutableRelationalDao dao) {
Map<Date, Integer> dateTripMap = new HashMap<Date, Integer>();
for (Trip trip : dao.getAllTrips()) {
_log.debug(trip.toString());
// check for service
boolean hasCalDateException = false;
// are there calendar dates?
for (ServiceCalendarDate calDate : dao.getCalendarDatesForServiceId(trip.getServiceId())) {
// _log.info(calDate.toString());
Date date = constructDate(calDate.getDate());
if (dateTripMap.get(date) == null) {
dateTripMap.put(date, 1);
} else {
dateTripMap.put(date, dateTripMap.get(date) + 1);
}
}
// if there are no entries in calendarDates, check serviceCalendar
if (!hasCalDateException) {
ServiceCalendar servCal = dao.getCalendarForServiceId(trip.getServiceId());
if (servCal != null) {
// check for service using calendar
Date start = removeTime(servCal.getStartDate().getAsDate());
_log.info(start.toString());
Date end = removeTime(servCal.getEndDate().getAsDate());
_log.info(end.toString());
}
}
}
return dateTripMap;
}
use of org.onebusaway.gtfs.model.Trip in project onebusaway-gtfs-modules by OneBusAway.
the class UpdateTripIdById method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
// trips updated, array of mta_ids that we've updated
HashMap<String, Trip> tripsUpdated = new HashMap<>();
// trips to remove, list of trips that have duplicate mta_ids
ArrayList<Trip> tripsToRemove = new ArrayList<>();
_log.info("Total dao {}", dao.getAllTrips().size());
_log.info("Stop times: {}", dao.getAllStopTimes().size());
for (Trip trip : dao.getAllTrips()) {
if (trip.getMtaTripId() != null) {
if (tripsUpdated.containsKey(trip.getMtaTripId())) {
tripsToRemove.add(trip);
for (StopTime stopTime : dao.getStopTimesForTrip(trip)) {
stopTime.setTrip(tripsUpdated.get(trip.getMtaTripId()));
}
} else {
tripsUpdated.put(trip.getMtaTripId(), trip);
trip.setId(new AgencyAndId(trip.getId().getAgencyId(), trip.getMtaTripId()));
}
}
}
for (Trip tripToRemove : tripsToRemove) {
// removeEntityLibrary.removeTrip(dao, tripToRemove);
dao.removeEntity(tripToRemove);
}
_log.info("Total dao {}", dao.getAllTrips().size());
_log.info("Stop times: {}", dao.getAllStopTimes().size());
}
Aggregations