Class: WrfForecast::Threshold::BaseThreshold
- Inherits:
-
Object
- Object
- WrfForecast::Threshold::BaseThreshold
- Defined in:
- lib/wrf_forecast/threshold/base_threshold.rb
Overview
This abstract class determines the significant thresholds for a forecast day. That means that this class can only work correctly if the data represents a time span of up to 24 hours. Will raise an NotImplementedError if the abstract methods are called without an implementation in a child class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#indicators ⇒ Hash
readonly
The indicator by mapping symbol => boolean.
Instance Method Summary collapse
-
#add_indicator(identifier, is_active, warning_text) ⇒ Object
private
method to add a threshold value to the indicator hash.
-
#change_indicator(identifier, flag, condition) ⇒ Object
private
method to change a given indicator to the given flag if the condition if met.
-
#check_data_values(data_values) ⇒ Object
private
method to check if the data sample offers enough data for the indicators less than 720 data points means, less than 1 data point every 2 minutes less then 48 data points means, less than 2 data points per hours.
-
#determine_indicators(data_values) ⇒ Object
private
abstract method to determine the indicators based on the input data.
-
#initialize(data_values) ⇒ BaseThreshold
constructor
initialization.
-
#initialize_indicators ⇒ Object
private
abstract method to initialize of the required indicators.
Constructor Details
#initialize(data_values) ⇒ BaseThreshold
initialization
23 24 25 26 27 28 |
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 23 def initialize(data_values) @indicators = Hash.new() initialize_indicators check_data_values(data_values) determine_indicators(data_values) end |
Instance Attribute Details
#indicators ⇒ Hash (readonly)
Returns the indicator by mapping symbol => boolean.
19 20 21 |
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 19 def indicators @indicators end |
Instance Method Details
#add_indicator(identifier, is_active, warning_text) ⇒ Object (private)
method to add a threshold value to the indicator hash
36 37 38 39 |
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 36 def add_indicator(identifier, is_active, warning_text) @indicators[identifier] = WrfForecast::Threshold::ThresholdValue.new(identifier, is_active, warning_text) end |
#change_indicator(identifier, flag, condition) ⇒ Object (private)
method to change a given indicator to the given flag if the condition if met
45 46 47 |
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 45 def change_indicator(identifier, flag, condition) @indicators[identifier].is_active = flag if (condition) end |
#check_data_values(data_values) ⇒ Object (private)
method to check if the data sample offers enough data for the indicators less than 720 data points means, less than 1 data point every 2 minutes less then 48 data points means, less than 2 data points per hours
53 54 55 56 57 58 59 60 |
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 53 def check_data_values(data_values) if (data_values.size < 720) puts "Warning: Data values for #{self.class} are lesser than 720." end if (data_values.size < 48) raise ArgumentError, "Error: Lesser than 48 data values available for threshold." end end |
#determine_indicators(data_values) ⇒ Object (private)
abstract method to determine the indicators based on the input data
72 73 74 75 |
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 72 def determine_indicators(data_values) fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: determine_indicators from its base class".red end |
#initialize_indicators ⇒ Object (private)
abstract method to initialize of the required indicators
64 65 66 67 |
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 64 def initialize_indicators fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: initialize_indicators from its base class".red end |