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
-
#granularity ⇒ Object
readonly
Returns the value of attribute granularity.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
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) @granularity = keywords.fetch(:granularity) @config = keywords[:config] @skip_blanks = keywords[:skip_blanks] end |
Instance Attribute Details
#granularity ⇒ Object (readonly)
Returns the value of attribute granularity.
8 9 10 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 8 def granularity @granularity end |
#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 |
Instance Method Details
#clean_values ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 44 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
36 37 38 39 40 41 42 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 36 def data @data ||= config.driver.get( keys: timeline.map do |at| Nocturnal::Key.new(key: key, granularity: granularity, at: at) end ) end |
#perform ⇒ Object
60 61 62 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 60 def perform @skip_blanks ? clean_values : values end |
#timeline ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 23 def timeline @timeline ||= begin pgrn = Nocturnal::Parser.new(granularity) Nocturnal.timeline( from: localized_time(@from), to: localized_time(@to), offset: pgrn.offset, unit: pgrn.unit, config: config ) end end |
#values ⇒ Object
53 54 55 56 57 58 |
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 53 def values { at: timeline, values: data } end |