forest_liana 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/services/forest_liana/line_stat_getter.rb +8 -5
- data/app/services/forest_liana/operator_date_interval_parser.rb +9 -9
- data/app/services/forest_liana/pie_stat_getter.rb +19 -15
- data/app/services/forest_liana/stat_getter.rb +18 -0
- data/app/services/forest_liana/value_stat_getter.rb +3 -8
- data/lib/forest_liana/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9847fca87fc1e7caff49a8aaf899a23c33169314
|
4
|
+
data.tar.gz: bf383e4e3b8fcc4be34a368018bdd8ab43e1bb0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 812421ddef29e95a562c928d610b3dfb148a7b9526ce69e88586d89c6b10a3569f9d32ea8cc8243ae1d4e67056ee406c770ed8b5a6fbf00e06a6dbd0ba01a1ea
|
7
|
+
data.tar.gz: bec80b2cb5b6524af1b6c2ddcbdd7a132910c85b25f9a6f06ca0455165c106c46b9cecc9c7c4dba37f4945dabc805bf8208109f89d7c3c96e38e360b3456865d
|
@@ -1,15 +1,14 @@
|
|
1
1
|
module ForestLiana
|
2
|
-
class LineStatGetter
|
2
|
+
class LineStatGetter < StatGetter
|
3
3
|
attr_accessor :record
|
4
4
|
|
5
5
|
def initialize(resource, params)
|
6
|
-
|
7
|
-
@params = params
|
6
|
+
super(resource, params)
|
8
7
|
@populates = {}
|
9
8
|
end
|
10
9
|
|
11
10
|
def perform
|
12
|
-
value = @resource.unscoped
|
11
|
+
value = @resource.unscoped.eager_load(includes)
|
13
12
|
|
14
13
|
if @params[:filterType] && @params[:filters]
|
15
14
|
conditions = []
|
@@ -24,7 +23,7 @@ module ForestLiana
|
|
24
23
|
value = value.where(conditions.join(filter_operator))
|
25
24
|
end
|
26
25
|
|
27
|
-
value = value.send(time_range,
|
26
|
+
value = value.send(time_range, group_by_date_field)
|
28
27
|
value = value.group(group_by_field || :id) if group_by_field
|
29
28
|
|
30
29
|
value = value.send(@params[:aggregate].downcase, @params[:aggregate_field])
|
@@ -52,6 +51,10 @@ module ForestLiana
|
|
52
51
|
|
53
52
|
private
|
54
53
|
|
54
|
+
def group_by_date_field
|
55
|
+
"#{@resource.table_name}.#{@params[:group_by_date_field]}"
|
56
|
+
end
|
57
|
+
|
55
58
|
def group_by_field
|
56
59
|
field_name = @params[:group_by_field]
|
57
60
|
association = @resource.reflect_on_association(field_name) if field_name
|
@@ -7,17 +7,17 @@ module ForestLiana
|
|
7
7
|
lastMonth: { duration: 1, period: 'month' }, # TODO: Remove once new filter protocol is live
|
8
8
|
last3Months: { duration: 3, period: 'month' }, # TODO: Remove once new filter protocol is live
|
9
9
|
lastYear: { duration: 1, period: 'year' }, # TODO: Remove once new filter protocol is live
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
:$yesterday => { duration: 1, period: 'day' },
|
11
|
+
:$previousWeek => { duration: 1, period: 'week' },
|
12
|
+
:$previousMonth => { duration: 1, period: 'month' },
|
13
|
+
:$previousQuarter => { duration: 3, period: 'month',
|
14
14
|
period_of_time: 'quarter' },
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
:$previousYear => { duration: 1, period: 'year' },
|
16
|
+
:$weekToDate => { duration: 1, period: 'week', to_date: true },
|
17
|
+
:$monthToDate => { duration: 1, period: 'month', to_date: true },
|
18
|
+
:$quarterToDate => { duration: 3, period: 'month',
|
19
19
|
period_of_time: 'quarter', to_date: true },
|
20
|
-
|
20
|
+
:$yearToDate => { duration: 1, period: 'year', to_date: true }
|
21
21
|
}
|
22
22
|
|
23
23
|
PERIODS_FROM_NOW = 'fromNow' # TODO: Remove once new filter protocol is live
|
@@ -1,12 +1,7 @@
|
|
1
1
|
module ForestLiana
|
2
|
-
class PieStatGetter
|
2
|
+
class PieStatGetter < StatGetter
|
3
3
|
attr_accessor :record
|
4
4
|
|
5
|
-
def initialize(resource, params)
|
6
|
-
@resource = resource
|
7
|
-
@params = params
|
8
|
-
end
|
9
|
-
|
10
5
|
def perform
|
11
6
|
if @params[:group_by_field]
|
12
7
|
value = @resource
|
@@ -23,18 +18,12 @@ module ForestLiana
|
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
26
|
-
# NOTICE: The generated alias for a count is "count_all", for a sum the
|
27
|
-
# alias looks like "sum_#{aggregate_field}"
|
28
|
-
field = 'all'
|
29
|
-
if @params[:aggregate].downcase == 'sum'
|
30
|
-
field = @params[:aggregate_field].downcase
|
31
|
-
end
|
32
|
-
|
33
21
|
value = value
|
34
22
|
.unscoped
|
23
|
+
.eager_load(includes)
|
35
24
|
.where(conditions.join(filter_operator))
|
36
|
-
.group(@params[:group_by_field])
|
37
|
-
.order(
|
25
|
+
.group("#{@resource.table_name}.#{@params[:group_by_field]}")
|
26
|
+
.order(order)
|
38
27
|
.send(@params[:aggregate].downcase, @params[:aggregate_field])
|
39
28
|
.map do |k, v|
|
40
29
|
# NOTICE: Display the enum name instead of a integer if "enum" type
|
@@ -50,5 +39,20 @@ module ForestLiana
|
|
50
39
|
end
|
51
40
|
end
|
52
41
|
|
42
|
+
def order
|
43
|
+
# NOTICE: The generated alias for a count is "count_all", for a sum the
|
44
|
+
# alias looks like "sum_#{aggregate_field}"
|
45
|
+
field = 'all'
|
46
|
+
if @params[:aggregate].downcase == 'sum'
|
47
|
+
field = @params[:aggregate_field].downcase
|
48
|
+
end
|
49
|
+
|
50
|
+
if includes.size == 0
|
51
|
+
"#{@params[:aggregate].downcase}_#{field} DESC"
|
52
|
+
else
|
53
|
+
"#{@params[:aggregate].downcase}_id DESC"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
53
57
|
end
|
54
58
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ForestLiana
|
2
|
+
class StatGetter
|
3
|
+
attr_accessor :record
|
4
|
+
|
5
|
+
def initialize(resource, params)
|
6
|
+
@resource = resource
|
7
|
+
@params = params
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def includes
|
13
|
+
SchemaUtils.one_associations(@resource)
|
14
|
+
.select { |association| SchemaUtils.model_included?(association.klass) }
|
15
|
+
.map(&:name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,16 +1,11 @@
|
|
1
1
|
module ForestLiana
|
2
|
-
class ValueStatGetter
|
2
|
+
class ValueStatGetter < StatGetter
|
3
3
|
attr_accessor :record
|
4
4
|
|
5
|
-
def initialize(resource, params)
|
6
|
-
@resource = resource
|
7
|
-
@params = params
|
8
|
-
end
|
9
|
-
|
10
5
|
def perform
|
11
6
|
return if @params[:aggregate].blank?
|
12
|
-
valueCurrent = @resource.unscoped
|
13
|
-
valuePrevious = @resource.unscoped
|
7
|
+
valueCurrent = @resource.unscoped.eager_load(includes)
|
8
|
+
valuePrevious = @resource.unscoped.eager_load(includes)
|
14
9
|
filter_date_interval = false
|
15
10
|
|
16
11
|
if @params[:filterType] && @params[:filters]
|
data/lib/forest_liana/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_liana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- app/services/forest_liana/schema_adapter.rb
|
180
180
|
- app/services/forest_liana/schema_utils.rb
|
181
181
|
- app/services/forest_liana/search_query_builder.rb
|
182
|
+
- app/services/forest_liana/stat_getter.rb
|
182
183
|
- app/services/forest_liana/stripe_bank_accounts_getter.rb
|
183
184
|
- app/services/forest_liana/stripe_cards_getter.rb
|
184
185
|
- app/services/forest_liana/stripe_invoices_getter.rb
|