Class: Trifle::Stats::Operations::Timeseries::Values
- Inherits:
-
Object
- Object
- Trifle::Stats::Operations::Timeseries::Values
- Defined in:
- lib/trifle/stats/operations/timeseries/values.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
- #clean_values ⇒ Object
- #config ⇒ Object
- #data ⇒ Object
-
#initialize(**keywords) ⇒ Values
constructor
A new instance of Values.
- #perform ⇒ Object
- #timeline ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(**keywords) ⇒ Values
Returns a new instance of Values.
10 11 12 13 14 15 16 17 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 10 def initialize(**keywords) @key = keywords.fetch(:key) @from = keywords.fetch(:from) @to = keywords.fetch(:to) @range = keywords.fetch(:range) @config = keywords[:config] @skip_blanks = keywords[:skip_blanks] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 8 def key @key end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
8 9 10 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 8 def range @range end |
Instance Method Details
#clean_values ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 35 def clean_values timeline.each_with_object({ at: [], values: [] }).with_index do |(_at, res), idx| next if data[idx].empty? res[:at] << timeline[idx] res[:values] << data[idx] end end |
#config ⇒ Object
19 20 21 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 19 def config @config || Trifle::Stats.default end |
#data ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 27 def data @data ||= config.driver.get( keys: timeline.map do |at| Nocturnal::Key.new(key: key, range: range, at: at) end ) end |
#perform ⇒ Object
51 52 53 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 51 def perform @skip_blanks ? clean_values : values end |
#timeline ⇒ Object
23 24 25 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 23 def timeline @timeline ||= Nocturnal.timeline(from: @from, to: @to, range: range) end |
#values ⇒ Object
44 45 46 47 48 49 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 44 def values { at: timeline, values: data } end |