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



26
27
28
29
30
31
32
33
34
35
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 26

def initialize(forecast_repository)
  data = forecast_repository.forecast_data
  @pressure_threshold = WrfForecast::Threshold::PressureThreshold.new(data[:pressure])
  @air_temperature_threshold = WrfForecast::Threshold::AirTemperatureThreshold.new(data[:air_temperature])
  @apparent_temperature_threshold = WrfForecast::Threshold::ApparentTemperatureThreshold.
                                    new(data[:apparent_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

#air_temperature_thresholdAirTemperatureThreshold (readonly)

Returns the class holding the air temperature thresholds.

Returns:



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

def air_temperature_threshold
  @air_temperature_threshold
end

#apparent_temperature_thresholdApparentTemperatureThreshold (readonly)

Returns the class holding the apparent temperature thresholds.

Returns:



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

def apparent_temperature_threshold
  @apparent_temperature_threshold
end

#pressure_thresholdPressureThreshold (readonly)

Returns the class holding the pressure thresholds.

Returns:



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

def pressure_threshold
  @pressure_threshold
end

#rain_thresholdRainThreshold (readonly)

Returns the class holding the rain thresholds.

Returns:



20
21
22
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 20

def rain_threshold
  @rain_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



22
23
24
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 22

def warnings
  @warnings
end

#wind_thresholdWindThreshold (readonly)

Returns the class holding the wind thresholds.

Returns:



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

def wind_threshold
  @wind_threshold
end

Instance Method Details

#collect_active_thresholdsObject (private)

method to collect all overstepped thresholds indicating significant weather



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

def collect_active_thresholds
  @warnings = Hash.new()
  @warnings[:air_temperature] = collect_thresholds_for(@air_temperature_threshold)
  @warnings[:apparent_temperature] = collect_thresholds_for(@apparent_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



50
51
52
53
54
55
56
# File 'lib/wrf_forecast/threshold/threshold_handler.rb', line 50

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