Search in sources :

Example 1 with TripEntry

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

the class StopScheduleBeanServiceImpl method groupStopTimeInstancesByRouteCollectionId.

private void groupStopTimeInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> stopTimesByRouteCollectionId, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
    Map<AgencyAndId, Set<FrequencyEntry>> frequencyLabelsByRouteCollectionId = new FactoryMap<AgencyAndId, Set<FrequencyEntry>>(new HashSet<FrequencyEntry>());
    for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) {
        ServiceIdActivation serviceIds = index.getServiceIds();
        Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
        if (!serviceDates.contains(date))
            continue;
        Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
        for (BlockStopTimeEntry stopTime : index.getStopTimes()) {
            BlockTripEntry blockTrip = stopTime.getTrip();
            TripEntry trip = blockTrip.getTrip();
            AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
            FrequencyEntry frequencyLabel = trip.getFrequencyLabel();
            InstanceState state = new InstanceState(serviceDate.getTime(), frequencyLabel);
            StopTimeInstance sti = new StopTimeInstance(stopTime, state);
            if (frequencyLabel == null) {
                stopTimesByRouteCollectionId.get(routeCollectionId).add(sti);
            } else if (frequencyLabelsByRouteCollectionId.get(routeCollectionId).add(frequencyLabel)) {
                frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
            }
        }
    }
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Set(java.util.Set) HashSet(java.util.HashSet) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 2 with TripEntry

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

the class TripBeanServiceImpl method getTripForId.

@Cacheable
public TripBean getTripForId(AgencyAndId tripId) {
    TripEntry tripEntry = _graph.getTripEntryForId(tripId);
    if (tripEntry == null)
        return null;
    AgencyAndId routeId = tripEntry.getRouteCollection().getId();
    RouteBean routeBean = _routeBeanService.getRouteForId(routeId);
    TripNarrative tripNarrative = _narrativeService.getTripForId(tripId);
    TripBean tripBean = new TripBean();
    tripBean.setId(ApplicationBeanLibrary.getId(tripId));
    tripBean.setTripShortName(tripNarrative.getTripShortName());
    tripBean.setTripHeadsign(tripNarrative.getTripHeadsign());
    tripBean.setRoute(routeBean);
    tripBean.setRouteShortName(tripNarrative.getRouteShortName());
    tripBean.setServiceId(ApplicationBeanLibrary.getId(tripEntry.getServiceId().getId()));
    AgencyAndId shapeId = tripEntry.getShapeId();
    if (shapeId != null && shapeId.hasValues())
        tripBean.setShapeId(ApplicationBeanLibrary.getId(shapeId));
    tripBean.setDirectionId(tripEntry.getDirectionId());
    tripBean.setTotalTripDistance(tripEntry.getTotalTripDistance());
    BlockEntry block = tripEntry.getBlock();
    tripBean.setBlockId(ApplicationBeanLibrary.getId(block.getId()));
    return tripBean;
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 3 with TripEntry

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

the class TripStatusBeanServiceImpl method getTripEntryAndBlockLocationAsTripDetails.

private TripDetailsBean getTripEntryAndBlockLocationAsTripDetails(BlockTripInstance blockTripInstance, BlockLocation blockLocation, TripDetailsInclusionBean inclusion, long time) {
    TripBean trip = null;
    long serviceDate = blockTripInstance.getServiceDate();
    FrequencyBean frequency = null;
    TripStopTimesBean stopTimes = null;
    TripStatusBean status = null;
    AgencyAndId vehicleId = null;
    boolean missing = false;
    FrequencyEntry frequencyLabel = blockTripInstance.getFrequencyLabel();
    if (frequencyLabel != null) {
        frequency = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
    }
    BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
    TripEntry tripEntry = blockTrip.getTrip();
    if (inclusion.isIncludeTripBean()) {
        trip = _tripBeanService.getTripForId(tripEntry.getId());
        if (trip == null)
            missing = true;
    }
    if (inclusion.isIncludeTripSchedule()) {
        stopTimes = _tripStopTimesBeanService.getStopTimesForBlockTrip(blockTripInstance);
        if (stopTimes == null)
            missing = true;
    }
    if (inclusion.isIncludeTripStatus() && blockLocation != null) {
        status = getBlockLocationAsStatusBean(blockLocation, time);
        if (status == null)
            missing = true;
        else
            vehicleId = AgencyAndIdLibrary.convertFromString(status.getVehicleId());
    }
    List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, blockTripInstance, vehicleId);
    if (missing)
        return null;
    String tripId = AgencyAndIdLibrary.convertToString(tripEntry.getId());
    TripDetailsBean bean = new TripDetailsBean();
    bean.setTripId(tripId);
    bean.setServiceDate(serviceDate);
    bean.setFrequency(frequency);
    bean.setTrip(trip);
    bean.setSchedule(stopTimes);
    bean.setStatus(status);
    bean.setSituations(situations);
    return bean;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean)

