Class: DataStore::AverageCalculator
- Inherits:
-
Object
- Object
- DataStore::AverageCalculator
- Defined in:
- lib/data_store/average_calculator.rb
Constant Summary collapse
- TIMESTAMP_CORRECTION_FACTOR =
0.0001
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#table_index ⇒ Object
readonly
Returns the value of attribute table_index.
Instance Method Summary collapse
-
#initialize(table) ⇒ AverageCalculator
constructor
A new instance of AverageCalculator.
-
#perform ⇒ Object
Calculate average value if needed Average value is store through an add call by a Table object So the average calculator is called again recursively.
Constructor Details
#initialize(table) ⇒ AverageCalculator
Returns a new instance of AverageCalculator.
9 10 11 12 13 14 |
# File 'lib/data_store/average_calculator.rb', line 9 def initialize(table) @table = table @identifier = table.identifier @table_index = table.table_index @base = Base.find(identifier: identifier) end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/data_store/average_calculator.rb', line 7 def base @base end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
7 8 9 |
# File 'lib/data_store/average_calculator.rb', line 7 def identifier @identifier end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
7 8 9 |
# File 'lib/data_store/average_calculator.rb', line 7 def table @table end |
#table_index ⇒ Object (readonly)
Returns the value of attribute table_index.
7 8 9 |
# File 'lib/data_store/average_calculator.rb', line 7 def table_index @table_index end |
Instance Method Details
#perform ⇒ Object
Calculate average value if needed Average value is store through an add call by a Table object So the average calculator is called again recursively
19 20 21 22 23 24 |
# File 'lib/data_store/average_calculator.rb', line 19 def perform if calculation_needed? average = previous_average_record ? calculate! : dataset.avg(:value) table.add(average, table_index: table_index + 1, created: last[:created], type: :gauge) end end |