use of uk.org.siri.siri20.NaturalLanguageStringStructure in project onebusaway-application-modules by camsys.
the class SiriSupportV2 method getMonitoredCallStructure.
private static MonitoredCallStructure getMonitoredCallStructure(StopBean stopBean, PresentationService presentationService, double distanceOfCallAlongTrip, double distanceOfVehicleFromCall, int visitNumber, int index, TimepointPredictionRecord prediction, DetailLevel detailLevel, long responseTimestamp) {
if (prediction.getScheduleRelationship() != null && prediction.isSkipped()) {
_log.info("SKIPPED STOP: " + stopBean.getId());
return null;
}
MonitoredCallStructure monitoredCallStructure = new MonitoredCallStructure();
monitoredCallStructure.setVisitNumber(BigInteger.valueOf(visitNumber));
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue(stopBean.getId());
NaturalLanguageStringStructure stopPoint = new NaturalLanguageStringStructure();
stopPoint.setValue(stopBean.getName());
if (prediction != null) {
// 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(DateUtil.toXmlGregorianCalendar(responseTimestamp + 1000));
monitoredCallStructure.setExpectedDepartureTime(DateUtil.toXmlGregorianCalendar(responseTimestamp + 1000));
} else {
monitoredCallStructure.setExpectedArrivalTime(DateUtil.toXmlGregorianCalendar(prediction.getTimepointPredictedArrivalTime()));
monitoredCallStructure.setExpectedDepartureTime(DateUtil.toXmlGregorianCalendar(prediction.getTimepointPredictedArrivalTime()));
}
}
// siri extensions
// TODO - LCARABALLO - Distance Along Route Might Still need Extension
/*SiriExtensionWrapper wrapper = new SiriExtensionWrapper();
ExtensionsStructure distancesExtensions = new ExtensionsStructure();
SiriDistanceExtension distances = new SiriDistanceExtension();
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setGroupingUsed(false);
distances.setCallDistanceAlongRoute(Double.valueOf(df
.format(distanceOfCallAlongTrip)));
wrapper.setDistances(distances);
distancesExtensions.setAny(wrapper);
monitoredCallStructure.setExtensions(distancesExtensions);*/
// distances
NaturalLanguageStringStructure presentableDistance = new NaturalLanguageStringStructure();
presentableDistance.setValue(presentationService.getPresentableDistance(distanceOfVehicleFromCall, index));
monitoredCallStructure.setNumberOfStopsAway(BigInteger.valueOf(index));
monitoredCallStructure.setDistanceFromStop(new BigDecimal(distanceOfVehicleFromCall).toBigInteger());
monitoredCallStructure.setArrivalProximityText(presentableDistance);
// basic
if (detailLevel.equals(DetailLevel.BASIC) || detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) {
monitoredCallStructure.getStopPointName().add(stopPoint);
}
// normal
if (detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.CALLS)) {
monitoredCallStructure.setStopPointRef(stopPointRef);
}
return monitoredCallStructure;
}
Aggregations