module DarkskyWeather::Api::WeatherAnalysis

Public Instance Methods

average_visibility(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 60
def average_visibility(hours: hourly)
  visibility_total = hours.map{|h| h.visibility }.sum
  return (visibility_total / hours.count.to_f).to_f
end
average_wind_speed(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 101
def average_wind_speed(hours: hourly)
  total_wind_speed = hours.map{|h| h.wind_speed }.sum
  (total_wind_speed / hours.count.to_f).to_f
end
best_visibility(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 51
def best_visibility(hours: hourly)
  hours.map{|h| h.visibility }.max || 10
end
best_visibility_datetime(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 55
def best_visibility_datetime(hours: hourly)
  stamp = hours.sort_by{|h| h.visibility }.last.time
  return DateTime.strptime(stamp.to_s, "%s")
end
max_accumulation(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 33
def max_accumulation(hours: hourly)
  hours.map{|h| h.precip_accumulation }.max || 0
end
max_accumulation_datetime(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 37
def max_accumulation_datetime(hours: hourly)
  stamp = hours.sort_by{|h| h.precip_accumulation }.last.time
  return DateTime.strptime(stamp.to_s, "%s")
end
max_precipitation(type: 'rain', hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 24
def max_precipitation(type: 'rain', hours: hourly)
  hours.select{|h| h.precip_type == type  }.map{|h| h.precip_intensity }.max || 0
end
max_precipitation_datetime(type: 'rain', hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 28
def max_precipitation_datetime(type: 'rain', hours: hourly)
  stamp = hours.select{|h| h.precip_type == type  }.sort_by{|h| h.precip_intensity.to_f }.last.time
  return DateTime.strptime(stamp.to_s, "%s")
end
max_temperature(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 65
def max_temperature(hours: hourly)
  hours.map{|h| h.temperature }.max
end
max_temperature_datetime(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 69
def max_temperature_datetime(hours: hourly)
  stamp = hours.sort_by{|h| h.temperature }.last.time
  return DateTime.strptime(stamp.to_s, "%s")
end
max_wind_gust(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 106
def max_wind_gust(hours: hourly)
  hours.map{|h| h.wind_gust }.max
end
max_wind_gust_datetime(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 110
def max_wind_gust_datetime(hours: hourly)
  stamp = hours.sort_by{|h| h.wind_gust }.last.time
  return DateTime.strptime(stamp.to_s, "%s")
end
max_wind_speed(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 83
def max_wind_speed(hours: hourly)
  hours.map{|h| h.wind_speed }.max
end
max_wind_speed_datetime(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 87
def max_wind_speed_datetime(hours: hourly)
  stamp = hours.sort_by{|h| h.wind_speed }.last.time
  return DateTime.strptime(stamp.to_s, "%s")
end
min_temperature(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 74
def min_temperature(hours: hourly)
  hours.map{|h| h.temperature }.min
end
min_temperature_datetime(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 78
def min_temperature_datetime(hours: hourly)
  stamp = hours.sort_by{|h| h.temperature }.first.time
  return DateTime.strptime(stamp.to_s, "%s")
end
min_wind_speed(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 92
def min_wind_speed(hours: hourly)
  hours.map{|h| h.wind_speed }.min
end
min_wind_speed_datetime(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 96
def min_wind_speed_datetime(hours: hourly)
  stamp = hours.sort_by{|h| h.wind_speed }.first.time
  return DateTime.strptime(stamp.to_s, "%s")
end
total_precipitation(type: 'rain', hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 20
def total_precipitation(type: 'rain', hours: hourly)
  hours.select{|h| h.precip_type == type  }.map{|h| h.precip_intensity.to_f }.sum
end
weather_at(time) click to toggle source

Get the hourly weather data that encompasses the passed time.

# File lib/darksky_weather/api/weather_analysis.rb, line 15
def weather_at(time)
  compare_time = Time.strptime(time.to_s, '%s').beginning_of_hour
  hourly.select{|h| h.time == compare_time.to_i }.first
end
weather_between(start_time, end_time) click to toggle source

Get the range of hourly weather data that occurred inclusively between start_time and end_time

# File lib/darksky_weather/api/weather_analysis.rb, line 7
def weather_between(start_time, end_time)
  normalized_start = Time.strptime(start_time.to_s, '%s').beginning_of_hour.to_i
  normalized_end   = Time.strptime(end_time.to_s, '%s').beginning_of_hour.to_i

  return hourly.select{|h| h.time.to_i >= normalized_start && h.time.to_i <= normalized_end }.sort_by(&:time)
end
worst_visibility(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 42
def worst_visibility(hours: hourly)
  hours.map{|h| h.visibility }.min || 10
end
worst_visibility_datetime(hours: hourly) click to toggle source
# File lib/darksky_weather/api/weather_analysis.rb, line 46
def worst_visibility_datetime(hours: hourly)
  stamp = hours.sort_by{|h| h.visibility }.first.time
  return DateTime.strptime(stamp.to_s, "%s")
end