Search in sources :

Example 6 with ServiceIntervalBlock

use of org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock in project onebusaway-application-modules by camsys.

the class BlockStatusServiceImpl method getBlockInstancesForIndexAndTimestamps.

private List<BlockInstance> getBlockInstancesForIndexAndTimestamps(BlockSequenceIndex index, List<Date> timestamps) {
    Date tFrom = timestamps.get(0);
    Date tTo = timestamps.get(timestamps.size() - 1);
    ServiceIntervalBlock serviceIntervalBlock = index.getServiceIntervalBlock();
    List<BlockSequence> sequences = index.getSequences();
    Collection<Date> serviceDates = _extendedCalendarService.getServiceDatesWithinRange(index.getServiceIds(), serviceIntervalBlock.getRange(), tFrom, tTo);
    List<BlockInstance> instances = new ArrayList<BlockInstance>();
    for (Date serviceDate : serviceDates) {
        int effectiveFromTime = (int) ((tFrom.getTime() - serviceDate.getTime()) / 1000);
        int effectiveToTime = (int) ((tTo.getTime() - serviceDate.getTime()) / 1000);
        int indexFrom = Arrays.binarySearch(serviceIntervalBlock.getMaxArrivals(), effectiveFromTime);
        int indexTo = Arrays.binarySearch(serviceIntervalBlock.getMinDepartures(), effectiveToTime);
        if (indexFrom < 0)
            indexFrom = -(indexFrom + 1);
        if (indexTo < 0)
            indexTo = -(indexTo + 1);
        InstanceState state = new InstanceState(serviceDate.getTime());
        for (int i = indexFrom; i < indexTo; i++) {
            BlockSequence sequence = sequences.get(i);
            BlockConfigurationEntry blockConfig = sequence.getBlockConfig();
            BlockInstance instance = new BlockInstance(blockConfig, state);
            instances.add(instance);
        }
    }
    return instances;
}
Also used : ServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Aggregations

ServiceIntervalBlock (org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock)6 FrequencyServiceIntervalBlock (org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)2 BlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex)2 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)2 Test (org.junit.Test)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)1 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)1 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)1 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)1 BlockLayoverIndex (org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex)1 BlockSequenceIndex (org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex)1 BlockTripIndexData (org.onebusaway.transit_data_federation.services.blocks.BlockTripIndexData)1 BlockTripReference (org.onebusaway.transit_data_federation.services.blocks.BlockTripReference)1 FrequencyBlockTripIndexData (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndexData)1 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)1