use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getMonitoredStopVisitsForStop.
@Override
public List<MonitoredStopVisitStructure> getMonitoredStopVisitsForStop(String stopId, int maximumOnwardCalls, DetailLevel detailLevel, long currentTime, List<AgencyAndId> routeIds, Map<Filters, String> filters) {
List<MonitoredStopVisitStructure> output = new ArrayList<MonitoredStopVisitStructure>();
String directionId = filters.get(Filters.DIRECTION_REF);
int maximumStopVisits = SiriSupportV2.convertToNumeric(filters.get(Filters.MAX_STOP_VISITS), Integer.MAX_VALUE);
Integer minimumStopVisitsPerLine = SiriSupportV2.convertToNumeric(filters.get(Filters.MIN_STOP_VISITS), null);
Map<AgencyAndId, Integer> visitCountByLine = new HashMap<AgencyAndId, Integer>();
int visitCount = 0;
for (ArrivalAndDepartureBean adBean : getArrivalsAndDeparturesForStop(stopId, currentTime)) {
TripStatusBean statusBeanForCurrentTrip = adBean.getTripStatus();
TripBean tripBeanForAd = adBean.getTrip();
if (statusBeanForCurrentTrip == null)
continue;
if (!_presentationService.include(statusBeanForCurrentTrip) || !_presentationService.include(adBean, statusBeanForCurrentTrip))
continue;
MonitoredStopVisitStructure stopVisit = new MonitoredStopVisitStructure();
stopVisit.setRecordedAtTime(DateUtil.toXmlGregorianCalendar(statusBeanForCurrentTrip.getLastUpdateTime()));
List<TimepointPredictionRecord> timePredictionRecords = null;
timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(stopId).getAgencyId(), statusBeanForCurrentTrip);
MonitoredVehicleJourneyStructure mvjourney = new MonitoredVehicleJourneyStructure();
stopVisit.setMonitoredVehicleJourney(mvjourney);
SiriSupportV2.fillMonitoredVehicleJourney(mvjourney, tripBeanForAd, statusBeanForCurrentTrip, adBean.getStop(), OnwardCallsMode.STOP_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, statusBeanForCurrentTrip.isPredicted(), detailLevel, currentTime, filters);
// FILTERS
AgencyAndId thisRouteId = AgencyAndIdLibrary.convertFromString(mvjourney.getLineRef().getValue());
String thisDirectionId = mvjourney.getDirectionRef().getValue();
if (routeIds.size() > 0 && !routeIds.contains(thisRouteId))
continue;
if (directionId != null && !thisDirectionId.equals(directionId))
continue;
// Monitored Stop Visits
Map<String, MonitoredStopVisitStructure> visitsMap = new HashMap<String, MonitoredStopVisitStructure>();
// visit count filters
Integer visitCountForThisLine = visitCountByLine.get(thisRouteId);
if (visitCountForThisLine == null) {
visitCountForThisLine = 0;
}
if (visitCount >= maximumStopVisits) {
if (minimumStopVisitsPerLine == null) {
break;
} else {
if (visitCountForThisLine >= minimumStopVisitsPerLine) {
continue;
}
}
}
// unique stops filters
if (stopVisit.getMonitoredVehicleJourney() == null || stopVisit.getMonitoredVehicleJourney().getVehicleRef() == null || StringUtils.isBlank(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue())) {
continue;
} else {
String visitKey = stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue();
if (visitsMap.containsKey(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue())) {
if (stopVisit.getMonitoredVehicleJourney().getProgressStatus() == null) {
visitsMap.remove(visitKey);
visitsMap.put(visitKey, stopVisit);
}
continue;
} else {
visitsMap.put(stopVisit.getMonitoredVehicleJourney().getVehicleRef().getValue(), stopVisit);
}
}
output.add(stopVisit);
visitCount++;
visitCountForThisLine++;
visitCountByLine.put(thisRouteId, visitCountForThisLine);
}
Collections.sort(output, new Comparator<MonitoredStopVisitStructure>() {
public int compare(MonitoredStopVisitStructure arg0, MonitoredStopVisitStructure arg1) {
try {
SiriExtensionWrapper wrapper0 = (SiriExtensionWrapper) arg0.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
SiriExtensionWrapper wrapper1 = (SiriExtensionWrapper) arg1.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
return wrapper0.getDistances().getDistanceFromCall().compareTo(wrapper1.getDistances().getDistanceFromCall());
} catch (Exception e) {
return -1;
}
}
});
return output;
}
use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getTripStopTimes.
public TripStopTimesV2Bean getTripStopTimes(TripStopTimesBean tripStopTimes) {
TripStopTimesV2Bean bean = new TripStopTimesV2Bean();
bean.setTimeZone(tripStopTimes.getTimeZone());
List<TripStopTimeV2Bean> instances = new ArrayList<TripStopTimeV2Bean>();
for (TripStopTimeBean sti : tripStopTimes.getStopTimes()) {
TripStopTimeV2Bean stiBean = new TripStopTimeV2Bean();
stiBean.setArrivalTime(sti.getArrivalTime());
stiBean.setDepartureTime(sti.getDepartureTime());
stiBean.setStopHeadsign(sti.getStopHeadsign());
stiBean.setDistanceAlongTrip(sti.getDistanceAlongTrip());
stiBean.setStopId(sti.getStop().getId());
addToReferences(sti.getStop());
instances.add(stiBean);
}
bean.setStopTimes(instances);
TripBean nextTrip = tripStopTimes.getNextTrip();
if (nextTrip != null) {
bean.setNextTripId(nextTrip.getId());
addToReferences(nextTrip);
}
TripBean prevTrip = tripStopTimes.getPreviousTrip();
if (prevTrip != null) {
bean.setPreviousTripId(prevTrip.getId());
addToReferences(prevTrip);
}
FrequencyBean freq = tripStopTimes.getFrequency();
if (freq != null)
bean.setFrequency(getFrequency(freq));
return bean;
}
use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getTripStatus.
public TripStatusV2Bean getTripStatus(TripStatusBean tripStatus) {
TripStatusV2Bean bean = new TripStatusV2Bean();
TripBean activeTrip = tripStatus.getActiveTrip();
if (activeTrip != null) {
bean.setActiveTripId(activeTrip.getId());
bean.setBlockTripSequence(tripStatus.getBlockTripSequence());
addToReferences(activeTrip);
}
bean.setServiceDate(tripStatus.getServiceDate());
FrequencyBean frequency = tripStatus.getFrequency();
if (frequency != null)
bean.setFrequency(getFrequency(frequency));
bean.setScheduledDistanceAlongTrip(tripStatus.getScheduledDistanceAlongTrip());
bean.setTotalDistanceAlongTrip(tripStatus.getTotalDistanceAlongTrip());
bean.setPosition(tripStatus.getLocation());
if (tripStatus.isOrientationSet())
bean.setOrientation(tripStatus.getOrientation());
StopBean closestStop = tripStatus.getClosestStop();
if (closestStop != null) {
bean.setClosestStop(closestStop.getId());
addToReferences(closestStop);
bean.setClosestStopTimeOffset(tripStatus.getClosestStopTimeOffset());
}
StopBean nextStop = tripStatus.getNextStop();
if (nextStop != null) {
bean.setNextStop(nextStop.getId());
addToReferences(nextStop);
bean.setNextStopTimeOffset(tripStatus.getNextStopTimeOffset());
}
bean.setPhase(tripStatus.getPhase());
bean.setStatus(tripStatus.getStatus());
bean.setPredicted(tripStatus.isPredicted());
if (tripStatus.getLastUpdateTime() > 0)
bean.setLastUpdateTime(tripStatus.getLastUpdateTime());
if (tripStatus.getLastLocationUpdateTime() > 0)
bean.setLastLocationUpdateTime(tripStatus.getLastLocationUpdateTime());
if (tripStatus.isLastKnownDistanceAlongTripSet())
bean.setLastKnownDistanceAlongTrip(tripStatus.getLastKnownDistanceAlongTrip());
bean.setLastKnownLocation(tripStatus.getLastKnownLocation());
if (tripStatus.isLastKnownOrientationSet())
bean.setLastKnownOrientation(tripStatus.getLastKnownOrientation());
if (tripStatus.isScheduleDeviationSet())
bean.setScheduleDeviation((int) tripStatus.getScheduleDeviation());
if (tripStatus.isDistanceAlongTripSet())
bean.setDistanceAlongTrip(tripStatus.getDistanceAlongTrip());
bean.setVehicleId(tripStatus.getVehicleId());
List<ServiceAlertBean> situations = tripStatus.getSituations();
if (situations != null && !situations.isEmpty()) {
List<String> situationIds = new ArrayList<String>();
for (ServiceAlertBean situation : situations) {
situationIds.add(situation.getId());
addToReferences(situation);
}
bean.setSituationIds(situationIds);
}
return bean;
}
use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getVehicleStatus.
public VehicleStatusV2Bean getVehicleStatus(VehicleStatusBean vehicleStatus) {
VehicleStatusV2Bean bean = new VehicleStatusV2Bean();
bean.setLastUpdateTime(vehicleStatus.getLastUpdateTime());
if (vehicleStatus.getLastLocationUpdateTime() > 0)
bean.setLastLocationUpdateTime(vehicleStatus.getLastLocationUpdateTime());
bean.setLocation(vehicleStatus.getLocation());
bean.setPhase(vehicleStatus.getPhase());
bean.setStatus(vehicleStatus.getStatus());
bean.setVehicleId(vehicleStatus.getVehicleId());
TripBean trip = vehicleStatus.getTrip();
if (trip != null) {
bean.setTripId(trip.getId());
addToReferences(trip);
}
TripStatusBean tripStatus = vehicleStatus.getTripStatus();
if (tripStatus != null)
bean.setTripStatus(getTripStatus(tripStatus));
return bean;
}
use of org.onebusaway.transit_data.model.trips.TripBean in project onebusaway-application-modules by camsys.
the class VehiclePositionsForAgencyAction method fillFeedMessage.
@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(agencyId, timestamp);
for (VehicleStatusBean vehicle : vehicles.getList()) {
FeedEntity.Builder entity = feed.addEntityBuilder();
entity.setId(Integer.toString(feed.getEntityCount()));
VehiclePosition.Builder vehiclePosition = entity.getVehicleBuilder();
TripStatusBean tripStatus = vehicle.getTripStatus();
if (tripStatus != null) {
TripBean activeTrip = tripStatus.getActiveTrip();
RouteBean route = activeTrip.getRoute();
TripDescriptor.Builder tripDesc = vehiclePosition.getTripBuilder();
tripDesc.setTripId(normalizeId(activeTrip.getId()));
tripDesc.setRouteId(normalizeId(route.getId()));
}
VehicleDescriptor.Builder vehicleDesc = vehiclePosition.getVehicleBuilder();
vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
CoordinatePoint location = vehicle.getLocation();
if (location != null) {
Position.Builder position = vehiclePosition.getPositionBuilder();
position.setLatitude((float) location.getLat());
position.setLongitude((float) location.getLon());
}
vehiclePosition.setTimestamp(vehicle.getLastUpdateTime() / 1000);
}
}
Aggregations