artirix_data_models 0.6.7 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/artirix_data_models.rb +1 -0
- data/lib/artirix_data_models/aggregation.rb +92 -7
- data/lib/artirix_data_models/aggregation_builder.rb +21 -8
- data/lib/artirix_data_models/inspectable.rb +16 -0
- data/lib/artirix_data_models/model.rb +1 -13
- data/lib/artirix_data_models/raw_aggregation_data_normaliser.rb +24 -2
- data/lib/artirix_data_models/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f15642b0096a000e01eb83c1ce3016f0af83b001
|
4
|
+
data.tar.gz: afdfc74dd09d32112a198cf4a5f9c89b2437b84c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6484979971c7378ad68acf26d6a9ca4be25869643a111a049b66efd85fce6a2fb80222fb0d039ea8389cd20592dd258f8d95de00e5988aa309cff2540c235ddf
|
7
|
+
data.tar.gz: d15b73a1ac5588b68178842a2c456055ba4bfe674b516425dabf4baab8ed5ccdef82b89e14e8669b5c1f81ee9abb228b132be92e3767953194957ab7571aa11b
|
data/README.md
CHANGED
@@ -250,6 +250,18 @@ end
|
|
250
250
|
|
251
251
|
## Changes
|
252
252
|
|
253
|
+
### 0.7.1
|
254
|
+
|
255
|
+
- added `MetricAggregation`. Normal `AggregationBuilder` will build an aggregation with that class if instead of `buckets` it finds `value` in the JSON.
|
256
|
+
- normalize raw aggregations now does not ignore metric aggregations (see above)
|
257
|
+
- added `calculate_filtered(filtered_values)` to aggregations (noop in Metric aggregations). In a bucket aggregation, will mark with `filtered?` each bucket (aka Aggregation Value) if the `bucket.name` is present in the given `filtered_values`.
|
258
|
+
- added to `Aggregation` the methods:
|
259
|
+
-- `filtered_buckets` that will return only buckets marked as `filtered?`
|
260
|
+
-- `unfiltered_buckets` that will return only buckets not marked as `filtered?`
|
261
|
+
-- `filtered_first_buckets` that will concatenate `filtered_buckets` and `unfiltered_buckets`
|
262
|
+
- changed classes to stop inheriting from `Struct`, had some problems with inheritance.
|
263
|
+
- `Aggregation`, `Aggregation::Value` and `MetricAggregation` now using the same inspection as models.
|
264
|
+
|
253
265
|
### 0.6.7
|
254
266
|
|
255
267
|
- aggregations use `key_as_string` as name of the bucket value if it exists, if not then it uses `key` and if that also does not exist then it uses `name`
|
@@ -288,6 +300,10 @@ end
|
|
288
300
|
|
289
301
|
## Yanked versions
|
290
302
|
|
303
|
+
### ~0.7.0~
|
304
|
+
|
305
|
+
Yanked because of bug on Aggregations. Released 0.7.1 with the fix. Changeset moved too to 0.7.1
|
306
|
+
|
291
307
|
### ~0.6.3~
|
292
308
|
|
293
309
|
Yanked because of typo bug on SortedBucketAggregationBase. Released 0.6.3.1 with the fix.
|
data/lib/artirix_data_models.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
module ArtirixDataModels
|
2
|
-
class
|
2
|
+
class CommonAggregation
|
3
|
+
include Inspectable
|
4
|
+
attr_accessor :name
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
end
|
7
9
|
|
8
|
-
def self.from_json(definition, value_class = Value)
|
10
|
+
def self.from_json(definition, value_class = Aggregation::Value)
|
9
11
|
DAORegistry.aggregations_factory.aggregation_from_json(definition, value_class: value_class, aggregation_class: self)
|
10
12
|
end
|
11
13
|
|
12
14
|
def pretty_name
|
15
|
+
@pretty_name ||= load_pretty_name
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def load_pretty_name
|
13
20
|
I18n.t("aggregations.#{name.to_s.gsub('.', '_')}.name", default: default_pretty_name)
|
14
21
|
end
|
15
22
|
|
@@ -17,6 +24,20 @@ module ArtirixDataModels
|
|
17
24
|
name
|
18
25
|
end
|
19
26
|
|
27
|
+
end
|
28
|
+
|
29
|
+
class Aggregation < CommonAggregation
|
30
|
+
include Enumerable
|
31
|
+
|
32
|
+
attr_accessor :buckets
|
33
|
+
|
34
|
+
def initialize(name, buckets)
|
35
|
+
super name
|
36
|
+
@buckets = buckets
|
37
|
+
end
|
38
|
+
|
39
|
+
delegate :each, :empty?, to: :buckets
|
40
|
+
|
20
41
|
def non_empty_buckets
|
21
42
|
buckets.reject { |x| x.empty? }
|
22
43
|
end
|
@@ -28,10 +49,40 @@ module ArtirixDataModels
|
|
28
49
|
}
|
29
50
|
end
|
30
51
|
|
31
|
-
|
52
|
+
def calculate_filtered(filtered_values = [])
|
53
|
+
buckets.each do |b|
|
54
|
+
b.filtered = filtered_values.include?(b.name)
|
55
|
+
end
|
56
|
+
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
def filtered_buckets
|
61
|
+
buckets.select &:filtered?
|
62
|
+
end
|
63
|
+
|
64
|
+
def unfiltered_buckets
|
65
|
+
buckets.reject &:filtered?
|
66
|
+
end
|
67
|
+
|
68
|
+
def filtered_first_buckets
|
69
|
+
filtered_buckets + unfiltered_buckets
|
70
|
+
end
|
71
|
+
|
72
|
+
class Value
|
73
|
+
|
74
|
+
attr_accessor :filtered, :aggregation_name, :name, :count
|
75
|
+
attr_writer :aggregations
|
76
|
+
|
77
|
+
def initialize(aggregation_name, name, count, aggregations)
|
78
|
+
@aggregation_name = aggregation_name
|
79
|
+
@name = name
|
80
|
+
@count = count
|
81
|
+
@aggregations = aggregations
|
82
|
+
end
|
32
83
|
|
33
84
|
def aggregations
|
34
|
-
Array(
|
85
|
+
Array(@aggregations)
|
35
86
|
end
|
36
87
|
|
37
88
|
alias_method :nested_aggregations, :aggregations
|
@@ -69,6 +120,18 @@ module ArtirixDataModels
|
|
69
120
|
}
|
70
121
|
end
|
71
122
|
|
123
|
+
def mark_filtered
|
124
|
+
@filtered = true
|
125
|
+
end
|
126
|
+
|
127
|
+
def mark_unfiltered
|
128
|
+
@filtered = false
|
129
|
+
end
|
130
|
+
|
131
|
+
def filtered?
|
132
|
+
!!@filtered
|
133
|
+
end
|
134
|
+
|
72
135
|
private
|
73
136
|
def load_pretty_name
|
74
137
|
tranlsation_key = "aggregations.#{aggregation_name.to_s.gsub('.', '_')}.buckets.#{name.to_s.gsub('.', '_')}"
|
@@ -76,4 +139,26 @@ module ArtirixDataModels
|
|
76
139
|
end
|
77
140
|
end
|
78
141
|
end
|
142
|
+
|
143
|
+
class MetricAggregation < CommonAggregation
|
144
|
+
attr_accessor :value
|
145
|
+
|
146
|
+
def initialize(name, value)
|
147
|
+
super name
|
148
|
+
@value = value
|
149
|
+
end
|
150
|
+
|
151
|
+
def data_hash
|
152
|
+
{
|
153
|
+
name: name,
|
154
|
+
value: value
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|
158
|
+
def calculate_filtered(_filtered_values = [])
|
159
|
+
# NOOP
|
160
|
+
self
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
79
164
|
end
|
@@ -1,22 +1,35 @@
|
|
1
1
|
module ArtirixDataModels
|
2
2
|
|
3
3
|
class AggregationBuilder
|
4
|
-
attr_reader :aggregations_factory, :definition, :value_class, :aggregation_class
|
5
|
-
|
6
|
-
def initialize(aggregations_factory:, definition:, aggregation_class: Aggregation, value_class: Aggregation::Value)
|
7
|
-
@aggregations_factory
|
8
|
-
@definition
|
9
|
-
@aggregation_class
|
10
|
-
@
|
4
|
+
attr_reader :aggregations_factory, :definition, :value_class, :aggregation_class, :metric_aggregation_class
|
5
|
+
|
6
|
+
def initialize(aggregations_factory:, definition:, aggregation_class: Aggregation, metric_aggregation_class: MetricAggregation, value_class: Aggregation::Value)
|
7
|
+
@aggregations_factory = aggregations_factory
|
8
|
+
@definition = definition
|
9
|
+
@aggregation_class = aggregation_class
|
10
|
+
@metric_aggregation_class = metric_aggregation_class || aggregation_class
|
11
|
+
@value_class = value_class
|
11
12
|
end
|
12
13
|
|
13
14
|
def build
|
14
|
-
|
15
|
+
if is_metric?
|
16
|
+
metric_aggregation_class.new agg_name, value
|
17
|
+
else
|
18
|
+
aggregation_class.new agg_name, buckets
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
alias_method :call, :build
|
18
23
|
|
19
24
|
private
|
25
|
+
def is_metric?
|
26
|
+
definition.key?(:value) && !definition.key?(:buckets)
|
27
|
+
end
|
28
|
+
|
29
|
+
def value
|
30
|
+
definition[:value]
|
31
|
+
end
|
32
|
+
|
20
33
|
def buckets
|
21
34
|
definition[:buckets].map do |bucket|
|
22
35
|
build_bucket(bucket)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ArtirixDataModels
|
2
|
+
module Inspectable
|
3
|
+
def inspect
|
4
|
+
inspect_with_tab 1
|
5
|
+
end
|
6
|
+
|
7
|
+
def inspect_with_tab(tab_level = 0)
|
8
|
+
insp = data_hash.map do |at, val|
|
9
|
+
v = val.try(:inspect_with_tab, tab_level + 1) || val.inspect
|
10
|
+
tab = ' ' * tab_level * 4
|
11
|
+
"#{tab} - #{at}: #{v}"
|
12
|
+
end
|
13
|
+
"#<#{self.class} \n#{insp.join("\n")}>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -107,6 +107,7 @@ module ArtirixDataModels
|
|
107
107
|
|
108
108
|
included do
|
109
109
|
include KeywordInit
|
110
|
+
include Inspectable
|
110
111
|
end
|
111
112
|
|
112
113
|
def self.direct_getter_method_name(attribute)
|
@@ -121,19 +122,6 @@ module ArtirixDataModels
|
|
121
122
|
data_hash.reject { |_, v| v.nil? }
|
122
123
|
end
|
123
124
|
|
124
|
-
def inspect_with_tab(tab_level = 0)
|
125
|
-
insp = data_hash.map do |at, val|
|
126
|
-
v = val.try(:inspect_with_tab, tab_level + 1) || val.inspect
|
127
|
-
tab = ' ' * tab_level * 4
|
128
|
-
"#{tab} - #{at}: #{v}"
|
129
|
-
end
|
130
|
-
"#<#{self.class} \n#{insp.join("\n")}>"
|
131
|
-
end
|
132
|
-
|
133
|
-
def inspect
|
134
|
-
inspect_with_tab 1
|
135
|
-
end
|
136
|
-
|
137
125
|
module ClassMethods
|
138
126
|
def attribute(*attributes)
|
139
127
|
attributes.each { |attribute| _define_attribute attribute }
|
@@ -2,6 +2,7 @@ module ArtirixDataModels
|
|
2
2
|
class RawAggregationDataNormaliser
|
3
3
|
|
4
4
|
FIND_BUCKETS = ->(_k, v, _o) { v.respond_to?(:key?) && v.key?(:buckets) }
|
5
|
+
FIND_VALUE = ->(_k, v, _o) { v.respond_to?(:key?) && v.key?(:value) }
|
5
6
|
|
6
7
|
attr_reader :raw_aggs, :aggregations_factory, :list
|
7
8
|
|
@@ -25,6 +26,11 @@ module ArtirixDataModels
|
|
25
26
|
private
|
26
27
|
|
27
28
|
def normalise_hash(hash)
|
29
|
+
treat_buckets(hash)
|
30
|
+
treat_values(hash)
|
31
|
+
end
|
32
|
+
|
33
|
+
def treat_buckets(hash)
|
28
34
|
with_buckets_list = deep_locate hash, FIND_BUCKETS
|
29
35
|
|
30
36
|
with_buckets_list.each do |with_buckets|
|
@@ -34,17 +40,29 @@ module ArtirixDataModels
|
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
43
|
+
def treat_values(hash)
|
44
|
+
with_values_list = deep_locate hash, FIND_VALUE
|
45
|
+
|
46
|
+
with_values_list.each do |with_values|
|
47
|
+
with_values.each do |name, value|
|
48
|
+
normalise_element(name, value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
37
53
|
def normalise_element(name, value)
|
38
54
|
return unless Hash === value
|
39
55
|
|
40
56
|
if value.key?(:buckets)
|
41
|
-
|
57
|
+
add_normalised_buckets_element_to_list(name, value)
|
58
|
+
elsif value.key?(:value)
|
59
|
+
add_normalised_value_element_to_list(name, value)
|
42
60
|
else
|
43
61
|
normalise_hash(value)
|
44
62
|
end
|
45
63
|
end
|
46
64
|
|
47
|
-
def
|
65
|
+
def add_normalised_buckets_element_to_list(name, value)
|
48
66
|
buckets = value[:buckets].map do |raw_bucket|
|
49
67
|
normalise_bucket(raw_bucket)
|
50
68
|
end
|
@@ -52,6 +70,10 @@ module ArtirixDataModels
|
|
52
70
|
list << { name: name, buckets: buckets }
|
53
71
|
end
|
54
72
|
|
73
|
+
def add_normalised_value_element_to_list(name, value)
|
74
|
+
list << { name: name, value: value[:value] }
|
75
|
+
end
|
76
|
+
|
55
77
|
def normalise_bucket(raw_bucket)
|
56
78
|
basic_bucket(raw_bucket).tap do |bucket|
|
57
79
|
nested_aggs = nested_aggs_from(raw_bucket)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artirix_data_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Turiño
|
@@ -256,6 +256,7 @@ files:
|
|
256
256
|
- lib/artirix_data_models/fake_response_factory.rb
|
257
257
|
- lib/artirix_data_models/gateway_response_adaptors/model_adaptor.rb
|
258
258
|
- lib/artirix_data_models/gateways/data_gateway.rb
|
259
|
+
- lib/artirix_data_models/inspectable.rb
|
259
260
|
- lib/artirix_data_models/model.rb
|
260
261
|
- lib/artirix_data_models/raw_aggregation_data_normaliser.rb
|
261
262
|
- lib/artirix_data_models/spec_support.rb
|