Class TransitInterpolationLibrary


  • public class TransitInterpolationLibrary
    extends Object
    Transit-specific methods to support searching for deviations (produced from real-time predictions) for a given stop. Interpolation behavior is consistent with the GTFS-realtime spec (https://developers.google.com/transit/gtfs-realtime/) when using the EInRangeStrategy.PREVIOUS_VALUE and EOutOfRangeStrategy.LAST_VALUE strategies - in particular, this applies to the propagation of delays downstream in a trip. The EInRangeStrategy.INTERPOLATE and EOutOfRangeStrategy.INTERPOLATE strategies have behavior consistent with the normal InterpolationLibrary, which do not conform to the GTFS-rt spec.
    • Constructor Detail

      • TransitInterpolationLibrary

        public TransitInterpolationLibrary()
    • Method Detail

      • interpolate

        public static Double interpolate​(double[] keys,
                                         double[] values,
                                         double target,
                                         EOutOfRangeStrategy outOfRangeStrategy)
      • interpolate

        public static Double interpolate​(double[] keys,
                                         double[] values,
                                         double target,
                                         EOutOfRangeStrategy outOfRangeStrategy,
                                         EInRangeStrategy inRangeStrategy)
        Find the deviation that should be used for a particular stop, given sorted keys (arrival times) and values (deviations) arrays. The target is the arrival time for the stop we're searching for. Delay propagation is consistent with the GTFS-realtime spec (https://developers.google.com/transit/gtfs-realtime/) when using the EInRangeStrategy.PREVIOUS_VALUE and EOutOfRangeStrategy.LAST_VALUE strategies. If EOutOfRangeStrategy.LAST_VALUE is provided and all deviations are downstream from the target stop, null will be returned to indicate that no real-time information is available for the target stop. If EInRangeStrategy.INTERPOLATE is provided, this method will interpolate using linear interpolation and produce a value for a target key within the key-range of the map. For a key outside the range of the keys of the map, the outOfRange EOutOfRangeStrategy strategy will determine the interpolation behavior. EOutOfRangeStrategy.INTERPOLATE will linearly extrapolate the value.
        Parameters:
        keys - sorted array of keys (the scheduled arrival time of the stop)
        values - sorted arrays of values (the list of real-time deviations for the provided stops)
        target - the target key used to interpolate a value (the scheduled arrival time of the stop)
        outOfRangeStrategy - the strategy to use for a target key that outside the key-range of the value map (use EOutOfRangeStrategy.LAST_VALUE for GTFS-rt behavior)
        inRangeStrategy - the strategy to use for a target key that inside the key-range of the value map (use EInRangeStrategy.PREVIOUS_VALUE for GTFS-rt behavior)
        Returns:
        an interpolated value (deviation) for the target key, or null if the target is upstream of the deviations