Search in sources :

Example 71 with BlockConfigurationEntry

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

the class BlockCalendarServiceImpl method findFrequencyBlockTripsInRange.

private void findFrequencyBlockTripsInRange(FrequencyServiceIntervalBlock serviceIntervalIndex, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, List<FrequencyEntry> frequencies, Collection<BlockInstance> instances) {
    int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
    int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
    int indexFrom = index(Arrays.binarySearch(serviceIntervalIndex.getEndTimes(), scheduledTimeFrom));
    int indexTo = index(Arrays.binarySearch(serviceIntervalIndex.getStartTimes(), scheduledTimeTo));
    for (int in = indexFrom; in < indexTo; in++) {
        BlockTripEntry trip = trips.get(in);
        BlockConfigurationEntry block = trip.getBlockConfiguration();
        FrequencyEntry frequency = frequencies.get(in);
        InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
        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) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 72 with BlockConfigurationEntry

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

the class BlockCalendarServiceImpl method getClosestActiveBlocks.

@Override
public List<BlockInstance> getClosestActiveBlocks(AgencyAndId blockId, long time) {
    Date timeAsDate = new Date(time);
    Min<BlockInstance> m = new Min<BlockInstance>();
    BlockEntry blockEntry = _transitGraphDao.getBlockEntryForId(blockId);
    for (BlockConfigurationEntry blockConfig : blockEntry.getConfigurations()) {
        List<Date> serviceDates = _calendarService.getDatesForServiceIdsAsOrderedList(blockConfig.getServiceIds());
        int index = index(Collections.binarySearch(serviceDates, timeAsDate));
        if (index > 0) {
            BlockInstance instance = new BlockInstance(blockConfig, serviceDates.get(index - 1).getTime());
            long delta = getTimeToBlockInstance(instance, time);
            m.add(delta, instance);
        }
        if (index < serviceDates.size()) {
            BlockInstance instance = new BlockInstance(blockConfig, serviceDates.get(index).getTime());
            long delta = getTimeToBlockInstance(instance, time);
            m.add(delta, instance);
        }
    }
    return m.getMinElements();
}
Also used : Min(org.onebusaway.collections.Min) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date)

Example 73 with BlockConfigurationEntry

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

the class BlockCalendarServiceImpl method findBlockLayoversInRange.

private void findBlockLayoversInRange(LayoverIntervalBlock 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.getEndTimes(), scheduledTimeFrom));
    int indexTo = index(Arrays.binarySearch(intervals.getStartTimes(), 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 74 with BlockConfigurationEntry

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

the class BlockGeospatialServiceImpl method getActiveScheduledBlocksPassingThroughBounds.

@Override
public List<BlockInstance> getActiveScheduledBlocksPassingThroughBounds(CoordinateBounds bounds, long timeFrom, long timeTo) {
    List<StopEntry> stops = _transitGraphDao.getStopsByLocation(bounds);
    Set<AgencyAndId> blockIds = new HashSet<AgencyAndId>();
    for (StopEntry stop : stops) {
        List<BlockStopTimeIndex> stopTimeIndices = _blockIndexService.getStopTimeIndicesForStop(stop);
        Set<BlockConfigurationEntry> blockConfigs = new HashSet<BlockConfigurationEntry>();
        List<List<BlockConfigurationEntry>> blockConfigsList = MappingLibrary.map(stopTimeIndices, "blockConfigs");
        for (List<BlockConfigurationEntry> l : blockConfigsList) {
            blockConfigs.addAll(l);
        }
        List<AgencyAndId> stopBlockIds = MappingLibrary.map(blockConfigs, "block.id");
        blockIds.addAll(stopBlockIds);
    }
    Set<BlockTripIndex> blockIndices = new HashSet<BlockTripIndex>();
    for (AgencyAndId blockId : blockIds) {
        blockIndices.addAll(_blockIndexService.getBlockTripIndicesForBlock(blockId));
    }
    List<BlockLayoverIndex> layoverIndices = Collections.emptyList();
    List<FrequencyBlockTripIndex> frequencyIndices = Collections.emptyList();
    return _blockCalendarService.getActiveBlocksInTimeRange(blockIndices, layoverIndices, frequencyIndices, timeFrom, timeTo);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockLayoverIndex(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) List(java.util.List) ArrayList(java.util.ArrayList) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) HashSet(java.util.HashSet)

Example 75 with BlockConfigurationEntry

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

the class BlockLocationServiceImpl method getScheduledBlockLocationForBlockInstance.

private ScheduledBlockLocation getScheduledBlockLocationForBlockInstance(BlockInstance blockInstance, long targetTime) {
    BlockConfigurationEntry blockConfig = blockInstance.getBlock();
    long serviceDate = blockInstance.getServiceDate();
    int scheduledTime = (int) ((targetTime - serviceDate) / 1000);
    return _scheduledBlockLocationService.getScheduledBlockLocationFromScheduledTime(blockConfig, scheduledTime);
}
Also used : BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Aggregations

BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)89 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)36 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 Test (org.junit.Test)30 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)29 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)27 ArrayList (java.util.ArrayList)23 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)23 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)17 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)14 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)13 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)13 Date (java.util.Date)12 List (java.util.List)11 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)10 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)8 FactoryMap (org.onebusaway.collections.FactoryMap)8