Module: DarkskyWeather::Api::WeatherAnalysis

Included in:
WeatherCollection, WeatherData
Defined in:
lib/darksky_weather/api/weather_analysis.rb

Instance Method Summary collapse

Instance Method Details

#average_visibility(hours: hourly) ⇒ Object



60
61
62
63
# 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) ⇒ Object



101
102
103
104
# 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) ⇒ Object



51
52
53
# 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) ⇒ Object



55
56
57
58
# 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) ⇒ Object



33
34
35
# 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) ⇒ Object



37
38
39
40
# 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) ⇒ Object



24
25
26
# 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) ⇒ Object



28
29
30
31
# 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) ⇒ Object



65
66
67
# 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) ⇒ Object



69
70
71
72
# 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) ⇒ Object



106
107
108
# 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) ⇒ Object



110
111
112
113
# 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) ⇒ Object



83
84
85
# 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) ⇒ Object



87
88
89
90
# 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) ⇒ Object



74
75
76
# 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) ⇒ Object



78
79
80
81
# 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) ⇒ Object



92
93
94
# 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) ⇒ Object



96
97
98
99
# 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) ⇒ Object



20
21
22
# 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) ⇒ Object

Get the hourly weather data that encompasses the passed time.



15
16
17
18
# 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) ⇒ Object

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



7
8
9
10
11
12
# 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) ⇒ Object



42
43
44
# 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) ⇒ Object



46
47
48
49
# 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