Search in sources :

Example 31 with TripEntry

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

the class ArrivalAndDepartureServiceImpl method getBlockStopTime.

private BlockStopTimeEntry getBlockStopTime(BlockTripInstance blockTripInstance, AgencyAndId stopId, int stopSequence, int timeOfServiceDate) {
    /**
     * We don't iterate over block stop times directly because there is
     * performance penalty with instantiating each. Also note that this will
     * currently miss the case where a stop is visited twice in the same trip.
     */
    BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
    TripEntry trip = blockTrip.getTrip();
    List<StopTimeEntry> stopTimes = trip.getStopTimes();
    if (stopSequence > -1) {
        /**
         * If a stop sequence has been specified, we start our search at the
         * specified index, expanding our search until we find the target stop. We
         * allow this flexibility in the case of a bookmarked arrival-departure
         * where the stop sequence has changed slightly due to the addition or
         * subtraction of a previous stop.
         */
        int offset = 0;
        while (true) {
            int before = stopSequence - offset;
            if (isMatch(stopTimes, stopId, before)) {
                return blockTrip.getStopTimes().get(before);
            }
            int after = stopSequence + offset;
            if (isMatch(stopTimes, stopId, after)) {
                return blockTrip.getStopTimes().get(after);
            }
            if (before < 0 && after >= stopTimes.size())
                return null;
            offset++;
        }
    } else {
        Min<BlockStopTimeEntry> m = new Min<BlockStopTimeEntry>();
        int index = 0;
        for (StopTimeEntry stopTime : stopTimes) {
            if (stopTime.getStop().getId().equals(stopId)) {
                int a = Math.abs(timeOfServiceDate - stopTime.getArrivalTime());
                int b = Math.abs(timeOfServiceDate - stopTime.getDepartureTime());
                int delta = Math.min(a, b);
                m.add(delta, blockTrip.getStopTimes().get(index));
            }
            index++;
        }
        if (m.isEmpty())
            return null;
        return m.getMinElement();
    }
}
Also used : Min(org.onebusaway.collections.Min) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) 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)

Example 32 with TripEntry

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

the class BlockConfigurationEntriesFactory method processTripsForServiceIdConfiguration.

private BlockConfigurationEntryImpl.Builder processTripsForServiceIdConfiguration(BlockEntryImpl block, Map<LocalizedServiceId, List<TripEntryImpl>> tripsByServiceId, ServiceIdActivation serviceIds) {
    ArrayList<TripEntry> trips = new ArrayList<TripEntry>();
    for (LocalizedServiceId serviceId : serviceIds.getActiveServiceIds()) {
        trips.addAll(tripsByServiceId.get(serviceId));
    }
    Collections.sort(trips, _blockTripComparator);
    trips.trimToSize();
    double[] tripGapDistances = computeGapDistancesBetweenTrips(trips);
    BlockConfigurationEntryImpl.Builder builder = BlockConfigurationEntryImpl.builder();
    builder.setBlock(block);
    builder.setServiceIds(serviceIds);
    builder.setTrips(trips);
    builder.setTripGapDistances(tripGapDistances);
    return builder;
}
Also used : LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) ArrayList(java.util.ArrayList) BlockConfigurationEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 33 with TripEntry

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

the class BlockConfigurationEntriesFactory method computeGapDistancesBetweenTrips.

private double[] computeGapDistancesBetweenTrips(List<TripEntry> trips) {
    double[] tripGapDistances = new double[trips.size()];
    if (_shapePointHelper == null)
        return tripGapDistances;
    for (int index = 0; index < trips.size() - 1; index++) {
        TripEntry tripA = trips.get(index);
        TripEntry tripB = trips.get(index + 1);
        double d = 0;
        ShapePoints shapeFrom = _shapePointHelper.getShapePointsForShapeId(tripA.getShapeId());
        ShapePoints shapeTo = _shapePointHelper.getShapePointsForShapeId(tripB.getShapeId());
        if (shapeFrom != null && shapeTo != null && !shapeFrom.isEmpty() && !shapeTo.isEmpty()) {
            int n = shapeFrom.getSize();
            double lat1 = shapeFrom.getLatForIndex(n - 1);
            double lon1 = shapeFrom.getLonForIndex(n - 1);
            double lat2 = shapeTo.getLatForIndex(0);
            double lon2 = shapeTo.getLonForIndex(0);
            d = SphericalGeometryLibrary.distance(lat1, lon1, lat2, lon2);
        }
        tripGapDistances[index] = d;
    }
    return tripGapDistances;
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)

Example 34 with TripEntry

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

the class FrequencyEntriesFactory method computeBlockFrequencies.

private List<FrequencyEntry> computeBlockFrequencies(BlockEntryImpl block, List<BlockTripEntry> trips, Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlock) {
    List<FrequencyEntry> frequencies = null;
    for (BlockTripEntry blockTrip : trips) {
        TripEntry trip = blockTrip.getTrip();
        List<FrequencyEntry> potentialFrequencies = frequenciesAlongBlock.get(trip.getId());
        if (frequencies == null) {
            frequencies = potentialFrequencies;
        } else {
            if (!frequencies.equals(potentialFrequencies)) {
                throw new IllegalStateException("frequency-based trips in same block don't have same frequencies: blockId=" + block.getId());
            }
        }
    }
    return frequencies;
}
Also used : 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)

Example 35 with TripEntry

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

the class RouteServiceImpl method getStopsForRouteCollection.

@Override
@Cacheable
public Collection<AgencyAndId> getStopsForRouteCollection(AgencyAndId id) {
    Set<AgencyAndId> stopIds = new HashSet<AgencyAndId>();
    RouteCollectionEntry routeCollectionEntry = _transitGraphDao.getRouteCollectionForId(id);
    for (RouteEntry route : routeCollectionEntry.getChildren()) {
        List<TripEntry> trips = route.getTrips();
        for (TripEntry trip : trips) {
            List<StopTimeEntry> stopTimes = trip.getStopTimes();
            for (StopTimeEntry stopTime : stopTimes) stopIds.add(stopTime.getStop().getId());
        }
    }
    return new ArrayList<AgencyAndId>(stopIds);
}
Also used : RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) ArrayList(java.util.ArrayList) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) HashSet(java.util.HashSet) Cacheable(org.onebusaway.container.cache.Cacheable)

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