dataoperations-aggregate 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dataoperations-aggregate.rb +65 -28
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88229d7d1a3eb43c59f593c15ed5350189f534927d849b8bb75e70583610bdb6
4
- data.tar.gz: 812bea576d59f4211e659c6e6da8f37cdabbac7a01faadc9e8f09e3512f0ea7b
3
+ metadata.gz: c368ec8e096b29b25a672bae856f1dc75f6cb597e5e8e1a3a7ede37b11919014
4
+ data.tar.gz: f0a01a9dab19a6102ae759c076ea4703717003b07f18e56be331a02a30ac1662
5
5
  SHA512:
6
- metadata.gz: dabc7016ecefa788042959f1184b258fe70d2468ed5e72e9a675902c1f2f53941559fe5e5083887f131662daf65e4f6339bf788269509f41da3093dd090b68e2
7
- data.tar.gz: d0da00e819b18b73d0a942e2b8b871af276300936043cb09ebec48e0277bd1eb283ffbc57fdee3e73c1d400aae0149d7cfc9634dc45bf7533a9f68daa18f730f
6
+ metadata.gz: 0adfbb913ad9dc057f4bcfa129ad2f3d8b01d16259165068d459608ca06cf29017249ec12537f33054ecc8a1e8df4c38e94d2442f0be1a9e5681ebb6d5f036a1
7
+ data.tar.gz: 4cbf7af8882233b867843d77b8c9f677121abd26f8536904b5ee4fae04e3b02034128a204d96930b0cc09bf70387a5549f5d5ff80eb1078baadebccf071cd3c8
@@ -12,7 +12,10 @@ 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 bucket].freeze
15
+ VALID_AGGREGATIONS = %w[sum min max mean median variance standard_deviation histogram].freeze
16
+ DEFAULT_HISTOGRAM_CUMULATIVE = false
17
+ DEFAULT_HISTOGRAM_BUCKET_INFINITE_ENABLED = true
18
+ DEFAULT_HISTOGRAM_BUCKET_COMPARATION = :less_or_equal
16
19
  DEFAULT_HASH_TIME_FORMAT = '%Y-%m-%dT%H'.freeze
17
20
  DEFAULT_INERVAL_SECONDS = 3600
18
21
 
@@ -31,8 +34,11 @@ module DataOperations
31
34
  aggregation_names:,
32
35
  group_field_names:,
33
36
  aggregate_field_names:,
34
- buckets:[],
35
- bucket_metrics:[]
37
+ histogram_cumulative: DEFAULT_HISTOGRAM_CUMULATIVE,
38
+ histogram_bucket_infinite_enabled: DEFAULT_HISTOGRAM_BUCKET_INFINITE_ENABLED,
39
+ histogram_bucket_comparation: DEFAULT_HISTOGRAM_BUCKET_COMPARATION,
40
+ histogram_buckets:[],
41
+ histogram_fields:[]
36
42
  )
37
43
  @aggregator = aggregator
38
44
  @time_format = time_format
@@ -45,8 +51,11 @@ module DataOperations
45
51
  @processing_mode = processing_mode
46
52
  @time_started_mode = time_started_mode
47
53
  @aggregator_name = aggregator_name
48
- @buckets = buckets
49
- @bucket_metrics = bucket_metrics
54
+ @histogram_cumulative = histogram_cumulative
55
+ @histogram_bucket_infinite_enabled = histogram_bucket_infinite_enabled
56
+ @histogram_bucket_comparation = histogram_bucket_comparation
57
+ @histogram_buckets = histogram_buckets
58
+ @histogram_fields = histogram_fields
50
59
 
51
60
 
52
61
  if aggregation_names.nil? || !aggregation_names.is_a?(Array)
@@ -224,15 +233,20 @@ module DataOperations
224
233
  if aggregate_field_value.is_a?(Array)
225
234
  @aggregation_names.each do |operation|
226
235
 
227
- #If bucket, calculate bucket for metric
228
- if operation == 'bucket'
236
+ #If histogram, calculate bucket for metric
237
+ if operation == 'histogram'
238
+ if @histogram_bucket_comparation == :less_or_equal
239
+ bucket_comparation = "le"
240
+ else
241
+ bucket_comparation = "ge"
242
+ end
229
243
  #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)
244
+ if !@histogram_buckets.nil? && !@histogram_fields.nil? && @histogram_fields.include?(aggregate_field_key)
245
+ data_bucket = calculate_histogram_buckets(aggregate_field_value, @histogram_buckets)
232
246
 
