class Net::NTP::Check::AutoBandPass

The filtering works like this: This assumes you are passing in a 9 length Array. Other lengths may work, but YMMV. This then gets the average of the middle three of the sorted Array. Using this average, and an arbitrary range (+/- 200ms), we delete any values outside of that range. This effectively is a lazy-man's band-pass filter.

Constants

FILTER_RANGE

Public Class Methods

apply_band(values, average) click to toggle source
# File lib/net/ntp/check/offset.rb, line 95
def self.apply_band(values, average)
  values.dup.each do |o|
    upper_bound = (average + FILTER_RANGE)
    lower_bound = (average - FILTER_RANGE)
    values.delete(o) if o < lower_bound || o > upper_bound
  end
  values
end
average(values) click to toggle source
# File lib/net/ntp/check/offset.rb, line 104
def self.average(values)
  values.reduce { |a, e| a + e } / values.length.to_f
end
filter(values) click to toggle source
# File lib/net/ntp/check/offset.rb, line 83
def self.filter(values)
  v = values.sort
  Net::NTP::Check.logger.debug("AutoBandPass values: #{v}")
  middle = values.length / 2.0
  middle.ceil unless values.length % 2
  avg = average(v[(middle - 1).floor..(middle + 1).floor])
  Net::NTP::Check.logger.debug("AutoBandPass mid values avg: #{avg}")
  v = apply_band(v, avg)
  Net::NTP::Check.logger.debug("AutoBandPass values with filter: #{v}")
  average(v)
end