Class: Redis::TimeSeries::Aggregation
- Inherits:
-
Object
- Object
- Redis::TimeSeries::Aggregation
- Defined in:
- lib/redis/time_series/aggregation.rb
Overview
An aggregation is a combination of a mathematical function, and a time window over which to apply that function. In RedisTimeSeries, aggregations are used to downsample data from a source series to a destination series, using compaction rules.
Constant Summary collapse
- TYPES =
%w[ avg count first last max min range std.p std.s sum var.p var.s ]
Instance Attribute Summary collapse
-
#duration ⇒ Integer
(also: #time_bucket)
readonly
The time window to apply the aggregation over, in milliseconds.
-
#type ⇒ String
(also: #aggregation_type)
readonly
The type of aggregation to apply.
Class Method Summary collapse
-
.parse(agg) ⇒ Aggregation
Parse a method argument into an aggregation.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares aggregations based on type and duration.
-
#initialize(type, duration) ⇒ Aggregation
constructor
Create a new Aggregation given a type and duration.
- #to_a ⇒ Array private
- #to_s ⇒ String private
Constructor Details
#initialize(type, duration) ⇒ Aggregation
Create a new Aggregation given a type and duration.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/redis/time_series/aggregation.rb', line 55 def initialize(type, duration) type = type.to_s.downcase unless TYPES.include? type raise AggregationError, "#{type} is not a valid aggregation type!" end @type = type if defined?(ActiveSupport::Duration) && duration.is_a?(ActiveSupport::Duration) @duration = duration.in_milliseconds else @duration = duration.to_i end end |
Instance Attribute Details
#duration ⇒ Integer (readonly) Also known as: time_bucket
Returns the time window to apply the aggregation over, in milliseconds.
33 34 35 |
# File 'lib/redis/time_series/aggregation.rb', line 33 def duration @duration end |
#type ⇒ String (readonly) Also known as: aggregation_type
Returns the type of aggregation to apply.
29 30 31 |
# File 'lib/redis/time_series/aggregation.rb', line 29 def type @type end |
Class Method Details
.parse(agg) ⇒ Aggregation
Parse a method argument into an aggregation.
41 42 43 44 45 46 |
# File 'lib/redis/time_series/aggregation.rb', line 41 def self.parse(agg) return unless agg return agg if agg.is_a?(self) return new(agg.first, agg.last) if agg.is_a?(Array) && agg.size == 2 raise AggregationError, "Couldn't parse #{agg} into an aggregation rule!" end |
Instance Method Details
#==(other) ⇒ Boolean
Compares aggregations based on type and duration.
82 83 84 85 |
# File 'lib/redis/time_series/aggregation.rb', line 82 def ==(other) parsed = self.class.parse(other) type == parsed.type && duration == parsed.duration end |
#to_a ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 |
# File 'lib/redis/time_series/aggregation.rb', line 70 def to_a ['AGGREGATION', type, duration] end |
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/redis/time_series/aggregation.rb', line 76 def to_s to_a.join(' ') end |