Class: WrfForecast::Threshold::ThresholdHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/wrf_forecast/threshold/threshold_handler.rb

Overview

This class maintains the different threshold classes and initializes them with the data of the forecast repository.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(forecast_repository) ⇒ ThresholdHandler

initialization

Parameters:

  • forecast_repository (ForecastRepository)

    the forecast repository holding the forecast data



22
23
24
25
26
27
28
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 22

def initialize(forecast_repository)
  data = forecast_repository.forecast_data
  @temperature_threshold = WrfForecast::Threshold::TemperatureThreshold.new(data[:air_temperature])
  @wind_threshold = WrfForecast::Threshold::WindThreshold.new(data[:wind_speed])
  @rain_threshold = WrfForecast::Threshold::RainThreshold.new(forecast_repository.hourly_rain)
  collect_active_thresholds
end

Instance Attribute Details

#rain_thresholdRainThreshold (readonly)

Returns the class holding the rain thresholds.

Returns:



16
17
18
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 16

def rain_threshold
  @rain_threshold
end

#temperature_thresholdTemperatureThreshold (readonly)

Returns the class holding the temperature thresholds.

Returns:



12
13
14
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 12

def temperature_threshold
  @temperature_threshold
end

#warningsHash (readonly)

Returns the mapping of measurand and triggered thresholds for the current forecast.

Returns:

  • (Hash)

    the mapping of measurand and triggered thresholds for the current forecast



18
19
20
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 18

def warnings
  @warnings
end

#wind_thresholdWindThreshold (readonly)

Returns the class holding the wind thresholds.

Returns:



14
15
16
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 14

def wind_threshold
  @wind_threshold
end

Instance Method Details

#collect_active_thresholdsObject (private)

method to collect all overstepped thresholds indicating significant weather



33
34
35
36
37
38
39
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 33

def collect_active_thresholds
  @warnings = Hash.new()
  @warnings[:air_temperature] = collect_thresholds_for(@temperature_threshold)
  @warnings[:wind_speed] = collect_thresholds_for(@wind_threshold)
  @warnings[:rain] = collect_thresholds_for(@rain_threshold)
  nil
end

#collect_thresholds_for(threshold) ⇒ Object (private)

method to collect the overstepped thresholds for the given measurand threshold



42
43
44
45
46
47
48
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 42

def collect_thresholds_for(threshold)
  active_thresholds = Array.new()
  threshold.indicators.each_value { |value| 
    active_thresholds << value if(value.is_active)
  }
  return active_thresholds
end