Search in sources :

Example 11 with NaturalLanguageStringStructure

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;
}
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)8 NaturalLanguageStringStructure (uk.org.siri.siri_2.NaturalLanguageStringStructure)8 ArrayList (java.util.ArrayList)7 StopPointRefStructure (uk.org.siri.siri_2.StopPointRefStructure)7 DirectionRefStructure (uk.org.siri.siri_2.DirectionRefStructure)6 LineRefStructure (uk.org.siri.siri_2.LineRefStructure)6 LocationStructure (uk.org.siri.siri_2.LocationStructure)6 HashMap (java.util.HashMap)4 LineDirectionStructure (uk.org.siri.siri_2.LineDirectionStructure)4 List (java.util.List)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Filters (org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters)3 DetailLevel (org.onebusaway.api.actions.siri.model.DetailLevel)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 NaturalLanguageStringStructure (uk.org.siri.siri20.NaturalLanguageStringStructure)3 AnnotatedStopPointStructure (uk.org.siri.siri_2.AnnotatedStopPointStructure)3 ZonedDateTime (java.time.ZonedDateTime)2 Test (org.junit.Test)2 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)2