Search in sources :

Example 26 with TripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.

the class GtfsController method getRoute.

/* Expose shape points for route */
@RequestMapping(value = "/route/{agencyId}/{id}")
@ResponseBody
public ShapePoints getRoute(@PathVariable String agencyId, @PathVariable String id) {
    AgencyAndId routeId = new AgencyAndId(agencyId, id);
    RouteEntry route = _transitGraphDao.getRouteForId(routeId);
    // BAD - just uses first trip.
    TripEntry trip = routeToTrip(route);
    AgencyAndId shapeId = trip.getShapeId();
    return _shapePointService.getShapePointsForShapeId(shapeId);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 27 with TripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.

the class GtfsRealtimeEntitySource method getTrip.

public TripEntry getTrip(String tripId) {
    for (String agencyId : _agencyIds) {
        AgencyAndId id = new AgencyAndId(agencyId, tripId);
        TripEntry trip = _transitGraphDao.getTripEntryForId(id);
        if (trip != null)
            return trip;
    }
    try {
        AgencyAndId id = AgencyAndId.convertFromString(tripId);
        TripEntry trip = _transitGraphDao.getTripEntryForId(id);
        if (trip != null)
            return trip;
    } catch (IllegalArgumentException ex) {
    }
    return null;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 28 with TripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.

the class FeedServiceImpl method addAgencyIdToTripId.

private HasTripId addAgencyIdToTripId(HasTripId entity, String agencyId, GtfsRealtimeEntitySource entitySource) {
    if (StringUtils.isNotBlank(entity.getTripId())) {
        String tripId = entity.getTripId();
        if (agencyId.length() > 0) {
            entity.setTripId(new AgencyAndId(agencyId, tripId).toString());
        } else {
            // Look for the agency which has a match for this trip id
            TripEntry trip = entitySource.getTrip(entity.getTripId());
            if (trip == null) {
                _log.debug("No match found for trip: " + entity.getTripId());
            } else {
                entity.setTripId(trip.getId().toString());
                agencyId = trip.getId().getAgencyId();
            }
        }
    }
    return entity;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 29 with TripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.

the class AgencyServiceImpl method getAgencyIdsAndCoverageAreas.

@Cacheable
public Map<String, CoordinateBounds> getAgencyIdsAndCoverageAreas() {
    Map<String, CoordinateBounds> boundsByAgencyId = new HashMap<String, CoordinateBounds>();
    for (AgencyEntry agency : _graph.getAllAgencies()) {
        CoordinateBounds bounds = new CoordinateBounds();
        for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
            for (RouteEntry route : routeCollection.getChildren()) {
                for (TripEntry trip : route.getTrips()) {
                    for (StopTimeEntry stopTime : trip.getStopTimes()) {
                        StopEntry stop = stopTime.getStop();
                        bounds.addPoint(stop.getStopLat(), stop.getStopLon());
                    }
                }
            }
        }
        boundsByAgencyId.put(agency.getId(), bounds);
    }
    return boundsByAgencyId;
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) HashMap(java.util.HashMap) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 30 with TripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImpl method getArrivalAndDepartureForStop.

@Override
public ArrivalAndDepartureInstance getArrivalAndDepartureForStop(ArrivalAndDepartureQuery query) {
    StopEntry stop = query.getStop();
    int stopSequence = query.getStopSequence();
    TripEntry trip = query.getTrip();
    long serviceDate = query.getServiceDate();
    AgencyAndId vehicleId = query.getVehicleId();
    long time = query.getTime();
    Map<BlockInstance, List<BlockLocation>> locationsByInstance = _blockStatusService.getBlocks(trip.getBlock().getId(), serviceDate, vehicleId, time);
    if (locationsByInstance.isEmpty())
        return null;
    Map.Entry<BlockInstance, List<BlockLocation>> entry = locationsByInstance.entrySet().iterator().next();
    BlockInstance blockInstance = entry.getKey();
    List<BlockLocation> locations = entry.getValue();
    int timeOfServiceDate = (int) ((time - serviceDate) / 1000);
    ArrivalAndDepartureInstance instance = createArrivalAndDeparture(blockInstance, trip.getId(), stop.getId(), stopSequence, serviceDate, timeOfServiceDate, time);
    if (!locations.isEmpty()) {
        /**
         * What if there are multiple locations? Pick the first?
         */
        BlockLocation location = locations.get(0);
        applyBlockLocationToInstance(instance, location, time);
    }
    return instance;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ArrayList(java.util.ArrayList) List(java.util.List) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Aggregations

TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)73 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)39 ArrayList (java.util.ArrayList)20 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)18 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)14 HashSet (java.util.HashSet)13 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)10 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)10 List (java.util.List)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)9 Date (java.util.Date)7 Test (org.junit.Test)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)7 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)7 Cacheable (org.onebusaway.container.cache.Cacheable)6 RouteEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6