Search in sources :

Example 61 with BlockInstance

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

the class BlockStatusBeanServiceImpl method bean.

private BlockStatusBean bean(BlockLocation blockLocation) {
    if (blockLocation == null)
        return null;
    BlockInstance instance = blockLocation.getBlockInstance();
    BlockConfigurationEntry block = instance.getBlock();
    long serviceDate = instance.getServiceDate();
    BlockStatusBean bean = new BlockStatusBean();
    bean.setBlock(_blockBeanService.getBlockForId(block.getBlock().getId()));
    bean.setStatus("default");
    bean.setServiceDate(serviceDate);
    bean.setTotalDistanceAlongBlock(block.getTotalBlockDistance());
    bean.setInService(blockLocation.isInService());
    CoordinatePoint location = blockLocation.getLocation();
    bean.setLocation(location);
    bean.setScheduledDistanceAlongBlock(blockLocation.getScheduledDistanceAlongBlock());
    bean.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
    BlockTripEntry activeTrip = blockLocation.getActiveTrip();
    if (activeTrip != null) {
        BlockTripBean activeTripBean = _blockBeanService.getBlockTripAsBean(activeTrip);
        bean.setActiveTrip(activeTripBean);
    }
    BlockStopTimeEntry stop = blockLocation.getClosestStop();
    if (stop != null) {
        StopBean stopBean = _stopBeanService.getStopForId(stop.getStopTime().getStop().getId());
        bean.setClosestStop(stopBean);
        bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
    }
    bean.setPredicted(blockLocation.isPredicted());
    bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
    bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
    AgencyAndId vid = blockLocation.getVehicleId();
    if (vid != null)
        bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
    return bean;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) BlockStatusBean(org.onebusaway.transit_data.model.blocks.BlockStatusBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) StopBean(org.onebusaway.transit_data.model.StopBean) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 62 with BlockInstance

use of org.onebusaway.transit_data_federation.services.blocks.BlockInstance 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)

Example 63 with BlockInstance

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

the class BlockStatusServiceImpl method getBlocksForBounds.

@Override
public List<BlockLocation> getBlocksForBounds(CoordinateBounds bounds, long time) {
    long timeFrom = time - _runningLateWindow * 1000;
    long timeTo = time + _runningEarlyWindow * 1000;
    List<BlockInstance> instances = _blockGeospatialService.getActiveScheduledBlocksPassingThroughBounds(bounds, timeFrom, timeTo);
    List<BlockLocation> locations = getAsLocations(instances, time);
    List<BlockLocation> inRange = new ArrayList<BlockLocation>();
    for (BlockLocation location : locations) {
        CoordinatePoint p = location.getLocation();
        if (p != null && bounds.contains(p))
            inRange.add(location);
    }
    return inRange;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrayList(java.util.ArrayList) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation)

Aggregations

BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)63 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)36 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)25 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)24 Test (org.junit.Test)20 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)20 ArrayList (java.util.ArrayList)19 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)19 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)16 Date (java.util.Date)15 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)12 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)12 List (java.util.List)11 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)10 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)10 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)10 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)9 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)9 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)9