Class: Opower::TimeSeries::SyntheticResult::FormulaMap

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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ FormulaMap

Initializes the formula map using the set of results received from OpenTSDB.

Parameters:

  • data (Hash)

    A hash mapping formula parameters to OpenTSDB results



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

#parametersObject (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.

Parameters:

  • ts (String)

    the OpenTSDB timestamp to check (yes, it’s a String from OpenTSDB)



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