simple_drilldown 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +129 -3
- data/config/locales/nb.yml +1 -1
- data/lib/simple_drilldown/drilldown_controller.rb +1 -1
- data/lib/simple_drilldown/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24272122319881a4c28db29d1b986ebd2f49d0ed50d642648fe5e5795c4f04b4
|
4
|
+
data.tar.gz: c5ec174af7dcb4d1ca5dfabfa0abc27b8999177d2f6580be2f65f874825bfcf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6310bab272395d0b003616e99e9467c81f31148a6410e83e124770589ef6e9e81de2b60ca8aa84b31eadfc1fb62bfbe81a7e377187a2d0479d0c6e3c819cdbe1
|
7
|
+
data.tar.gz: ba2943b101e839e0793c51c4d80e94e27952476993c70b6eeaaa1a3a953336da0115890262f2a135ca49669a6298b8bf777bc5d60ba304616ca3c61041c504a4
|
data/README.md
CHANGED
@@ -1,10 +1,131 @@
|
|
1
1
|
# SimpleDrilldown
|
2
|
-
|
2
|
+
|
3
|
+
<a href="https://travis-ci.org/DatekWireless/simple_drilldown">
|
4
|
+
<img align="right" src="https://travis-ci.org/DatekWireless/simple_drilldown.svg?branch=master" alt="Build Status">
|
5
|
+
</a>
|
6
|
+
|
7
|
+
simple_drilldown offers a simple way to define axis to filter and group records
|
8
|
+
for analysis. The result is a record count for the selected filter and
|
9
|
+
distribution and the option to list the actual records.
|
3
10
|
|
4
11
|
## Usage
|
5
|
-
|
12
|
+
|
13
|
+
### Rails
|
14
|
+
|
15
|
+
For a given schema:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
ActiveRecord::Schema.define(version: 20141204155251) do
|
19
|
+
create_table "posts" do |t|
|
20
|
+
t.string "title", null: false
|
21
|
+
t.text "body", null: false
|
22
|
+
t.integer "user_id", null: false
|
23
|
+
t.datetime "published_at"
|
24
|
+
t.datetime "created_at", null: false
|
25
|
+
t.datetime "updated_at", null: false
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table "users" do |t|
|
29
|
+
t.string "name", limit: 16, null: false
|
30
|
+
end
|
31
|
+
|
32
|
+
create_table "comments" do |t|
|
33
|
+
t.integer "post_id", null: false
|
34
|
+
t.string "title", null: false
|
35
|
+
t.text "body", null: false
|
36
|
+
t.integer "rating", null: false
|
37
|
+
t.datetime "created_at"
|
38
|
+
t.datetime "updated_at"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
We have three entities:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
class Post < ActiveRecord::Base
|
48
|
+
belongs_to :user
|
49
|
+
has_many :comments
|
50
|
+
end
|
51
|
+
|
52
|
+
class User < ActiveRecord::Base
|
53
|
+
has_many :comments
|
54
|
+
has_many :posts
|
55
|
+
end
|
56
|
+
|
57
|
+
class Comment < ActiveRecord::Base
|
58
|
+
belongs_to :post
|
59
|
+
belongs_to :user
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Controller
|
64
|
+
|
65
|
+
Create a new controller to focus on posts. Each drilldown controller focuses on
|
66
|
+
one main entity.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
class PostsDrilldownController < DrilldownController
|
70
|
+
|
71
|
+
# What fields should be displayed as default when listing actual Post records.
|
72
|
+
default_fields %w{created_at user title}
|
73
|
+
|
74
|
+
# The main focus of the drilldown
|
75
|
+
target_class Post
|
76
|
+
|
77
|
+
# How should we count the reords?
|
78
|
+
select "count(*) as count".freeze
|
79
|
+
|
80
|
+
# When listing records, what relations should be included for optimization?
|
81
|
+
list_includes :user, :comments
|
82
|
+
|
83
|
+
# In what order should records be listed?
|
84
|
+
list_order 'posts.created_at'
|
85
|
+
|
86
|
+
# Field definitions when listing records
|
87
|
+
field :created_at
|
88
|
+
field :title
|
89
|
+
|
90
|
+
# The "attr_method" option transforms the value from the database to a
|
91
|
+
# readable form.
|
92
|
+
field :user, attr_method: lambda { |post| post.user.name }
|
93
|
+
field :body, attr_method: lambda { |post| post.body[0..32] }
|
94
|
+
field :comments, attr_method: lambda { |post| post.comments.count }
|
95
|
+
|
96
|
+
dimension :calendar_date, "DATE(posts.created_at)", interval: true
|
97
|
+
dimension :comments, "SELECT count(*) FROM comments c WHERE c.post_id = posts.id"
|
98
|
+
dimension :user, 'users.name', includes: :user
|
99
|
+
dimension :day_of_month, "date_part('day', posts.created_at)"
|
100
|
+
dimension :day_of_week, "CASE WHEN date_part('dow', posts.created_at) = 0 THEN 7 ELSE date_part('dow', posts.created_at) END",
|
101
|
+
label_method: lambda { |day_no| Date::DAYNAMES[day_no.to_i % 7] }
|
102
|
+
dimension :hour_of_day, "date_part('hour', posts.created_at"
|
103
|
+
dimension :month, "date_part('month', posts.created_at",
|
104
|
+
label_method: lambda { |month_no| Date::MONTHNAMES[month_no.to_i] }
|
105
|
+
dimension :week, "date_part('week', posts.created_at)"
|
106
|
+
dimension :year, "date_part('year', posts.created_at)"
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
The controller inherits the ```index``` action and other actions to display the
|
111
|
+
results.
|
112
|
+
|
113
|
+
### Views
|
114
|
+
|
115
|
+
You need the following views:
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
## Excel export
|
120
|
+
|
121
|
+
# TODO: Write about Excel export.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
{excel_type: 'Number', excel_style: 'ThreeDecimalNumberFormat'}
|
125
|
+
```
|
6
126
|
|
7
127
|
## Installation
|
128
|
+
|
8
129
|
Add this line to your application's Gemfile:
|
9
130
|
|
10
131
|
```ruby
|
@@ -22,7 +143,12 @@ $ gem install simple_drilldown
|
|
22
143
|
```
|
23
144
|
|
24
145
|
## Contributing
|
25
|
-
|
146
|
+
|
147
|
+
1. Fork it
|
148
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
149
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
150
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
151
|
+
5. Create new Pull Request
|
26
152
|
|
27
153
|
## License
|
28
154
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/config/locales/nb.yml
CHANGED
@@ -416,7 +416,7 @@ module SimpleDrilldown
|
|
416
416
|
options[:include].uniq!
|
417
417
|
|
418
418
|
joins = self.class.make_join([], @target_class.name.underscore.to_sym, options.delete(:include))
|
419
|
-
result[:transactions] = @target_class.joins(joins).where(@base_condition).where(list_conditions(conditions, values)).includes(options[:include]).order(options[:order]).all
|
419
|
+
result[:transactions] = @target_class.unscoped.joins(joins).where(@base_condition).where(list_conditions(conditions, values)).includes(options[:include]).order(options[:order]).all
|
420
420
|
end
|
421
421
|
end
|
422
422
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_drilldown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uwe Kubosch
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
requirements: []
|
153
|
-
rubygems_version: 3.
|
153
|
+
rubygems_version: 3.1.2
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Simple data warehouse and drilldown.
|