Search in sources :

Example 6 with NaturalLanguageStringStructure

use of uk.org.siri.siri.NaturalLanguageStringStructure 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;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri.NaturalLanguageStringStructure) DecimalFormat(java.text.DecimalFormat) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) SiriDistanceExtension(org.onebusaway.transit_data_federation.siri.SiriDistanceExtension) StopPointRefStructure(uk.org.siri.siri.StopPointRefStructure) OnwardCallStructure(uk.org.siri.siri.OnwardCallStructure) ExtensionsStructure(uk.org.siri.siri.ExtensionsStructure) Date(java.util.Date)

Aggregations

NaturalLanguageStringStructure (uk.org.siri.siri.NaturalLanguageStringStructure)6 Date (java.util.Date)5 SiriDistanceExtension (org.onebusaway.transit_data_federation.siri.SiriDistanceExtension)5 SiriExtensionWrapper (org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper)5 MonitoredCallStructure (uk.org.siri.siri.MonitoredCallStructure)4 DecimalFormat (java.text.DecimalFormat)3 ExtensionsStructure (uk.org.siri.siri.ExtensionsStructure)3 ArrayList (java.util.ArrayList)2 StopBean (org.onebusaway.transit_data.model.StopBean)2 DirectionRefStructure (uk.org.siri.siri.DirectionRefStructure)2 LineRefStructure (uk.org.siri.siri.LineRefStructure)2 StopPointRefStructure (uk.org.siri.siri.StopPointRefStructure)2 BigDecimal (java.math.BigDecimal)1 DateFormat (java.text.DateFormat)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Matchers.anyString (org.mockito.Matchers.anyString)1 StopResult (org.onebusaway.enterprise.webapp.actions.m.model.StopResult)1 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)1 NameBean (org.onebusaway.transit_data.model.NameBean)1