Example 4 with TripEntry

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

the class TripStatusBeanServiceImpl method getTripsForId.

@Override
public ListBean<TripDetailsBean> getTripsForId(TripDetailsQueryBean query) {
    AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(query.getTripId());
    long serviceDate = query.getServiceDate();
    AgencyAndId vehicleId = AgencyAndIdLibrary.convertFromString(query.getVehicleId());
    long time = query.getTime();
    TripEntry tripEntry = _transitGraphDao.getTripEntryForId(tripId);
    if (tripEntry == null)
        return new ListBean<TripDetailsBean>();
    Map<BlockInstance, List<BlockLocation>> locationsByInstance = _blockStatusService.getBlocks(tripEntry.getBlock().getId(), serviceDate, vehicleId, time);
    List<TripDetailsBean> tripDetails = new ArrayList<TripDetailsBean>();
    for (Map.Entry<BlockInstance, List<BlockLocation>> entry : locationsByInstance.entrySet()) {
        BlockInstance blockInstance = entry.getKey();
        List<BlockLocation> locations = entry.getValue();
        BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstance, tripId);
        if (blockTripInstance == null)
            throw new IllegalStateException("expected blockTrip for trip=" + tripEntry + " and block=" + blockInstance);
        /**
         * If we have no locations for the specified block instance, it means the
         * block is not currently active. But we can still attempt to construct a
         * trip details
         */
        if (locations.isEmpty()) {
            TripDetailsBean details = getTripEntryAndBlockLocationAsTripDetails(blockTripInstance, null, query.getInclusion(), time);
            tripDetails.add(details);
        } else {
            for (BlockLocation location : locations) {
                TripDetailsBean details = getBlockLocationAsTripDetails(blockTripInstance, location, query.getInclusion(), time);
                tripDetails.add(details);
            }
        }
    }
    return new ListBean<TripDetailsBean>(tripDetails, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) 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) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean)

Example 5 with TripEntry

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

the class BlockGeospatialServiceImpl method groupBlockSequenceIndicesByShapeIds.

/**
 **
 * Private Methods
 ***
 */
private void groupBlockSequenceIndicesByShapeIds() {
    List<BlockSequenceIndex> indices = _blockIndexService.getAllBlockSequenceIndices();
    for (BlockSequenceIndex index : indices) {
        Set<AgencyAndId> shapeIdsForIndex = new HashSet<AgencyAndId>();
        for (BlockSequence sequence : index.getSequences()) {
            for (BlockStopTimeEntry bst : sequence.getStopTimes()) {
                BlockTripEntry blockTrip = bst.getTrip();
                TripEntry trip = blockTrip.getTrip();
                AgencyAndId shapeId = trip.getShapeId();
                if (shapeId != null)
                    shapeIdsForIndex.add(shapeId);
            }
        }
        for (AgencyAndId shapeId : shapeIdsForIndex) {
            List<BlockSequenceIndex> list = _blockSequenceIndicesByShapeId.get(shapeId);
            if (list == null) {
                list = new ArrayList<BlockSequenceIndex>();
                _blockSequenceIndicesByShapeId.put(shapeId, list);
            }
            list.add(index);
        }
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) HashSet(java.util.HashSet)

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