Class: Trifle::Stats::Operations::Timeseries::Classify
- Inherits:
-
Object
- Object
- Trifle::Stats::Operations::Timeseries::Classify
- Defined in:
- lib/trifle/stats/operations/timeseries/classify.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #classify(value) ⇒ Object
- #config ⇒ Object
- #deep_classify(hash) ⇒ Object
-
#initialize(**keywords) ⇒ Classify
constructor
A new instance of Classify.
- #key_for(range:) ⇒ Object
- #perform ⇒ Object
Constructor Details
#initialize(**keywords) ⇒ Classify
Returns a new instance of Classify.
10 11 12 13 14 15 |
# File 'lib/trifle/stats/operations/timeseries/classify.rb', line 10 def initialize(**keywords) @key = keywords.fetch(:key) @at = keywords.fetch(:at) @values = keywords.fetch(:values) @config = keywords[:config] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/trifle/stats/operations/timeseries/classify.rb', line 8 def key @key end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
8 9 10 |
# File 'lib/trifle/stats/operations/timeseries/classify.rb', line 8 def values @values end |
Instance Method Details
#classify(value) ⇒ Object
29 30 31 |
# File 'lib/trifle/stats/operations/timeseries/classify.rb', line 29 def classify(value) config.designator.designate(value: value).to_s.gsub('.', '_') end |
#config ⇒ Object
17 18 19 |
# File 'lib/trifle/stats/operations/timeseries/classify.rb', line 17 def config @config || Trifle::Stats.default end |
#deep_classify(hash) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/trifle/stats/operations/timeseries/classify.rb', line 21 def deep_classify(hash) hash.transform_values do |value| next deep_classify(value) if value.is_a?(Hash) { classify(value) => 1 } end end |
#key_for(range:) ⇒ Object
33 34 35 36 |
# File 'lib/trifle/stats/operations/timeseries/classify.rb', line 33 def key_for(range:) at = Nocturnal.new(@at, config: config).send(range) [key, range, at.to_i] end |
#perform ⇒ Object
38 39 40 41 42 43 |
# File 'lib/trifle/stats/operations/timeseries/classify.rb', line 38 def perform config.driver.inc( keys: config.ranges.map { |range| key_for(range: range) }, **deep_classify(values) ) end |