active_reporting 0.6.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/tests.yml +150 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +7 -5
- data/README.md +7 -6
- data/lib/active_reporting/metric.rb +5 -2
- data/lib/active_reporting/report.rb +5 -1
- data/lib/active_reporting/reporting_dimension.rb +9 -2
- data/lib/active_reporting/version.rb +1 -1
- metadata +5 -5
- data/.codeclimate.yml +0 -15
- data/.travis.yml +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc7dff49fb9bffe3ea663751a710d20343a8dd6a218a088433e772884ab3412b
|
4
|
+
data.tar.gz: 9c03f8ed6f0247d911da6290b120c8b74643cc780761585cd8b0b85ef4a55ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c48dae4c7a6a5389241ef0ee3d01038073d2c75582b8b60aaa93be0e41a3e70abc84f87d609071bca9e86b72968a842f65af199d1a7f7f84e8c449ab720cf9e
|
7
|
+
data.tar.gz: 003b8752db40a55ac09dde37d6f32d21bc14d921c88011393339b4f59554dedfe10557d49545f929d5ea1c7f5a64911fd1fda9fc5bf0d67823e9b68eae9396c1
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
3
|
+
# Please see the documentation for all configuration options:
|
4
|
+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
5
|
+
|
6
|
+
version: 2
|
7
|
+
updates:
|
8
|
+
- package-ecosystem: "github-actions"
|
9
|
+
directory: "/"
|
10
|
+
schedule:
|
11
|
+
interval: "weekly"
|
@@ -0,0 +1,150 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- main
|
10
|
+
|
11
|
+
env:
|
12
|
+
POSTGRES_USER: postgres
|
13
|
+
POSTGRES_PASSWORD: postgres
|
14
|
+
PGPASSWORD: postgres
|
15
|
+
POSTGRES_HOST: localhost
|
16
|
+
MYSQL_HOST: '127.0.0.1'
|
17
|
+
MYSQL_USER: 'root'
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
tests:
|
21
|
+
services:
|
22
|
+
pg:
|
23
|
+
image: postgres:12
|
24
|
+
env:
|
25
|
+
POSTGRES_USER: postgres
|
26
|
+
POSTGRES_PASSWORD: postgres
|
27
|
+
ports: ['5432:5432']
|
28
|
+
mysql:
|
29
|
+
image: mysql:5.7
|
30
|
+
env:
|
31
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
32
|
+
MYSQL_DATABASE: active_reporting_test
|
33
|
+
ports:
|
34
|
+
- 3306
|
35
|
+
|
36
|
+
runs-on: ubuntu-latest
|
37
|
+
strategy:
|
38
|
+
fail-fast: false
|
39
|
+
matrix:
|
40
|
+
include:
|
41
|
+
- ruby: '3.0'
|
42
|
+
gemfile: '6.1'
|
43
|
+
db: 'mysql'
|
44
|
+
|
45
|
+
- ruby: '3.0'
|
46
|
+
gemfile: '6.1'
|
47
|
+
db: 'pg'
|
48
|
+
|
49
|
+
- ruby: '3.0'
|
50
|
+
gemfile: '6.1'
|
51
|
+
db: 'sqlite'
|
52
|
+
|
53
|
+
- ruby: '3.0'
|
54
|
+
gemfile: '7.0'
|
55
|
+
db: 'mysql'
|
56
|
+
|
57
|
+
- ruby: '3.0'
|
58
|
+
gemfile: '7.0'
|
59
|
+
db: 'pg'
|
60
|
+
|
61
|
+
- ruby: '3.0'
|
62
|
+
gemfile: '7.0'
|
63
|
+
db: 'sqlite'
|
64
|
+
|
65
|
+
- ruby: '3.1'
|
66
|
+
gemfile: '7.0'
|
67
|
+
db: 'mysql'
|
68
|
+
|
69
|
+
- ruby: '3.1'
|
70
|
+
gemfile: '7.0'
|
71
|
+
db: 'pg'
|
72
|
+
|
73
|
+
- ruby: '3.1'
|
74
|
+
gemfile: '7.0'
|
75
|
+
db: 'sqlite'
|
76
|
+
|
77
|
+
- ruby: '3.2'
|
78
|
+
gemfile: '7.0'
|
79
|
+
db: 'mysql'
|
80
|
+
|
81
|
+
- ruby: '3.2'
|
82
|
+
gemfile: '7.0'
|
83
|
+
db: 'pg'
|
84
|
+
|
85
|
+
- ruby: '3.2'
|
86
|
+
gemfile: '7.0'
|
87
|
+
db: 'sqlite'
|
88
|
+
|
89
|
+
- ruby: '3.3'
|
90
|
+
gemfile: '7.0'
|
91
|
+
db: 'mysql'
|
92
|
+
|
93
|
+
- ruby: '3.3'
|
94
|
+
gemfile: '7.0'
|
95
|
+
db: 'pg'
|
96
|
+
|
97
|
+
- ruby: '3.3'
|
98
|
+
gemfile: '7.0'
|
99
|
+
db: 'sqlite'
|
100
|
+
|
101
|
+
- ruby: '3.2'
|
102
|
+
gemfile: '7.1'
|
103
|
+
db: 'mysql'
|
104
|
+
|
105
|
+
- ruby: '3.2'
|
106
|
+
gemfile: '7.1'
|
107
|
+
db: 'pg'
|
108
|
+
|
109
|
+
- ruby: '3.2'
|
110
|
+
gemfile: '7.1'
|
111
|
+
db: 'sqlite'
|
112
|
+
|
113
|
+
- ruby: '3.3'
|
114
|
+
gemfile: '7.1'
|
115
|
+
db: 'mysql'
|
116
|
+
|
117
|
+
- ruby: '3.3'
|
118
|
+
gemfile: '7.1'
|
119
|
+
db: 'pg'
|
120
|
+
|
121
|
+
- ruby: '3.3'
|
122
|
+
gemfile: '7.1'
|
123
|
+
db: 'sqlite'
|
124
|
+
name: rails ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}, ${{ matrix.db }}
|
125
|
+
|
126
|
+
steps:
|
127
|
+
- uses: actions/checkout@v4
|
128
|
+
|
129
|
+
- name: Set up Ruby
|
130
|
+
uses: ruby/setup-ruby@v1
|
131
|
+
with:
|
132
|
+
ruby-version: ${{ matrix.ruby }}
|
133
|
+
bundler-cache: false
|
134
|
+
|
135
|
+
- name: Bundle install
|
136
|
+
env:
|
137
|
+
DB: ${{ matrix.db }}
|
138
|
+
RAILS: ${{ matrix.gemfile }}
|
139
|
+
run: |
|
140
|
+
bundle install --jobs 4 --retry 3
|
141
|
+
- name: Create PG DB
|
142
|
+
run: |
|
143
|
+
psql -c 'create database active_reporting_test;' -U postgres -h localhost
|
144
|
+
- name: Run tests
|
145
|
+
env:
|
146
|
+
MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}
|
147
|
+
DB: ${{ matrix.db }}
|
148
|
+
RAILS: ${{ matrix.gemfile }}
|
149
|
+
run: |
|
150
|
+
bundle exec rake test
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 0.6.2 (2024-03-18)
|
2
|
+
|
3
|
+
### Features
|
4
|
+
|
5
|
+
* `Metric` can now take an optional `measure` argument to override the measure that would normally be used.
|
6
|
+
|
7
|
+
## 0.6.1 (2020-08-29)
|
8
|
+
|
9
|
+
### Misc
|
10
|
+
|
11
|
+
* Add `date` as an option for datetime drills - *germanotm*
|
12
|
+
|
1
13
|
## 0.6.0 (2020-08-21)
|
2
14
|
|
3
15
|
### Features
|
data/Gemfile
CHANGED
@@ -4,12 +4,14 @@ gemspec
|
|
4
4
|
|
5
5
|
gem 'simplecov', require: false
|
6
6
|
|
7
|
-
rails = ENV['RAILS'] || '
|
7
|
+
rails = ENV['RAILS'] || '6.1'
|
8
8
|
db = ENV['DB'] || 'sqlite'
|
9
9
|
|
10
10
|
case rails
|
11
|
-
when '
|
12
|
-
gem 'activerecord', '~>
|
13
|
-
when '
|
14
|
-
gem 'activerecord', '~>
|
11
|
+
when '6.1'
|
12
|
+
gem 'activerecord', '~> 6.1.0'
|
13
|
+
when '7.0'
|
14
|
+
gem 'activerecord', '~> 7.0.0'
|
15
|
+
when '7.1'
|
16
|
+
gem 'activerecord', '~> 7.1.0'
|
15
17
|
end
|
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
[![Code Climate](https://codeclimate.com/github/t27duck/active_reporting/badges/gpa.svg)](https://codeclimate.com/github/t27duck/active_reporting)
|
1
|
+
![Build Status](https://github.com/t27duck/active_reporting/workflows/CI/badge.svg)
|
4
2
|
|
5
3
|
# ActiveReporting
|
6
4
|
|
@@ -8,9 +6,9 @@ ActiveReporting implements various terminology used in Relational Online Analyti
|
|
8
6
|
|
9
7
|
ActiveReporting officially supports MySQL, PostgreSQL, and SQLite.
|
10
8
|
|
11
|
-
ActiveReporting officially supports Ruby
|
9
|
+
ActiveReporting officially supports Ruby 3.0 and later. Other versions may work, but are not supported.
|
12
10
|
|
13
|
-
ActiveReporting officially supports Rails
|
11
|
+
ActiveReporting officially supports Rails 6.1 - 7.1. Other versions may work, but are not supported.
|
14
12
|
|
15
13
|
## Installation
|
16
14
|
|
@@ -250,6 +248,7 @@ When creating a metric, ActiveReporting will recognize the following datetime hi
|
|
250
248
|
- decade
|
251
249
|
- century
|
252
250
|
- millennium
|
251
|
+
- date
|
253
252
|
|
254
253
|
Under the hood Active Reporting uses specific database functions to manipulate datetime columns. Postgres provides a way to group by `datetime` column data on the fly using the [`date_trunc` function](https://www.postgresql.org/docs/8.1/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC). On Mysql this can be done using [Date and Time Functions](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html).
|
255
254
|
|
@@ -307,7 +306,7 @@ my_metric = ActiveReporting::Metric.new(
|
|
307
306
|
|
308
307
|
You may pass a hash instead of a symbol to customize the dimension options (example: { dimension_name: { option1: value, option2: value}}). The avaliable options are:
|
309
308
|
|
310
|
-
- `field` - Specify the hierarchy level that should be used instead the default dimension label. Ex: `[:sales_rep, {mobile_phone: { field :manufacture }}]`. If you use a hash instead of a Symbol to define a hierarchy the `field` item must be a valid field in your table.
|
309
|
+
- `field` - Specify the hierarchy level that should be used instead the default dimension label. Ex: `[:sales_rep, {mobile_phone: { field: :manufacture }}]`. If you use a hash instead of a Symbol to define a hierarchy the `field` item must be a valid field in your table.
|
311
310
|
|
312
311
|
- `name` - You may costumize the label alias, by default the dimension name will be used. The `name` can be whatever label you want. Ex :`[{sale_date: { field: :month, name: :a_custom_name_for_month }}]`.
|
313
312
|
|
@@ -319,6 +318,8 @@ You may pass a hash instead of a symbol to customize the dimension options (exam
|
|
319
318
|
|
320
319
|
`metric_filter` - An additional HAVING clause to be tacked on to the end of the query. This allows for the further filtering of the end results based on the value of the aggregate. (Examples: `{gt: 3}`, `{eq: 5}`, `{lte: 7}`)
|
321
320
|
|
321
|
+
`measure` - Override the measure on the `ActiveReporting::Factmodel` used.
|
322
|
+
|
322
323
|
`order_by_dimension` - Allows you to set the ordering of the results based on a dimension label. (Examples: `{author: :desc}`, `{sales_ref: :asc}`)
|
323
324
|
|
324
325
|
For those using Postgres, you can take advantage of implicit hierarchies in `datetime` columns, as mentioned above:
|
@@ -7,7 +7,8 @@ module ActiveReporting
|
|
7
7
|
class Metric
|
8
8
|
extend Forwardable
|
9
9
|
def_delegators :@fact_model, :model
|
10
|
-
attr_reader :fact_model, :name, :dimensions, :dimension_filter, :aggregate
|
10
|
+
attr_reader :fact_model, :name, :dimensions, :dimension_filter, :aggregate
|
11
|
+
attr_reader :metric_filter, :order_by_dimension, :measure
|
11
12
|
|
12
13
|
def initialize(
|
13
14
|
name,
|
@@ -16,7 +17,8 @@ module ActiveReporting
|
|
16
17
|
dimensions: [],
|
17
18
|
dimension_filter: {},
|
18
19
|
metric_filter: {},
|
19
|
-
order_by_dimension: {}
|
20
|
+
order_by_dimension: {},
|
21
|
+
measure: nil
|
20
22
|
)
|
21
23
|
@name = name.to_sym
|
22
24
|
@fact_model = fact_model
|
@@ -25,6 +27,7 @@ module ActiveReporting
|
|
25
27
|
@metric_filter = metric_filter
|
26
28
|
@dimensions = ReportingDimension.build_from_dimensions(@fact_model, Array(dimensions))
|
27
29
|
@order_by_dimension = order_by_dimension
|
30
|
+
@measure = measure
|
28
31
|
check_dimension_filter
|
29
32
|
end
|
30
33
|
|
@@ -81,10 +81,14 @@ module ActiveReporting
|
|
81
81
|
when :count
|
82
82
|
'COUNT(*)'
|
83
83
|
else
|
84
|
-
"#{@metric.aggregate.to_s.upcase}(#{
|
84
|
+
"#{@metric.aggregate.to_s.upcase}(#{measure})"
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
def measure
|
89
|
+
@metric.measure || fact_model.measure
|
90
|
+
end
|
91
|
+
|
88
92
|
def dimension_joins(join_method)
|
89
93
|
@dimensions.select { |d| d.type == Dimension::TYPES[:standard] && d.join_method == join_method }.
|
90
94
|
map { |d| d.name.to_sym }
|
@@ -8,7 +8,7 @@ module ActiveReporting
|
|
8
8
|
# Values for the Postgres `date_trunc` method.
|
9
9
|
# See https://www.postgresql.org/docs/10/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
|
10
10
|
DATETIME_HIERARCHIES = %i[microseconds milliseconds second minute hour day week month quarter year decade
|
11
|
-
century millennium].freeze
|
11
|
+
century millennium date].freeze
|
12
12
|
JOIN_METHODS = { joins: :joins, left_outer_joins: :left_outer_joins }.freeze
|
13
13
|
attr_reader :join_method, :label
|
14
14
|
|
@@ -188,7 +188,12 @@ module ActiveReporting
|
|
188
188
|
end
|
189
189
|
|
190
190
|
def datetime_drill_postgress(column)
|
191
|
-
|
191
|
+
case @datetime_drill.to_sym
|
192
|
+
when :date
|
193
|
+
"DATE('#{column}')"
|
194
|
+
else
|
195
|
+
"DATE_TRUNC('#{@datetime_drill}', #{column})"
|
196
|
+
end
|
192
197
|
end
|
193
198
|
|
194
199
|
def datetime_drill_mysql(column)
|
@@ -219,6 +224,8 @@ module ActiveReporting
|
|
219
224
|
"YEAR(#{column}) DIV 100"
|
220
225
|
when :millennium
|
221
226
|
"YEAR(#{column}) DIV 1000"
|
227
|
+
when :date
|
228
|
+
"DATE(#{column})"
|
222
229
|
end
|
223
230
|
end
|
224
231
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_reporting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Drake
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -143,10 +143,10 @@ executables: []
|
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
-
- ".
|
146
|
+
- ".github/dependabot.yml"
|
147
|
+
- ".github/workflows/tests.yml"
|
147
148
|
- ".gitignore"
|
148
149
|
- ".rubocop.yml"
|
149
|
-
- ".travis.yml"
|
150
150
|
- CHANGELOG.md
|
151
151
|
- CODE_OF_CONDUCT.md
|
152
152
|
- Gemfile
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
|
-
rubygems_version: 3.
|
188
|
+
rubygems_version: 3.5.3
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: Add relational OLAP-like functionality for ActiveRecord
|
data/.codeclimate.yml
DELETED
data/.travis.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
services:
|
4
|
-
- mysql
|
5
|
-
addons:
|
6
|
-
postgresql: "9.6"
|
7
|
-
rvm:
|
8
|
-
- 2.5.8
|
9
|
-
- 2.6.6
|
10
|
-
- 2.7.1
|
11
|
-
env:
|
12
|
-
- RAILS=6-0 DB=sqlite
|
13
|
-
- RAILS=6-0 DB=pg
|
14
|
-
- RAILS=6-0 DB=mysql
|
15
|
-
- RAILS=5-2 DB=sqlite
|
16
|
-
- RAILS=5-2 DB=pg
|
17
|
-
- RAILS=5-2 DB=mysql
|
18
|
-
before_script:
|
19
|
-
- psql -c 'create database active_reporting_test;' -U postgres
|
20
|
-
- mysql -e 'create database active_reporting_test collate utf8_general_ci;'
|