Search in sources :

Example 46 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class UnitTestingSupport method trip.

public static TripEntryImpl trip(String id, String serviceId, double totalTripDistance) {
    TripEntryImpl trip = trip(id, serviceId);
    trip.setTotalTripDistance(totalTripDistance);
    return trip;
}
Also used : TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockTripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockTripEntryImpl)

Example 47 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class BlockConfigurationEntriesFactory method getTripsByServiceId.

/**
 **
 * Private Methods
 ***
 */
private Map<LocalizedServiceId, List<TripEntryImpl>> getTripsByServiceId(BlockEntryImpl block, List<TripEntryImpl> tripsInBlock) {
    Map<LocalizedServiceId, List<TripEntryImpl>> tripsByServiceId = new FactoryMap<LocalizedServiceId, List<TripEntryImpl>>(new ArrayList<TripEntryImpl>());
    TimeZone tz = null;
    for (TripEntryImpl trip : tripsInBlock) {
        LocalizedServiceId serviceId = trip.getServiceId();
        if (tz == null) {
            tz = serviceId.getTimeZone();
        } else if (!tz.equals(serviceId.getTimeZone())) {
            throw new IllegalStateException("trips in block must all have same timezone: block=" + block + " trip=" + trip + " execpted=" + tz + " actual=" + serviceId.getTimeZone());
        }
        tripsByServiceId.get(serviceId).add(trip);
    }
    return tripsByServiceId;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) TimeZone(java.util.TimeZone) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) ArrayList(java.util.ArrayList) List(java.util.List) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)

Example 48 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class BlockEntriesFactory method getTripsByBlockId.

private Map<AgencyAndId, List<TripEntryImpl>> getTripsByBlockId(TransitGraphImpl graph) {
    Collection<Route> routes = _gtfsDao.getAllRoutes();
    int routeIndex = 0;
    Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId = new FactoryMap<AgencyAndId, List<TripEntryImpl>>(new ArrayList<TripEntryImpl>());
    for (Route route : routes) {
        _log.info("routes: " + (routeIndex++) + "/" + routes.size());
        List<Trip> trips = _gtfsDao.getTripsForRoute(route);
        for (Trip trip : trips) {
            TripEntryImpl tripEntry = graph.getTripEntryForId(trip.getId());
            // prune the trip
            if (tripEntry == null)
                continue;
            /*
         * here we default the blockId to the tripId
         */
            AgencyAndId blockId = trip.getId();
            if (trip.getBlockId() != null) {
                /*
           * he have a block so set it
           */
                blockId = new AgencyAndId(trip.getId().getAgencyId(), trip.getBlockId());
            }
            tripsByBlockId.get(blockId).add(tripEntry);
        }
    }
    return tripsByBlockId;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) List(java.util.List) Route(org.onebusaway.gtfs.model.Route) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)

Example 49 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class DistanceAlongShapeLibrary method constructErrorForPotentialAssignmentCount.

private void constructErrorForPotentialAssignmentCount(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, long count) throws InvalidStopToShapeMappingException {
    if (count == 0) {
        _log.error("We were attempting to compute the distance along a particular trip for each stop time of that " + "trip by snapping them to the shape for that trip.  However, we could not find an assignment for each " + "stop time of the trip, which usually indicates that there is something wrong with the underlying " + "shape data.  For more information on errors of this kind, see:\n" + "  https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
    } else {
        _log.error("We were attempting to compute the distance along a particular trip for each stop time of that " + "trip by snapping them to the shape for that trip.  However, we found WAY TOO MANY potential " + "assignments, which usually indicates that there is something wrong with the underlying shape data.  " + "For more information on errors of this kind, see:\n" + "  https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
    }
    StopTimeEntryImpl first = stopTimes.get(0);
    TripEntryImpl trip = first.getTrip();
    StopTimeEntryImpl last = stopTimes.get(stopTimes.size() - 1);
    _log.error("error constructing stop-time distances along shape for trip=" + trip.getId() + " shape=" + trip.getShapeId() + " firstStopTime=" + first.getId() + " lastStopTime=" + last.getId());
    if (_shapeIdsWeHavePrinted.add(trip.getShapeId())) {
        StringBuilder b = new StringBuilder();
        for (int i = 0; i < shapePoints.getSize(); i++) {
            b.append(shapePoints.getLatForIndex(i));
            b.append(' ');
            b.append(shapePoints.getLonForIndex(i));
            b.append(' ');
            b.append(shapePoints.getDistTraveledForIndex(i));
            b.append('\n');
        }
        _log.error("shape points:\n" + b.toString());
    }
    throw new InvalidStopToShapeMappingException(first.getTrip());
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint)

Example 50 with TripEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.

the class FrequencyEntriesFactory method processFrequencies.

public void processFrequencies(TransitGraphImpl graph) {
    Map<AgencyAndId, List<FrequencyEntry>> frequenciesByTripId = new HashMap<AgencyAndId, List<FrequencyEntry>>();
    Collection<Frequency> allFrequencies = _gtfsDao.getAllFrequencies();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allFrequencies.size());
    int frequencyIndex = 0;
    Map<AgencyAndId, Integer> exactTimesValueByTrip = new HashMap<AgencyAndId, Integer>();
    for (Frequency frequency : allFrequencies) {
        if (frequencyIndex % logInterval == 0)
            _log.info("frequencies: " + (frequencyIndex++) + "/" + allFrequencies.size());
        frequencyIndex++;
        processRawFrequency(graph, frequency, frequenciesByTripId, exactTimesValueByTrip);
    }
    FrequencyComparator comparator = new FrequencyComparator();
    for (List<FrequencyEntry> list : frequenciesByTripId.values()) {
        Collections.sort(list, comparator);
    }
    int blockIndex = 0;
    Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId = MappingLibrary.mapToValueList(graph.getTrips(), "block.id");
    for (Map.Entry<AgencyAndId, List<TripEntryImpl>> entry : tripsByBlockId.entrySet()) {
        if (blockIndex % 10 == 0)
            _log.info("block: " + blockIndex + "/" + tripsByBlockId.size());
        blockIndex++;
        AgencyAndId blockId = entry.getKey();
        List<TripEntryImpl> tripsInBlock = entry.getValue();
        Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlockByTripId = new HashMap<AgencyAndId, List<FrequencyEntry>>();
        for (TripEntryImpl trip : tripsInBlock) {
            List<FrequencyEntry> frequencies = frequenciesByTripId.get(trip.getId());
            if (frequencies != null) {
                frequenciesAlongBlockByTripId.put(trip.getId(), frequencies);
            }
        }
        checkForInvalidFrequencyConfigurations(blockId, tripsInBlock, frequenciesAlongBlockByTripId);
        applyFrequenciesToBlockTrips(tripsInBlock, frequenciesAlongBlockByTripId);
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Frequency(org.onebusaway.gtfs.model.Frequency) ArrayList(java.util.ArrayList) List(java.util.List) FrequencyComparator(org.onebusaway.transit_data_federation.impl.blocks.FrequencyComparator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)58 Test (org.junit.Test)43 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)29 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)22 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)20 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)14 Trip (org.onebusaway.gtfs.model.Trip)10 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)10 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)10 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 ArrayList (java.util.ArrayList)9 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)8 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)7 Route (org.onebusaway.gtfs.model.Route)6 Stop (org.onebusaway.gtfs.model.Stop)6 StopTime (org.onebusaway.gtfs.model.StopTime)6