Class: Trifle::Stats::Operations::Timeseries::Values

Inherits:
Object
  • Object
show all
Defined in:
lib/trifle/stats/operations/timeseries/values.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 8

def key
  @key
end

#rangeObject (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_valuesObject



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

#configObject



19
20
21
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 19

def config
  @config || Trifle::Stats.default
end

#dataObject



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

#performObject



51
52
53
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 51

def perform
  @skip_blanks ? clean_values : values
end

#timelineObject



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

#valuesObject



44
45
46
47
48
49
# File 'lib/trifle/stats/operations/timeseries/values.rb', line 44

def values
  {
    at: timeline,
    values: data
  }
end