Search in sources :

Example 46 with Trip

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"));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 47 with Trip

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);
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip)

Example 48 with 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);
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route)

Example 49 with Trip

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;
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 50 with Trip

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());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StopTime(org.onebusaway.gtfs.model.StopTime)

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10