use of uk.org.siri.siri.StopPointRefStructure in project onebusaway-application-modules by camsys.
the class SiriSupport method getMonitoredCallStructure.
private static MonitoredCallStructure getMonitoredCallStructure(StopBean stopBean, PresentationService presentationService, double distanceOfCallAlongTrip, double distanceOfVehicleFromCall, int visitNumber, int index, TimepointPredictionRecord prediction, boolean hasRealtimeData, long responseTimestamp, long scheduledArrivalTime) {
MonitoredCallStructure monitoredCallStructure = new MonitoredCallStructure();
monitoredCallStructure.setVisitNumber(BigInteger.valueOf(visitNumber));
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue(stopBean.getId());
monitoredCallStructure.setStopPointRef(stopPointRef);
NaturalLanguageStringStructure stopPoint = new NaturalLanguageStringStructure();
stopPoint.setValue(stopBean.getName());
monitoredCallStructure.setStopPointName(stopPoint);
if (prediction != null) {
if (!hasRealtimeData) {
monitoredCallStructure.setExpectedArrivalTime(new Date(prediction.getTimepointScheduledTime()));
monitoredCallStructure.setExpectedDepartureTime(new Date(prediction.getTimepointScheduledTime()));
} else // do not allow predicted times to be less than ResponseTimestamp
if (prediction.getTimepointPredictedArrivalTime() < responseTimestamp) {
/*
* monitoredCall has less precision than onwardCall (date vs. timestamp)
* which results in a small amount of error when converting back to timestamp.
* Add a second here to prevent negative values from showing up in the UI
* (actual precision of the value is 1 minute, so a second has little influence)
*/
monitoredCallStructure.setExpectedArrivalTime(new Date(responseTimestamp + 1000));
monitoredCallStructure.setExpectedDepartureTime(new Date(responseTimestamp + 1000));
} else {
monitoredCallStructure.setExpectedArrivalTime(new Date(prediction.getTimepointPredictedArrivalTime()));
monitoredCallStructure.setExpectedDepartureTime(new Date(prediction.getTimepointPredictedArrivalTime()));
}
} else if (!hasRealtimeData) {
monitoredCallStructure.setExpectedArrivalTime(new Date(scheduledArrivalTime));
monitoredCallStructure.setExpectedDepartureTime(new Date(scheduledArrivalTime));
}
// setting the scheduled arrival time.
if (monitoredCallStructure.getExpectedArrivalTime() != null) {
monitoredCallStructure.setAimedArrivalTime(new Date(scheduledArrivalTime));
}
// siri extensions
SiriExtensionWrapper wrapper = new SiriExtensionWrapper();
ExtensionsStructure distancesExtensions = new ExtensionsStructure();
SiriDistanceExtension distances = new SiriDistanceExtension();
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setGroupingUsed(false);
distances.setStopsFromCall(index);
distances.setCallDistanceAlongRoute(NumberUtils.toDouble(df.format(distanceOfCallAlongTrip)));
distances.setDistanceFromCall(NumberUtils.toDouble(df.format(distanceOfVehicleFromCall)));
distances.setPresentableDistance(presentationService.getPresentableDistance(distances));
long deviation = 0L;
if (monitoredCallStructure.getExpectedArrivalTime() != null && monitoredCallStructure.getAimedArrivalTime() != null) {
// get schedule deviation in milliseconds
long deviationSeconds = monitoredCallStructure.getExpectedArrivalTime().getTime() - monitoredCallStructure.getAimedArrivalTime().getTime();
deviation = Math.round(deviationSeconds / (1000.0 * 60.0));
}
wrapper.setDeviation(String.valueOf(deviation));
wrapper.setDistances(distances);
distancesExtensions.setAny(wrapper);
monitoredCallStructure.setExtensions(distancesExtensions);
return monitoredCallStructure;
}
use of uk.org.siri.siri.StopPointRefStructure in project onebusaway-application-modules by camsys.
the class ServiceAlertsHelper method handleAffects.
/*
@SuppressWarnings("unused")
private void handlReasons(PtSituationElementStructure ptSituation,
ServiceAlertBean serviceAlert) {
throw new RuntimeException("handleReasons not implemented");
}
*/
private void handleAffects(ServiceAlertBean serviceAlert, PtSituationElementStructure ptSituation) {
if (serviceAlert.getAllAffects() == null)
return;
boolean hasOperators = false;
AffectsScopeStructure affectsStructure = new AffectsScopeStructure();
VehicleJourneys vehicleJourneys = new VehicleJourneys();
for (SituationAffectsBean affects : serviceAlert.getAllAffects()) {
String agencyId = affects.getAgencyId();
if (agencyId != null) {
Operators operators = new Operators();
if (StringUtils.equals(agencyId, "__ALL_OPERATORS__")) {
operators.setAllOperators("");
} else {
AffectedOperatorStructure affectedOperator = new AffectedOperatorStructure();
affectedOperator.setOperatorName(createDefaultedTextStructure(agencyId));
operators.getAffectedOperator().add(affectedOperator);
}
affectsStructure.setOperators(operators);
hasOperators = true;
}
// LineRef
String routeId = affects.getRouteId();
String directionId = affects.getDirectionId();
String stopId = affects.getStopId();
if (!StringUtils.isBlank(routeId)) {
AffectedVehicleJourneyStructure affectedVehicleJourneyStructure = new AffectedVehicleJourneyStructure();
LineRefStructure lineRefStructure = new LineRefStructure();
lineRefStructure.setValue(routeId);
affectedVehicleJourneyStructure.setLineRef(lineRefStructure);
if (!StringUtils.isBlank(directionId)) {
DirectionRefStructure directionRefStructure = new DirectionRefStructure();
directionRefStructure.setValue(directionId);
affectedVehicleJourneyStructure.setDirectionRef(directionRefStructure);
}
vehicleJourneys.getAffectedVehicleJourney().add(affectedVehicleJourneyStructure);
}
// add support for stop level alerts
if (!StringUtils.isBlank(stopId)) {
AffectedStopPointStructure stop = new AffectedStopPointStructure();
StopPointRefStructure stopRef = new StopPointRefStructure();
stopRef.setValue(stopId);
stop.setStopPointRef(stopRef);
if (affectsStructure.getStopPoints() == null) {
affectsStructure.setStopPoints(new AffectsScopeStructure.StopPoints());
}
affectsStructure.getStopPoints().getAffectedStopPoint().add(stop);
}
}
if (vehicleJourneys.getAffectedVehicleJourney().size() > 0) {
affectsStructure.setVehicleJourneys(vehicleJourneys);
}
if ((vehicleJourneys.getAffectedVehicleJourney().size() > 0) || hasOperators) {
ptSituation.setAffects(affectsStructure);
}
}
use of uk.org.siri.siri.StopPointRefStructure in project onebusaway-application-modules by camsys.
the class SiriSupport method getOnwardCallStructure.
private static OnwardCallStructure getOnwardCallStructure(StopBean stopBean, PresentationService presentationService, double distanceOfCallAlongTrip, double distanceOfVehicleFromCall, int visitNumber, int index, TimepointPredictionRecord prediction, boolean hasRealtimeData, long responseTimestamp, long scheduledArrivalTime) {
OnwardCallStructure onwardCallStructure = new OnwardCallStructure();
onwardCallStructure.setVisitNumber(BigInteger.valueOf(visitNumber));
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue(stopBean.getId());
onwardCallStructure.setStopPointRef(stopPointRef);
if (stopBean.getCode() != null) {
// Agency's prefer stop code display in UI, so override platform name for this use
NaturalLanguageStringStructure platform = new NaturalLanguageStringStructure();
platform.setValue(stopBean.getCode());
onwardCallStructure.setArrivalPlatformName(platform);
}
NaturalLanguageStringStructure stopPoint = new NaturalLanguageStringStructure();
stopPoint.setValue(stopBean.getName());
onwardCallStructure.setStopPointName(stopPoint);
if (prediction != null) {
if (prediction.getTimepointPredictedArrivalTime() < responseTimestamp) {
onwardCallStructure.setExpectedArrivalTime(new Date(responseTimestamp));
onwardCallStructure.setExpectedDepartureTime(new Date(responseTimestamp));
} else {
onwardCallStructure.setExpectedArrivalTime(new Date(prediction.getTimepointPredictedArrivalTime()));
onwardCallStructure.setExpectedDepartureTime(new Date(prediction.getTimepointPredictedDepartureTime()));
}
} else if (!hasRealtimeData) {
_log.debug("using arrival time of " + new Date(scheduledArrivalTime));
onwardCallStructure.setExpectedArrivalTime(new Date(scheduledArrivalTime));
onwardCallStructure.setExpectedDepartureTime(new Date(scheduledArrivalTime));
}
// siri extensions
SiriExtensionWrapper wrapper = new SiriExtensionWrapper();
ExtensionsStructure distancesExtensions = new ExtensionsStructure();
SiriDistanceExtension distances = new SiriDistanceExtension();
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setGroupingUsed(false);
distances.setStopsFromCall(index);
distances.setCallDistanceAlongRoute(NumberUtils.toDouble(df.format(distanceOfCallAlongTrip)));
distances.setDistanceFromCall(NumberUtils.toDouble(df.format(distanceOfVehicleFromCall)));
distances.setPresentableDistance(presentationService.getPresentableDistance(distances));
wrapper.setDistances(distances);
distancesExtensions.setAny(wrapper);
onwardCallStructure.setExtensions(distancesExtensions);
return onwardCallStructure;
}
Aggregations