Class: Opower::TimeSeries::SyntheticResult
- Inherits:
-
Object
- Object
- Opower::TimeSeries::SyntheticResult
- Defined in:
- lib/time_series/results/synthetic_result.rb
Overview
Provides support for synthetic metrics
Defined Under Namespace
Classes: FormulaMap, TimeSeriesCalculator
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#calculate ⇒ Object
Calculates the result of the formula set for this synthetic result.
-
#initialize(name, formula, data) ⇒ SyntheticResult
constructor
Initializes a synthetic results wrapper and runs the calculations on the results data.
-
#length ⇒ Integer
Gives the total results size after calculating synthetic metrics.
Constructor Details
#initialize(name, formula, data) ⇒ SyntheticResult
Initializes a synthetic results wrapper and runs the calculations on the results data.
16 17 18 19 20 21 22 23 24 |
# File 'lib/time_series/results/synthetic_result.rb', line 16 def initialize(name, formula, data) @name = name @formula = formula @data = data @results = {} @calculator = TimeSeriesCalculator.new calculate end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/time_series/results/synthetic_result.rb', line 9 def data @data end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
9 10 11 |
# File 'lib/time_series/results/synthetic_result.rb', line 9 def results @results end |
Instance Method Details
#calculate ⇒ Object
Calculates the result of the formula set for this synthetic result. Currently, the timestamps of each of the queries must match in order for a calculation to be performed.
28 29 30 31 32 33 34 |
# File 'lib/time_series/results/synthetic_result.rb', line 28 def calculate formula_map = FormulaMap.new(@data) formula_map.parameters.each do |ts, parameter| @results[ts] = @calculator.evaluate(@formula, parameter) end end |
#length ⇒ Integer
Gives the total results size after calculating synthetic metrics.
39 40 41 |
# File 'lib/time_series/results/synthetic_result.rb', line 39 def length @results.keys.length end |