Search in sources :

Example 1 with MonitoredCallStructure

use of uk.org.siri.siri_2.MonitoredCallStructure 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) {
    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;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) MonitoredCallStructure(uk.org.siri.siri_2.MonitoredCallStructure) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 MonitoredCallStructure (uk.org.siri.siri_2.MonitoredCallStructure)1 NaturalLanguageStringStructure (uk.org.siri.siri_2.NaturalLanguageStringStructure)1 StopPointRefStructure (uk.org.siri.siri_2.StopPointRefStructure)1