Module: ForecastIo::Forecasts
- Included in:
- Lita::Handlers::OnewheelForecastIo
- Defined in:
- lib/lita/handlers/forecasts.rb
Instance Method Summary collapse
- #ansi_humidity_forecast(forecast) ⇒ Object
- #ansi_rain_forecast(forecast) ⇒ Object
- #ansi_rain_intensity_forecast(forecast) ⇒ Object
- #ansi_temp_apparent_forecast(forecast, hours = 24) ⇒ Object
- #ansi_temp_forecast(forecast, hours = 24) ⇒ Object
- #ansi_wind_direction_forecast(forecast) ⇒ Object
- #ansi_windchill_forecast(forecast, hours = 24) ⇒ Object
- #ascii_rain_forecast(forecast) ⇒ Object
- #ascii_temp_forecast(forecast, hours = 24) ⇒ Object
- #ascii_wind_direction_forecast(forecast) ⇒ Object
-
#calculate_windchill(temp_c, wind) ⇒ Object
Temp must be F.
- #conditions(forecast) ⇒ Object
- #do_the_cloud_thing(forecast, chars) ⇒ Object
- #do_the_daily_humidity_thing(forecast) ⇒ Object
- #do_the_daily_pressure_thing(forecast) ⇒ Object
- #do_the_daily_rain_thing(forecast) ⇒ Object
- #do_the_daily_sun_thing(forecast, chars) ⇒ Object
- #do_the_daily_wind_thing(forecast) ⇒ Object
- #do_the_fog_thing(forecast, chars) ⇒ Object
-
#do_the_humidity_thing(forecast, chars, key) ⇒ Object
, type, range_colors = nil).
- #do_the_nearest_storm_thing(forecast) ⇒ Object
- #do_the_ozone_thing(forecast) ⇒ Object
- #do_the_pressure_thing(forecast) ⇒ Object
- #do_the_rain_chance_thing(forecast, chars, key, use_color = config.colors, minute_limit = nil) ⇒ Object
-
#do_the_rain_intensity_thing(forecast, chars, key) ⇒ Object
, type, range_colors = nil).
- #do_the_seven_day_rain_thing(forecast) ⇒ Object
- #do_the_seven_day_thing(forecast) ⇒ Object
- #do_the_sun_thing(forecast, chars) ⇒ Object
- #do_the_sunrise_thing(forecast) ⇒ Object
- #do_the_sunset_thing(forecast) ⇒ Object
- #do_the_temp_thing(forecast, key, chars, hours) ⇒ Object
- #do_the_today_thing(forecast, yesterday) ⇒ Object
- #do_the_tomorrow_thing(forecast) ⇒ Object
- #do_the_uvindex_thing(forecast) ⇒ Object
- #do_the_wind_direction_thing(forecast, wind_arrows, hours = 48) ⇒ Object
- #do_the_windchill_temp_thing(forecast, chars, hours) ⇒ Object
- #do_the_windows_data_thing(forecast) ⇒ Object
-
#do_the_windows_thing(forecast) ⇒ Object
Check for the time of day when it will hit 72F.
- #get_aggregate_by_data_key(forecast, key, datum) ⇒ Object
- #get_alerts(forecast) ⇒ Object
-
#get_daily_comparison_text(temp_diff, high) ⇒ Object
If the temperature difference is positive,.
- #get_max_by_data_key(forecast, key, datum) ⇒ Object
- #get_min_by_data_key(forecast, key, datum) ⇒ Object
Instance Method Details
#ansi_humidity_forecast(forecast) ⇒ Object
25 26 27 |
# File 'lib/lita/handlers/forecasts.rb', line 25 def ansi_humidity_forecast(forecast) do_the_humidity_thing(forecast, ansi_chars, 'humidity') #, 'probability', get_rain_range_colors) end |
#ansi_rain_forecast(forecast) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/lita/handlers/forecasts.rb', line 12 def ansi_rain_forecast(forecast) (str, precip_type) = do_the_rain_chance_thing(forecast, ansi_chars, 'precipProbability') #, 'probability', get_rain_range_colors) max = get_max_by_data_key(forecast, 'minutely', 'precipProbability') agg = get_max_by_data_key(forecast, 'minutely', 'precipIntensity') "1hr #{precip_type} probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} max #{(max.to_f * 100).round(2)}%, #{get_accumulation agg} accumulation" end |
#ansi_rain_intensity_forecast(forecast) ⇒ Object
19 20 21 22 23 |
# File 'lib/lita/handlers/forecasts.rb', line 19 def ansi_rain_intensity_forecast(forecast) (str, precip_type) = do_the_rain_intensity_thing(forecast, ansi_chars, 'precipIntensity') #, 'probability', get_rain_range_colors) agg = get_max_by_data_key(forecast, 'minutely', 'precipIntensity') "1hr #{precip_type} intensity #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s}, #{get_accumulation agg} accumulation" end |
#ansi_temp_apparent_forecast(forecast, hours = 24) ⇒ Object
148 149 150 151 |
# File 'lib/lita/handlers/forecasts.rb', line 148 def ansi_temp_apparent_forecast(forecast, hours = 24) str, temperature_data = do_the_temp_thing(forecast, 'apparentTemperature', ansi_chars, hours) "#{hours} hr apparent temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}" end |
#ansi_temp_forecast(forecast, hours = 24) ⇒ Object
143 144 145 146 |
# File 'lib/lita/handlers/forecasts.rb', line 143 def ansi_temp_forecast(forecast, hours = 24) str, temperature_data = do_the_temp_thing(forecast, 'temperature', ansi_chars, hours) "#{hours} hr temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}" end |
#ansi_wind_direction_forecast(forecast) ⇒ Object
215 216 217 218 |
# File 'lib/lita/handlers/forecasts.rb', line 215 def ansi_wind_direction_forecast(forecast) str, wind_speed, wind_gust = do_the_wind_direction_thing(forecast, ansi_wind_arrows) "48h wind direction #{get_speed wind_speed.first}|#{str}|#{get_speed wind_speed.last} Range: #{get_speed(wind_speed.min)} - #{get_speed(wind_speed.max)}, gusting to #{get_speed wind_gust.max}" end |
#ansi_windchill_forecast(forecast, hours = 24) ⇒ Object
153 154 155 156 |
# File 'lib/lita/handlers/forecasts.rb', line 153 def ansi_windchill_forecast(forecast, hours = 24) str, temperature_data = do_the_windchill_temp_thing(forecast, ansi_chars, hours) "#{hours} hr windchill temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}" end |
#ascii_rain_forecast(forecast) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/lita/handlers/forecasts.rb', line 5 def ascii_rain_forecast(forecast) (str, precip_type) = do_the_rain_chance_thing(forecast, ascii_chars, 'precipProbability') max = get_max_by_data_key(forecast, 'minutely', 'precipProbability') agg = get_max_by_data_key(forecast, 'minutely', 'precipIntensity') "1hr #{precip_type} probability #{(Time.now).strftime('%H:%M').to_s}|#{str}|#{(Time.now + 3600).strftime('%H:%M').to_s} max #{(max.to_f * 100).round(2)}%, #{get_accumulation agg} accumulation" end |
#ascii_temp_forecast(forecast, hours = 24) ⇒ Object
158 159 160 161 |
# File 'lib/lita/handlers/forecasts.rb', line 158 def ascii_temp_forecast(forecast, hours = 24) str, temperature_data = do_the_temp_thing(forecast, 'temperature', ascii_chars, hours) "#{hours} hr temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}" end |
#ascii_wind_direction_forecast(forecast) ⇒ Object
220 221 222 223 |
# File 'lib/lita/handlers/forecasts.rb', line 220 def ascii_wind_direction_forecast(forecast) str, wind_speed, wind_gust = do_the_wind_direction_thing(forecast, ascii_wind_arrows) "48h wind direction #{get_speed wind_speed.first}|#{str}|#{get_speed wind_speed.last} Range: #{get_speed(wind_speed.min)} - #{get_speed(wind_speed.max)}, gusting to #{get_speed wind_gust.max}" end |
#calculate_windchill(temp_c, wind) ⇒ Object
Temp must be F.
209 210 211 212 213 |
# File 'lib/lita/handlers/forecasts.rb', line 209 def calculate_windchill(temp_c, wind) #temp_f = fahrenheit(temp_c) #35.74 + (0.6215 * temp_f) - (35.75 * wind ** 0.16) + (0.4275 * temp_f * wind ** 0.16) 13.12 + (0.6215 * temp_c) - (11.37 * (wind ** 0.16)) + (0.3965 * (temp_c * (wind ** 0.16))) end |
#conditions(forecast) ⇒ Object
345 346 347 348 349 350 351 352 353 354 |
# File 'lib/lita/handlers/forecasts.rb', line 345 def conditions(forecast) temp_str, temps = do_the_temp_thing(forecast, 'temperature', ansi_chars, 8) wind_str, winds = do_the_wind_direction_thing(forecast, ansi_wind_arrows, 8) rain_str, rains = do_the_rain_chance_thing(forecast, ansi_chars, 'precipProbability', config.colors, 15) sun_chance = ((1 - forecast['daily']['data'][0]['cloudCover']) * 100).round "#{get_temperature temps.first.round(2)} |#{temp_str}| #{get_temperature temps.last.round(2)} "\ "/ #{get_speed(winds.first)} |#{wind_str}| #{get_speed(winds.last)} "\ "/ #{sun_chance}% chance of sun / 60m precip |#{rain_str}|" end |
#do_the_cloud_thing(forecast, chars) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/lita/handlers/forecasts.rb', line 294 def do_the_cloud_thing(forecast, chars) # O ◎ ] data = forecast['hourly']['data'].slice(0,23) max = 0 min = 1 data.each do |datum| if datum['cloudCover'] > max max = datum['cloudCover'] end if datum['cloudCover'] < min min = datum['cloudCover'] end end str = get_dot_str(chars, data, 0, 1, 'cloudCover') "24h cloud cover |#{str}| range #{min * 100}% - #{max * 100}%" end |
#do_the_daily_humidity_thing(forecast) ⇒ Object
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/lita/handlers/forecasts.rb', line 454 def do_the_daily_humidity_thing(forecast) humidities = [] data = forecast['daily']['data'] data.each do |day| humidities.push day['humidity'] end str = get_dot_str(ansi_chars, data, 0, 1, 'humidity') if config.colors str = get_colored_string(data, 'humidity', str, get_wind_range_colors) end "7day humidity #{get_humidity humidities.first}|#{str}|#{get_humidity humidities.last} "\ "range #{get_humidity humidities.min}-#{get_humidity humidities.max}" end |
#do_the_daily_pressure_thing(forecast) ⇒ Object
495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/lita/handlers/forecasts.rb', line 495 def do_the_daily_pressure_thing(forecast) # O ◎ ] data = forecast['daily']['data'] key = 'pressure' boiled_data = [] data.each do |d| boiled_data.push d[key] end str = get_dot_str(ansi_chars, data, boiled_data.min, boiled_data.max - boiled_data.min, key) "pressure #{data.first[key]} hPa |#{str}| #{data.last[key]} hPa range: #{boiled_data.min}-#{boiled_data.max} hPa [8 day forecast]" end |
#do_the_daily_rain_thing(forecast) ⇒ Object
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/lita/handlers/forecasts.rb', line 405 def do_the_daily_rain_thing(forecast) precip_type = 'rain' rains = [] data = forecast['hourly']['data'] data.each do |day| if day['precipType'] == 'snow' precip_type = 'snow' end rains.push day['precipProbability'] end str = get_dot_str(ansi_chars, data, 0, 1, 'precipProbability') if 'snow' == precip_type data.each_with_index do |datum, index| if datum['precipType'] == 'snow' str[index] = get_snowman config end end end if config.colors str = get_colored_string(data, 'precipProbability', str, get_rain_range_colors) end max = get_max_by_data_key(forecast, 'hourly', 'precipProbability') agg = get_aggregate_by_data_key(forecast, 'hourly', 'precipIntensity') "48 hr #{precip_type}s |#{str}| max #{(max.to_f * 100).round}%, #{get_accumulation agg} accumulation" end |
#do_the_daily_sun_thing(forecast, chars) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/lita/handlers/forecasts.rb', line 271 def do_the_daily_sun_thing(forecast, chars) key = 'cloudCover' data_points = [] data = forecast['daily']['data'] data.each do |datum| data_points.push (1 - datum[key]).to_f # It's a cloud cover percentage, so let's inverse it to give us sun cover. datum[key] = (1 - datum[key]).to_f # Mod the source data for the get_dot_str call below. end differential = data_points.max - data_points.min str = get_dot_str(chars, data, data_points.min, differential, key) if config.colors str = get_colored_string(data, key, str, get_sun_range_colors) end max = 1 - get_min_by_data_key(forecast, 'daily', key) "8 day sun forecast |#{str}| max #{(max * 100).to_i}%" end |
#do_the_daily_wind_thing(forecast) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/lita/handlers/forecasts.rb', line 437 def do_the_daily_wind_thing(forecast) winds = [] data = forecast['daily']['data'] data.each do |day| winds.push day['windSpeed'] end str = get_dot_str(ansi_chars, data, 0, winds.max, 'windSpeed') if config.colors str = get_colored_string(data, 'windSpeed', str, get_wind_range_colors) end "7day winds #{get_speed winds.first}|#{str}|#{get_speed winds.last} range #{get_speed winds.min}-#{get_speed winds.max}" end |
#do_the_fog_thing(forecast, chars) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/lita/handlers/forecasts.rb', line 313 def do_the_fog_thing(forecast, chars) key = 'visibility' data_points = [] data = forecast['hourly']['data'].slice(0,23) max = 0 min = 10 data.each do |datum| max = datum[key] if datum[key] > max min = datum[key] if datum[key] < min data_points.push (10 - datum[key]).to_f # It's a visibility number, so let's inverse it to give us fog. datum[key] = (10 - datum[key]).to_f # Mod the source data for the get_dot_str call below. end differential = data_points.max - data_points.min str = get_dot_str(chars, data, 0, 10, key) "24h fog report |#{str}| visibility #{min}mi - #{max}mi" end |
#do_the_humidity_thing(forecast, chars, key) ⇒ Object
, type, range_colors = nil)
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/lita/handlers/forecasts.rb', line 127 def do_the_humidity_thing(forecast, chars, key) #, type, range_colors = nil) data_points = [] data = forecast['hourly']['data'] data.each do |datum| data_points.push datum[key] end str = get_dot_str(chars, data, 0, 1, key) if config.colors str = get_colored_string(data, key, str, get_humidity_range_colors) end "#{get_humidity data_points.first}|#{str}|#{get_humidity data_points.last} range: #{get_humidity data_points.min}-#{get_humidity data_points.max}" end |
#do_the_nearest_storm_thing(forecast) ⇒ Object
519 520 521 |
# File 'lib/lita/handlers/forecasts.rb', line 519 def do_the_nearest_storm_thing(forecast) return forecast['currently']['nearestStormDistance'], forecast['currently']['nearestStormBearing'] end |
#do_the_ozone_thing(forecast) ⇒ Object
472 473 474 475 476 477 478 479 |
# File 'lib/lita/handlers/forecasts.rb', line 472 def do_the_ozone_thing(forecast) # O ◎ ] data = forecast['hourly']['data'] str = get_dot_str(ozone_chars, data, 280, 350-280, 'ozone') "ozones #{data.first['ozone']} |#{str}| #{data.last['ozone']} [24h forecast]" end |
#do_the_pressure_thing(forecast) ⇒ Object
481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/lita/handlers/forecasts.rb', line 481 def do_the_pressure_thing(forecast) data = forecast['hourly']['data'] key = 'pressure' boiled_data = [] data.each do |d| boiled_data.push d[key] end str = get_dot_str(ansi_chars, data, boiled_data.min, boiled_data.max - boiled_data.min, key) "pressure #{data.first[key]} hPa |#{str}| #{data.last[key]} hPa range: #{boiled_data.min}-#{boiled_data.max} hPa [48h forecast]" end |
#do_the_rain_chance_thing(forecast, chars, key, use_color = config.colors, minute_limit = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/lita/handlers/forecasts.rb', line 60 def do_the_rain_chance_thing(forecast, chars, key, use_color = config.colors, minute_limit = nil) if forecast['minutely'].nil? return 'No minute-by-minute data available.' end i_can_has_snow = false data_points = [] data = forecast['minutely']['data'] data.each do |datum| data_points.push datum[key] if datum['precipType'] == 'snow' i_can_has_snow = true end end if minute_limit data = condense_data(data, minute_limit) end str = get_dot_str(chars, data, 0, 1, key) if i_can_has_snow data.each_with_index do |datum, index| if datum['precipType'] == 'snow' str[index] = get_snowman config end end end if use_color str = get_colored_string(data, key, str, get_rain_range_colors) end precip_type = i_can_has_snow ? 'snow' : 'rain' return str, precip_type end |
#do_the_rain_intensity_thing(forecast, chars, key) ⇒ Object
, type, range_colors = nil)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lita/handlers/forecasts.rb', line 99 def do_the_rain_intensity_thing(forecast, chars, key) #, type, range_colors = nil) if forecast['minutely'].nil? return 'No minute-by-minute data available.' # The "Middle of Nowhere" case. end i_can_has_snow = false data_points = [] data = forecast['minutely']['data'] data.each do |datum| data_points.push datum[key] if datum['precipType'] == 'snow' i_can_has_snow = true end end # Fixed range graph- 0-0.11. str = get_dot_str(chars, data, 0, 0.11, key) if config.colors str = get_colored_string(data, key, str, get_rain_intensity_range_colors) end precip_type = i_can_has_snow ? 'snow' : 'rain' return str, precip_type end |
#do_the_seven_day_rain_thing(forecast) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/lita/handlers/forecasts.rb', line 382 def do_the_seven_day_rain_thing(forecast) precip_type = 'rain' rains = [] data = forecast['daily']['data'] data.each do |day| if day['precipType'] == 'snow' precip_type = 'snow' end rains.push day['precipProbability'] end str = get_dot_str(ansi_chars, data, 0, 1, 'precipProbability') if config.colors str = get_colored_string(data, 'precipProbability', str, get_rain_range_colors) end max = get_max_by_data_key(forecast, 'daily', 'precipProbability') "7day #{precip_type}s |#{str}| max #{max * 100}%" end |
#do_the_seven_day_thing(forecast) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/lita/handlers/forecasts.rb', line 356 def do_the_seven_day_thing(forecast) mintemps = [] maxtemps = [] data = forecast['daily']['data'] data.each do |day| mintemps.push day['temperatureMin'] maxtemps.push day['temperatureMax'] end differential = maxtemps.max - maxtemps.min max_str = get_dot_str(ansi_chars, data, maxtemps.min, differential, 'temperatureMax') differential = mintemps.max - mintemps.min min_str = get_dot_str(ansi_chars, data, mintemps.min, differential, 'temperatureMin') if config.colors max_str = get_colored_string(data, 'temperatureMax', max_str, get_temp_range_colors) min_str = get_colored_string(data, 'temperatureMin', min_str, get_temp_range_colors) end "7day high/low temps #{get_temperature maxtemps.first.to_f.round(1)} |#{max_str}| #{get_temperature maxtemps.last.to_f.round(1)} "\ "/ #{get_temperature mintemps.first.to_f.round(1)} |#{min_str}| #{get_temperature mintemps.last.to_f.round(1)} "\ "Range: #{get_temperature mintemps.min} - #{get_temperature maxtemps.max}" end |
#do_the_sun_thing(forecast, chars) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/lita/handlers/forecasts.rb', line 247 def do_the_sun_thing(forecast, chars) key = 'cloudCover' data_points = [] data = forecast['hourly']['data'] sun_mod_data = [] data.each do |datum| data_points.push (1 - datum[key]).to_f # It's a cloud cover percentage, so let's inverse it to give us sun cover. sun_mod_data << {key => (1 - datum[key]).to_f} # Mod the source data for the get_dot_str call below. end differential = data_points.max - data_points.min str = get_dot_str(chars, sun_mod_data, data_points.min, differential, key) if config.colors str = get_colored_string(sun_mod_data, key, str, get_sun_range_colors) end max = 1 - get_min_by_data_key(forecast, 'hourly', key) "48hr sun forecast |#{str}| max #{(max * 100).to_i}%" end |
#do_the_sunrise_thing(forecast) ⇒ Object
335 336 337 338 |
# File 'lib/lita/handlers/forecasts.rb', line 335 def do_the_sunrise_thing(forecast) t = Time.at(fix_time(forecast['daily']['data'][0]['sunriseTime'], forecast['offset'])) t.strftime("%H:%M:%S") end |
#do_the_sunset_thing(forecast) ⇒ Object
340 341 342 343 |
# File 'lib/lita/handlers/forecasts.rb', line 340 def do_the_sunset_thing(forecast) t = Time.at(fix_time(forecast['daily']['data'][0]['sunsetTime'], forecast['offset'])) t.strftime("%H:%M:%S") end |
#do_the_temp_thing(forecast, key, chars, hours) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/lita/handlers/forecasts.rb', line 163 def do_the_temp_thing(forecast, key, chars, hours) temps = [] data = forecast['hourly']['data'].slice(0,hours - 1) data.each_with_index do |datum, index| temps.push datum[key] break if index == hours - 1 # We only want (hours) 24hrs of data. end differential = temps.max - temps.min # Hmm. There's a better way. dot_str = get_dot_str(chars, data, temps.min, differential, key) if config.colors dot_str = get_colored_string(data, key, dot_str, get_temp_range_colors) end return dot_str, temps end |
#do_the_today_thing(forecast, yesterday) ⇒ Object
523 524 525 526 527 |
# File 'lib/lita/handlers/forecasts.rb', line 523 def do_the_today_thing(forecast, yesterday) Lita.logger.info "Basing today on today - yesterday: #{yesterday['daily']['data'][0]['temperatureMax']} - #{forecast['daily']['data'][0]['temperatureMax']}" temp_diff = yesterday['daily']['data'][0]['temperatureMax'] - forecast['daily']['data'][0]['temperatureMax'] get_daily_comparison_text(temp_diff, forecast['daily']['data'][0]['temperatureMax']) end |
#do_the_tomorrow_thing(forecast) ⇒ Object
529 530 531 532 533 |
# File 'lib/lita/handlers/forecasts.rb', line 529 def do_the_tomorrow_thing(forecast) Lita.logger.info "Basing tomorrow on today - tomorrow: #{forecast['daily']['data'][0]['temperatureMax']} - #{forecast['daily']['data'][1]['temperatureMax']}" temp_diff = forecast['daily']['data'][0]['temperatureMax'] - forecast['daily']['data'][1]['temperatureMax'] get_daily_comparison_text(temp_diff, forecast['daily']['data'][0]['temperatureMax']) end |
#do_the_uvindex_thing(forecast) ⇒ Object
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
# File 'lib/lita/handlers/forecasts.rb', line 661 def do_the_uvindex_thing(forecast) uvs = [] forecast['hourly']['data'].each do |hour| uvs.push hour['uvIndex'] end data = forecast['hourly']['data'] str = get_dot_str(ansi_chars, data, uvs.min, uvs.max - uvs.min, key = 'uvIndex') if config.colors str = get_colored_string(data, 'uvIndex', str, get_uvindex_colors) end "#{uvs.first} |#{str}| #{uvs.last} max: #{uvs.max}" end |
#do_the_wind_direction_thing(forecast, wind_arrows, hours = 48) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/lita/handlers/forecasts.rb', line 225 def do_the_wind_direction_thing(forecast, wind_arrows, hours = 48) key = 'windBearing' data = forecast['hourly']['data'].slice(0,hours - 1) str = '' data_points = [] gust_data = [] data.each_with_index do |datum, index| wind_arrow_index = get_cardinal_direction_from_bearing(datum[key]) str << wind_arrows[wind_arrow_index].to_s data_points.push datum['windSpeed'] gust_data.push datum['windGust'] break if index == hours - 1 # We only want (hours) of data. end if config.colors str = get_colored_string(data, 'windSpeed', str, get_wind_range_colors) end return str, data_points, gust_data end |
#do_the_windchill_temp_thing(forecast, chars, hours) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/lita/handlers/forecasts.rb', line 184 def do_the_windchill_temp_thing(forecast, chars, hours) temps = [] wind = [] data = forecast['hourly']['data'].slice(0,hours - 1) key = 'temperature' wind_key = 'windSpeed' data.each_with_index do |datum, index| temps.push calculate_windchill(datum[key], datum[wind_key]) break if index == hours - 1 # We only want (hours) 24hrs of data. end differential = temps.max - temps.min # Hmm. There's a better way. dot_str = get_dot_str(chars, data, temps.min, differential, key) if config.colors dot_str = get_colored_string(data, key, dot_str, get_temp_range_colors) end return dot_str, temps end |
#do_the_windows_data_thing(forecast) ⇒ Object
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
# File 'lib/lita/handlers/forecasts.rb', line 606 def do_the_windows_data_thing(forecast) time_to_close_the_windows = nil time_to_open_the_windows = nil window_close_temp = 0 high_temp = 0 last_temp = 0 forecast['hourly']['data'].each_with_index do |hour, index| if hour['temperature'] > high_temp high_temp = hour['temperature'].to_i end if !time_to_close_the_windows and hour['temperature'].to_i >= 71 if index == 0 time_to_close_the_windows = 'now' else time_to_close_the_windows = hour['time'] end window_close_temp = hour['temperature'] end if !time_to_open_the_windows and time_to_close_the_windows and hour['temperature'] < last_temp and hour['temperature'].to_i <= 75 time_to_open_the_windows = hour['time'] end last_temp = hour['temperature'] break if index > 18 end # Return some meta here and let the caller decide the text. if time_to_close_the_windows.nil? "Leave 'em open, no excess heat today(#{get_temperature high_temp})." else # Todo: base timezone on requested location. timezone = TZInfo::Timezone.get('America/Los_Angeles') if time_to_close_the_windows == 'now' output = "Close the windows now! It is #{get_temperature window_close_temp}. " else time_at = Time.at(time_to_close_the_windows).to_datetime local_time = timezone.utc_to_local(time_at) output = "Close the windows at #{local_time.strftime('%k:%M')}, it will be #{get_temperature window_close_temp}. " end if time_to_open_the_windows open_time = timezone.utc_to_local(Time.at(time_to_open_the_windows).to_datetime) output += "Open them back up at #{open_time.strftime('%k:%M')}. " end output += "The high today will be #{get_temperature high_temp}." datas = { 'timeToClose': local_time.strftime('%k:%M'), 'timeToOpen': open_time.strftime('%k:%M'), 'tempMax': high_temp, 'temp': window_close_temp } end end |
#do_the_windows_thing(forecast) ⇒ Object
Check for the time of day when it will hit 72F.
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/lita/handlers/forecasts.rb', line 551 def do_the_windows_thing(forecast) time_to_close_the_windows = nil time_to_open_the_windows = nil window_close_temp = 0 high_temp = 0 last_temp = 0 forecast['hourly']['data'].each_with_index do |hour, index| if hour['temperature'] > high_temp high_temp = hour['temperature'].to_i end if !time_to_close_the_windows and hour['temperature'].to_i >= 71 if index == 0 time_to_close_the_windows = 'now' else time_to_close_the_windows = hour['time'] end window_close_temp = hour['temperature'] end if !time_to_open_the_windows and time_to_close_the_windows and hour['temperature'] < last_temp and hour['temperature'].to_i <= 75 time_to_open_the_windows = hour['time'] end last_temp = hour['temperature'] break if index > 18 end # Return some meta here and let the caller decide the text. if time_to_close_the_windows.nil? "Leave 'em open, no excess heat today(#{get_temperature high_temp})." if high_temp <= 68 and high_temp > 62 "Open them up mid-day, high temp #{get_temperature high_temp}." elsif high_temp <= 62 "Best leave 'em shut, high temp #{get_temperature high_temp}." end else # Todo: base timezone on requested location. timezone = TZInfo::Timezone.get('America/Los_Angeles') if time_to_close_the_windows == 'now' output = "Close the windows now! It is #{get_temperature window_close_temp}. " else time_at = Time.at(time_to_close_the_windows).to_datetime local_time = timezone.utc_to_local(time_at) output = "Close the windows at #{local_time.strftime('%k:%M')}, it will be #{get_temperature window_close_temp}. " end if time_to_open_the_windows open_time = timezone.utc_to_local(Time.at(time_to_open_the_windows).to_datetime) output += "Open them back up at #{open_time.strftime('%k:%M')}. " end output += "The high today will be #{get_temperature high_temp}." end end |
#get_aggregate_by_data_key(forecast, key, datum) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lita/handlers/forecasts.rb', line 49 def get_aggregate_by_data_key(forecast, key, datum) unless forecast[key].nil? sum = 0 forecast[key]['data'].each do |data_point| Lita.logger.debug "Adding #{data_point[datum]} to #{sum}" sum += data_point[datum].to_f end sum.round(3) end end |
#get_alerts(forecast) ⇒ Object
510 511 512 513 514 515 516 517 |
# File 'lib/lita/handlers/forecasts.rb', line 510 def get_alerts(forecast) str = '' forecast['alerts'].each do |alert| alert['description'].match /\.\.\.(\w+)\.\.\./ str += "#{alert['uri']}\n" end str end |
#get_daily_comparison_text(temp_diff, high) ⇒ Object
If the temperature difference is positive,
536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/lita/handlers/forecasts.rb', line 536 def get_daily_comparison_text(temp_diff, high) if temp_diff <= 1 and temp_diff >= -1 'about the same as' elsif temp_diff > 1 and temp_diff <= 5 'cooler than' elsif temp_diff > 5 (high > 70)? 'much cooler than' : 'much colder than' elsif temp_diff < -1 and temp_diff >= -5 'warmer than' elsif temp_diff < -5 (high < 70)? 'much warmer than' : 'much hotter than' end end |
#get_max_by_data_key(forecast, key, datum) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/lita/handlers/forecasts.rb', line 29 def get_max_by_data_key(forecast, key, datum) unless forecast[key].nil? data_points = [] forecast[key]['data'].each do |data_point| data_points.push data_point[datum] end data_points.max end end |
#get_min_by_data_key(forecast, key, datum) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/lita/handlers/forecasts.rb', line 39 def get_min_by_data_key(forecast, key, datum) unless forecast[key].nil? data_points = [] forecast[key]['data'].each do |data_point| data_points.push data_point[datum] end data_points.min end end |