code: def winddir_average(data, threshold, min_count, decay=1.0):
      
      wind_filter = pywws.process.WindFilter()
      count = 0
      for item in data:
          wind_filter.add(item)
          if item['wind_dir'] is not None:
              count += 1
      if count < min_count:
          return None
      speed, direction = wind_filter.result()
      if speed is None or speed < threshold:
          return None
      return direction * 22.5
docs: Compute average wind direction (in degrees) for a slice of data.
  
      The wind speed and direction of each data item is converted to a
      vector before averaging, so the result reflects the dominant wind
      direction during the time period covered by the data.
  
      Setting the ``decay`` parameter converts the filter from a simple
      averager to one where the most recent sample carries the highest
      weight, and earlier samples have a lower weight according to how
      long ago they were.
  
      This process is an approximation of "exponential smoothing". See
      `Wikipedia <http://en.wikipedia.org/wiki/Exponential_smoothing>`_
      for a detailed discussion.
  
      The parameter ``decay`` corresponds to the value ``(1 - alpha)``
      in the Wikipedia description. Because the weather data being
      smoothed may not be at regular intervals this parameter is the
      decay over 5 minutes. Weather data at other intervals will have
      its weight scaled accordingly.
  
      :note: The return value is in degrees, not the 0..15 range used
          elsewhere in pywws.
  
      :param data: a slice of pywws raw/calib or hourly data.
  
      :type data: pywws.storage.CoreStore
  
      :param threshold: minimum average windspeed for there to be a
          valid wind direction.
  
      :type threshold: float
  
      :param min_count: minimum number of data items for there to be a
          valid wind direction.
  
      :type min_count: int
  
      :param decay: filter coefficient decay rate.
  
      :type decay: float
  
      :rtype: float