Search in sources :

Example 1 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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 BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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 3 with BlockTripEntry

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

the class TripStopTimesBeanServiceImpl method getStopTimesForBlockTrip.

@Override
public TripStopTimesBean getStopTimesForBlockTrip(BlockTripInstance blockTripInstance) {
    BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
    TripStopTimesBean bean = getStopTimesForTrip(blockTrip.getTrip());
    if (blockTrip.getPreviousTrip() != null) {
        BlockTripEntry previous = blockTrip.getPreviousTrip();
        TripBean previousTrip = _tripBeanService.getTripForId(previous.getTrip().getId());
        bean.setPreviousTrip(previousTrip);
    }
    if (blockTrip.getNextTrip() != null) {
        BlockTripEntry next = blockTrip.getNextTrip();
        TripBean nextTrip = _tripBeanService.getTripForId(next.getTrip().getId());
        bean.setNextTrip(nextTrip);
    }
    FrequencyEntry frequencyLabel = blockTripInstance.getFrequencyLabel();
    if (frequencyLabel != null) {
        long serviceDate = blockTripInstance.getServiceDate();
        FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
        bean.setFrequency(fb);
    }
    return bean;
}
Also used : FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) 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) TripStopTimesBean(org.onebusaway.transit_data.model.TripStopTimesBean)

Example 4 with BlockTripEntry

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

the class BlockCalendarServiceImpl method findBlockTripsInRange.

private void findBlockTripsInRange(ServiceIntervalBlock intervals, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, Collection<BlockInstance> instances) {
    int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
    int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
    int indexFrom = index(Arrays.binarySearch(intervals.getMaxDepartures(), scheduledTimeFrom));
    int indexTo = index(Arrays.binarySearch(intervals.getMinArrivals(), scheduledTimeTo));
    InstanceState state = new InstanceState(serviceDate.getTime());
    for (int in = indexFrom; in < indexTo; in++) {
        BlockTripEntry trip = trips.get(in);
        BlockConfigurationEntry block = trip.getBlockConfiguration();
        BlockInstance instance = new BlockInstance(block, state);
        instances.add(instance);
    }
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 5 with BlockTripEntry

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

the class BlockCalendarServiceImpl method handleBlockIndex.

private Collection<BlockInstance> handleBlockIndex(BlockTripIndex index, Date timeFrom, Date timeTo, Collection<BlockInstance> instances) {
    List<BlockTripEntry> trips = index.getTrips();
    ServiceIntervalBlock serviceIntervalBlock = index.getServiceIntervalBlock();
    ServiceInterval serviceInterval = serviceIntervalBlock.getRange();
    Collection<Date> serviceDates = _calendarService.getServiceDatesWithinRange(index.getServiceIds(), serviceInterval, timeFrom, timeTo);
    for (Date serviceDate : serviceDates) {
        findBlockTripsInRange(serviceIntervalBlock, serviceDate, timeFrom, timeTo, trips, instances);
    }
    return instances;
}
Also used : ServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock) FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ServiceInterval(org.onebusaway.gtfs.model.calendar.ServiceInterval) Date(java.util.Date)

Aggregations

BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)72 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)30 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)27 ArrayList (java.util.ArrayList)26 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)25 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 List (java.util.List)11 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)10 FactoryMap (org.onebusaway.collections.FactoryMap)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)7 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)7 Date (java.util.Date)6 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)6 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)5 StopSequence (org.onebusaway.transit_data_federation.model.StopSequence)5