Class: Opower::TimeSeries::SyntheticResult

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name, formula, data) ⇒ SyntheticResult

Initializes a synthetic results wrapper and runs the calculations on the results data.

Parameters:

  • name (String)
    • alias for this synthetic series

  • formula (String)
    • the formula used to calculate data together

  • data (Hash)
    • a hash containing key mappings to results to be used in the formula



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

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/time_series/results/synthetic_result.rb', line 9

def data
  @data
end

#resultsObject (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

#calculateObject

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

#lengthInteger

Gives the total results size after calculating synthetic metrics.

Returns:

  • (Integer)

    the number of data-points



39
40
41
# File 'lib/time_series/results/synthetic_result.rb', line 39

def length
  @results.keys.length
end