233
247
  data_bucket.each {|bucket,bucket_count|
234
248
  #@log.info("#{aggregate_field_key}_#{bucket} = #{bucket_count}")
235
- aggregator_data["#{aggregate_field_key}_bucket#{bucket}"] = bucket_count
249
+ aggregator_data["#{aggregate_field_key}_bucket_#{bucket_comparation}_#{bucket}"] = bucket_count
236
250
  }
237
251
 
238
252
  # Add aggregated data to interval
@@ -242,8 +256,8 @@ module DataOperations
242
256
  interval_aggregator_item_value = group_item_value['intervals'][interval_secs][interval_aggregator_item_key]
243
257
  data_bucket.each {|bucket,bucket_count|
244
258
  #@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
259
+ interval_aggregator_item_value['aggregate_fields'][aggregate_field_key]["bucket_#{bucket_comparation}_#{bucket}"] = [] if interval_aggregator_item_value['aggregate_fields'][aggregate_field_key]["bucket#{bucket}"].nil?
260
+ interval_aggregator_item_value['aggregate_fields'][aggregate_field_key]["bucket_#{bucket_comparation}_#{bucket}"] << bucket_count
247
261
  }
248
262
 
249
263
  end
@@ -264,10 +278,6 @@ module DataOperations
264
278
 
265
279
  end
266
280
 
267
- if !@buckets.nil? && ! @bucket_metrics.nil?
268
- #data = calculate_buckets(data, @buckets)
269
- end
270
-
271
281
  end
272
282
  end
273
283
 
@@ -284,8 +294,6 @@ module DataOperations
284
294
  interval_aggregator_item_value['aggregate_fields'][aggregate_field_key][operation] = []
285
295
  end
286
296
 
287
- ##Add buckets metadata (empty hash)
288
- ##interval_aggregator_item_value['aggregate_fields'][aggregate_field_key]['buckets']={}
289
297
  end
290
298
  end
291
299
 
@@ -339,10 +347,10 @@ module DataOperations
339
347
  case operation
340
348
  when 'max', 'min', 'mean', 'median'
341
349
  data = vector.method(operation).call
342
- when 'bucket'
350
+ when 'histogram'
343
351
  #Bucket operation generate bucket[\d]+
344
352
  data = nil
345
- when /^bucket[\d]+/
353
+ when /^bucket.+/
346
354
  #For buckets sum accumulations for internvals
347
355
  data = vector.method('sum').call
348
356
  else
@@ -361,20 +369,49 @@ module DataOperations
361
369
  end
362
370
 
363
371
  #Return Array with count by each bucket
364
- def calculate_buckets(data, buckets_config)
365
- buckets_config.sort!.uniq!
372
+ def calculate_histogram_buckets(data, buckets_config)
373
+
374
+ if @histogram_bucket_comparation == :less_or_equal
375
+ buckets_config.sort!.uniq!
376
+ else
377
+ buckets_config.reverse!.uniq!
378
+ end
379
+
366
380
  buckets = {}
367
381
 
368
382
  buckets_config.each {|bucket| buckets[bucket] = 0}
369
383
 
370
- data.each {|item|
371
- buckets_config.each {|bucket|
372
- if item <= bucket
384
+ #By default add Inf bucket
385
+ buckets["Inf"] = 0 if @histogram_bucket_infinite_enabled
386
+
387
+ data.each do|item|
388
+ item_in_bucket = false
389
+ buckets_config.each do|bucket|
390
+ item_in_bucket = false
391
+ if @histogram_bucket_comparation == :less_or_equal
392
+ if item <= bucket
393
+ item_in_bucket = true
394
+ end
395
+ elsif item >= bucket
396
+ item_in_bucket = true
397
+ end
398
+
399
+ if item_in_bucket
373
400
  buckets[bucket] += 1
374
- next
401
+ #Not accumule if histogram cumulative is false
402
+ break if !@histogram_cumulative
375
403
  end
376
- }
377
- }
404
+ end
405
+
406
+ #Only count Inf bucket if enabled
407
+ if @histogram_bucket_infinite_enabled
408
+ if !item_in_bucket
409
+ buckets["Inf"] += 1
410
+ elsif @histogram_cumulative
411
+ buckets["Inf"] += 1
412
+ end
413
+ end
414
+ end
378
415
  return buckets
379
416
  end
380
417
 
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.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Guillen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-03 00:00:00.000000000 Z
11
+ date: 2023-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: descriptive_statistics