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;
}
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);
}
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;
}
Aggregations