dataoperations-aggregate 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dataoperations-aggregate.rb +79 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88229d7d1a3eb43c59f593c15ed5350189f534927d849b8bb75e70583610bdb6
|
4
|
+
data.tar.gz: 812bea576d59f4211e659c6e6da8f37cdabbac7a01faadc9e8f09e3512f0ea7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dabc7016ecefa788042959f1184b258fe70d2468ed5e72e9a675902c1f2f53941559fe5e5083887f131662daf65e4f6339bf788269509f41da3093dd090b68e2
|
7
|
+
data.tar.gz: d0da00e819b18b73d0a942e2b8b871af276300936043cb09ebec48e0277bd1eb283ffbc57fdee3e73c1d400aae0149d7cfc9634dc45bf7533a9f68daa18f730f
|
@@ -12,7 +12,7 @@ module DataOperations
|
|
12
12
|
DEFAULT_TIME_STARTED_MODE = :first_message
|
13
13
|
DEFAULT_FIELD_NO_DATA_VALUE = 'no_data'.freeze
|
14
14
|
DEFAULT_AGGREGATIONS = %w[sum min max mean median variance standard_deviation].freeze
|
15
|
-
VALID_AGGREGATIONS = %w[sum min max mean median variance standard_deviation].freeze
|
15
|
+
VALID_AGGREGATIONS = %w[sum min max mean median variance standard_deviation bucket].freeze
|
16
16
|
DEFAULT_HASH_TIME_FORMAT = '%Y-%m-%dT%H'.freeze
|
17
17
|
DEFAULT_INERVAL_SECONDS = 3600
|
18
18
|
|
@@ -30,7 +30,9 @@ module DataOperations
|
|
30
30
|
log: Logger.new(STDOUT),
|
31
31
|
aggregation_names:,
|
32
32
|
group_field_names:,
|
33
|
-
aggregate_field_names
|
33
|
+
aggregate_field_names:,
|
34
|
+
buckets:[],
|
35
|
+
bucket_metrics:[]
|
34
36
|
)
|
35
37
|
@aggregator = aggregator
|
36
38
|
@time_format = time_format
|
@@ -43,6 +45,8 @@ module DataOperations
|
|
43
45
|
@processing_mode = processing_mode
|
44
46
|
@time_started_mode = time_started_mode
|
45
47
|
@aggregator_name = aggregator_name
|
48
|
+
@buckets = buckets
|
49
|
+
@bucket_metrics = bucket_metrics
|
46
50
|
|
47
51
|
|
48
52
|
if aggregation_names.nil? || !aggregation_names.is_a?(Array)
|
@@ -219,16 +223,51 @@ module DataOperations
|
|
219
223
|
# Aggregate data
|
220
224
|
if aggregate_field_value.is_a?(Array)
|
221
225
|
@aggregation_names.each do |operation|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
226
|
+
|
227
|
+
#If bucket, calculate bucket for metric
|
228
|
+
if operation == 'bucket'
|
229
|
+
#If set buckets and set metrics to calculate (bucket values depends of ranges based in metric activity)
|
230
|
+
if !@buckets.nil? && !@bucket_metrics.nil? && @bucket_metrics.include?(aggregate_field_key)
|
231
|
+
data_bucket = calculate_buckets(aggregate_field_value, @buckets)
|
232
|
+
|
233
|
+
data_bucket.each {|bucket,bucket_count|
|
234
|
+
#@log.info("#{aggregate_field_key}_#{bucket} = #{bucket_count}")
|
235
|
+
aggregator_data["#{aggregate_field_key}_bucket#{bucket}"] = bucket_count
|
236
|
+
}
|
237
|
+
|
238
|
+
# Add aggregated data to interval
|
239
|
+
group_item_value['intervals'].keys[1..-1].each do |interval_secs|
|
240
|
+
|
241
|
+
interval_aggregator_item_key = (aggregator_item_key / interval_secs.to_i) * interval_secs.to_i
|
242
|
+
interval_aggregator_item_value = group_item_value['intervals'][interval_secs][interval_aggregator_item_key]
|
243
|
+
data_bucket.each {|bucket,bucket_count|
|
244
|
+
#@log.info("#{aggregate_field_key}_#{bucket} = #{bucket_count}")
|
245
|
+
interval_aggregator_item_value['aggregate_fields'][aggregate_field_key]["bucket#{bucket}"] = [] if interval_aggregator_item_value['aggregate_fields'][aggregate_field_key]["bucket#{bucket}"].nil?
|
246
|
+
interval_aggregator_item_value['aggregate_fields'][aggregate_field_key]["bucket#{bucket}"] << bucket_count
|
247
|
+
}
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
else
|
253
|
+
data = aggregate_field_value.method(operation).call
|
254
|
+
aggregator_data["#{aggregate_field_key}_#{operation}"] = data
|
255
|
+
|
256
|
+
# Add aggregated data to interval
|
257
|
+
group_item_value['intervals'].keys[1..-1].each do |interval_secs|
|
258
|
+
interval_aggregator_item_key = (aggregator_item_key / interval_secs.to_i) * interval_secs.to_i
|
259
|
+
interval_aggregator_item_value = group_item_value['intervals'][interval_secs][interval_aggregator_item_key]
|
260
|
+
interval_aggregator_item_value['aggregate_fields'][aggregate_field_key][operation] << data
|
261
|
+
end
|
230
262
|
end
|
263
|
+
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
if !@buckets.nil? && ! @bucket_metrics.nil?
|
268
|
+
#data = calculate_buckets(data, @buckets)
|
231
269
|
end
|
270
|
+
|
232
271
|
end
|
233
272
|
end
|
234
273
|
|
@@ -244,6 +283,9 @@ module DataOperations
|
|
244
283
|
@aggregation_names.each do |operation|
|
245
284
|
interval_aggregator_item_value['aggregate_fields'][aggregate_field_key][operation] = []
|
246
285
|
end
|
286
|
+
|
287
|
+
##Add buckets metadata (empty hash)
|
288
|
+
##interval_aggregator_item_value['aggregate_fields'][aggregate_field_key]['buckets']={}
|
247
289
|
end
|
248
290
|
end
|
249
291
|
|
@@ -297,10 +339,17 @@ module DataOperations
|
|
297
339
|
case operation
|
298
340
|
when 'max', 'min', 'mean', 'median'
|
299
341
|
data = vector.method(operation).call
|
342
|
+
when 'bucket'
|
343
|
+
#Bucket operation generate bucket[\d]+
|
344
|
+
data = nil
|
345
|
+
when /^bucket[\d]+/
|
346
|
+
#For buckets sum accumulations for internvals
|
347
|
+
data = vector.method('sum').call
|
300
348
|
else
|
301
349
|
data = vector.median
|
302
350
|
end
|
303
|
-
|
351
|
+
#Nil data is avoid (for example for 'bucket' name operation)
|
352
|
+
aggregator_data["#{field_name}_#{operation}"] = data unless data.nil?
|
304
353
|
end
|
305
354
|
end
|
306
355
|
# @log.debug aggregator_item_value
|
@@ -310,5 +359,24 @@ module DataOperations
|
|
310
359
|
aggregate_data[s_interval] << aggregator_data
|
311
360
|
end
|
312
361
|
end
|
362
|
+
|
363
|
+
#Return Array with count by each bucket
|
364
|
+
def calculate_buckets(data, buckets_config)
|
365
|
+
buckets_config.sort!.uniq!
|
366
|
+
buckets = {}
|
367
|
+
|
368
|
+
buckets_config.each {|bucket| buckets[bucket] = 0}
|
369
|
+
|
370
|
+
data.each {|item|
|
371
|
+
buckets_config.each {|bucket|
|
372
|
+
if item <= bucket
|
373
|
+
buckets[bucket] += 1
|
374
|
+
next
|
375
|
+
end
|
376
|
+
}
|
377
|
+
}
|
378
|
+
return buckets
|
379
|
+
end
|
380
|
+
|
313
381
|
end
|
314
382
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dataoperations-aggregate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Guillen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: descriptive_statistics
|
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
rubygems_version: 3.0.3
|
53
|
+
rubygems_version: 3.0.3.1
|
54
54
|
signing_key:
|
55
55
|
specification_version: 4
|
56
56
|
summary: Aggregate data
|