Search in sources :

Example 11 with TargetTime

use of org.onebusaway.transit_data_federation.model.TargetTime in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.

/**
 **
 * {@link ArrivalsAndDeparturesBeanService} Interface
 ***
 */
@Override
public List<ArrivalAndDepartureBean> getArrivalsAndDeparturesByStopId(AgencyAndId stopId, ArrivalsAndDeparturesQueryBean query) {
    StopEntry stop = _transitGraphDao.getStopEntryForId(stopId, true);
    long time = query.getTime();
    int minutesBefore = Math.max(query.getMinutesBefore(), query.getFrequencyMinutesBefore());
    int minutesAfter = Math.max(query.getMinutesAfter(), query.getFrequencyMinutesAfter());
    long fromTime = time - minutesBefore * 60 * 1000;
    long toTime = time + minutesAfter * 60 * 1000;
    long nonFrequencyFromTime = time - query.getMinutesBefore() * 60 * 1000;
    long nonFrequencyToTime = time + query.getMinutesAfter() * 60 * 1000;
    long frequencyFromTime = time - query.getFrequencyMinutesBefore() * 60 * 1000;
    long frequencyToTime = time + query.getFrequencyMinutesAfter() * 60 * 1000;
    TargetTime target = new TargetTime(time, time);
    List<ArrivalAndDepartureInstance> instances = _arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(stop, target, fromTime, toTime);
    List<ArrivalAndDepartureBean> beans = new ArrayList<ArrivalAndDepartureBean>();
    Map<AgencyAndId, StopBean> stopBeanCache = new HashMap<AgencyAndId, StopBean>();
    for (ArrivalAndDepartureInstance instance : instances) {
        FrequencyEntry frequency = instance.getFrequency();
        long from = frequency != null ? frequencyFromTime : nonFrequencyFromTime;
        long to = frequency != null ? frequencyToTime : nonFrequencyToTime;
        if (!isArrivalAndDepartureInRange(instance, from, to))
            continue;
        ArrivalAndDepartureBean bean = getStopTimeInstanceAsBean(time, instance, stopBeanCache);
        applyBlockLocationToBean(instance, bean, time);
        Boolean isNegativeScheduledArrivalsEnabled = _gtfsRealtimeNegativeArrivals.getShowNegativeScheduledArrivalByAgencyId(instance.getBlockTrip().getTrip().getId().getAgencyId());
        if (isNegativeScheduledArrivalsEnabled != null && !isNegativeScheduledArrivalsEnabled && bean.getNumberOfStopsAway() < 0 && bean.getPredictedArrivalTime() <= 0)
            continue;
        applySituationsToBean(time, instance, bean);
        beans.add(bean);
    }
    Collections.sort(beans, new ArrivalAndDepartureComparator());
    return beans;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 12 with TargetTime

use of org.onebusaway.transit_data_federation.model.TargetTime in project onebusaway-application-modules by camsys.

the class VehicleStatusBeanServiceImpl method getVehicleLocationRecordForVehicleId.

@Override
public VehicleLocationRecordBean getVehicleLocationRecordForVehicleId(AgencyAndId vehicleId, long targetTime) {
    TargetTime target = new TargetTime(targetTime, targetTime);
    BlockLocation blockLocation = _blockLocationService.getLocationForVehicleAndTime(vehicleId, target);
    if (blockLocation == null)
        return null;
    return getBlockLocationAsVehicleLocationRecord(blockLocation);
}
Also used : TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation)

Example 13 with TargetTime

use of org.onebusaway.transit_data_federation.model.TargetTime in project onebusaway-application-modules by camsys.

the class BlockLocationServiceImpl method getLocationsForBlockInstance.

@Override
public Map<AgencyAndId, List<BlockLocation>> getLocationsForBlockInstance(BlockInstance blockInstance, List<Date> times, long currentTime) {
    Map<AgencyAndId, List<BlockLocation>> locationsByVehicleId = new FactoryMap<AgencyAndId, List<BlockLocation>>(new ArrayList<BlockLocation>());
    for (Date time : times) {
        TargetTime tt = new TargetTime(time.getTime(), currentTime);
        List<VehicleLocationCacheElements> records = getBlockLocationRecordCollectionForBlock(blockInstance, tt);
        for (VehicleLocationCacheElements cacheRecord : records) {
            BlockLocation location = getBlockLocation(blockInstance, cacheRecord, null, time.getTime());
            if (location != null) {
                locationsByVehicleId.get(location.getVehicleId()).add(location);
            }
        }
    }
    return locationsByVehicleId;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) VehicleLocationCacheElements(org.onebusaway.transit_data_federation.services.realtime.VehicleLocationCacheElements) List(java.util.List) ArrayList(java.util.ArrayList) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) Date(java.util.Date)

Aggregations

TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)13 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)12 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)8 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)7 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)7 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)7 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)7 Date (java.util.Date)6 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)6 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)6 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)5 ScheduledBlockLocationServiceImpl (org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl)5 VehicleLocationRecordCacheImpl (org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)2 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)2 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)2 StopBean (org.onebusaway.transit_data.model.StopBean)2 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)2