Class: Opower::TimeSeries::SyntheticResult::FormulaMap
- Inherits:
-
Object
- Object
- Opower::TimeSeries::SyntheticResult::FormulaMap
- Defined in:
- lib/time_series/results/synthetic_result.rb
Overview
Merges all matching data point timestamps together and assigns their values to formula keys
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
-
#build_hash(ts) ⇒ Object
Checks each of the keys in the data provided to see if they contain a data-point at the specified timestamp.
-
#initialize(data) ⇒ FormulaMap
constructor
Initializes the formula map using the set of results received from OpenTSDB.
Constructor Details
#initialize(data) ⇒ FormulaMap
Initializes the formula map using the set of results received from OpenTSDB.
79 80 81 82 83 84 85 86 |
# File 'lib/time_series/results/synthetic_result.rb', line 79 def initialize(data) @data = data @parameters = {} @data[@data.keys.sample].each_key do |ts| build_hash(ts) end end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
74 75 76 |
# File 'lib/time_series/results/synthetic_result.rb', line 74 def parameters @parameters end |
Instance Method Details
#build_hash(ts) ⇒ Object
Checks each of the keys in the data provided to see if they contain a data-point at the specified timestamp. Does nothing if any of the keys is missing a data-point.
92 93 94 95 96 97 98 99 |
# File 'lib/time_series/results/synthetic_result.rb', line 92 def build_hash(ts) result = @data.map { |key, dps| { key => dps[ts] } if dps.key?(ts) } return if result.include?(nil) @parameters[ts] = result.reduce do |formula_map, parameter| formula_map.merge(parameter) end end |