metricky 0.7.5 → 0.8.0
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 +18 -0
- data/app/controllers/metrics_controller.rb +11 -0
- data/app/views/metricky/_metric.html.erb +1 -1
- data/config/routes.rb +3 -0
- data/lib/generators/metricky/templates/metric.rb.tt +11 -6
- data/lib/metricky/base.rb +32 -0
- data/lib/metricky/helper.rb +10 -2
- data/lib/metricky/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 362f2f40e07645963b83935211c9ab8c222db9cb9064c099dd8b466597be2b08
|
4
|
+
data.tar.gz: 5a882ce98adecc050b1f3398935b26b09d961d67d98db24b5a018a3f3c43d65f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3f72bad0f1523a606e27244780c1b43e739fd846e5b393c4ab1bac1a2c4a8b8b2ca63cd23a01f51a7ff7a710faa624b1236dff0b0d1cc613707459ccec3967e
|
7
|
+
data.tar.gz: 9fa0ad994b4c4558f95eecb24ba9bf05ee42f19fc2805771900716925433f1b818e528f6887e2cff0b0f8ba5ab884cb85fd10541fdd482e6937aa9ef0f59103c
|
data/README.md
CHANGED
@@ -86,6 +86,16 @@ def columns
|
|
86
86
|
end
|
87
87
|
```
|
88
88
|
|
89
|
+
### Grouping the value
|
90
|
+
|
91
|
+
To `User.all.group(:color).count`
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
def group
|
95
|
+
:color
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
89
99
|
### Grouping by period (day, month, year, quarter, etc.)
|
90
100
|
|
91
101
|
In your metric, define what period:
|
@@ -150,6 +160,14 @@ class TotalUsersMetric < ApplicationMetric
|
|
150
160
|
end
|
151
161
|
```
|
152
162
|
|
163
|
+
#### Removing all ranges
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
class TotalUsersMetric < ApplicationMetric
|
167
|
+
reset_ranges!
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
153
171
|
#### Setting the default range
|
154
172
|
|
155
173
|
```ruby
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Metricky
|
2
|
+
class MetricsController < ActionController::Base
|
3
|
+
def show
|
4
|
+
metric = "#{params[:name].classify}Metric".constantize.new(params[:query] || {}, params[:options] || {})
|
5
|
+
unless metric.results.is_a?(Hash) || metric.results.is_a?(Array)
|
6
|
+
raise RenderError, "results must be a hash or array"
|
7
|
+
end
|
8
|
+
render json: metric.to_json
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/config/routes.rb
ADDED
@@ -10,15 +10,14 @@ class <%= class_name %>Metric < ApplicationMetric
|
|
10
10
|
def type
|
11
11
|
<%= options[:type][0] == ':' ? options[:type] : ":#{options[:type]}" %>
|
12
12
|
end
|
13
|
-
<% if options[:
|
13
|
+
<% if options[:group] %>
|
14
14
|
def period
|
15
|
-
<%= options[:
|
15
|
+
<%= options[:group][0] == ':' ? options[:group] : ":#{options[:group]}" %>
|
16
16
|
end
|
17
17
|
<% else %>
|
18
|
-
# ==> Change the
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# :week
|
18
|
+
# ==> Change the grouping
|
19
|
+
# def group
|
20
|
+
# :color
|
22
21
|
# end
|
23
22
|
<% end %>
|
24
23
|
|
@@ -42,5 +41,11 @@ class <%= class_name %>Metric < ApplicationMetric
|
|
42
41
|
# def form?
|
43
42
|
# false
|
44
43
|
# end
|
44
|
+
|
45
|
+
# ==> Render chart async
|
46
|
+
# Renders the chart asynchronously with an ajax request. There are some limitations. Read here.
|
47
|
+
# def form?
|
48
|
+
# false
|
49
|
+
# end
|
45
50
|
end
|
46
51
|
<% end -%>
|
data/lib/metricky/base.rb
CHANGED
@@ -20,6 +20,10 @@ module Metricky
|
|
20
20
|
:column_chart
|
21
21
|
end
|
22
22
|
|
23
|
+
def chart_options
|
24
|
+
@chart_options ||= {}
|
25
|
+
end
|
26
|
+
|
23
27
|
# What partial is rendered.
|
24
28
|
def to_partial_path
|
25
29
|
'/metricky/metric'
|
@@ -40,6 +44,10 @@ module Metricky
|
|
40
44
|
assets
|
41
45
|
end
|
42
46
|
|
47
|
+
def name
|
48
|
+
self.class.metric_name
|
49
|
+
end
|
50
|
+
|
43
51
|
def self.metric_name
|
44
52
|
name.demodulize.sub(/Metric$/, "")
|
45
53
|
end
|
@@ -85,6 +93,26 @@ module Metricky
|
|
85
93
|
ranges.any?
|
86
94
|
end
|
87
95
|
|
96
|
+
def chart?
|
97
|
+
results.is_a?(Hash) || results.is_a?(Array)
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_json
|
101
|
+
results.chart_json
|
102
|
+
end
|
103
|
+
|
104
|
+
def group
|
105
|
+
false
|
106
|
+
end
|
107
|
+
|
108
|
+
def group?
|
109
|
+
group.present?
|
110
|
+
end
|
111
|
+
|
112
|
+
def json?
|
113
|
+
false
|
114
|
+
end
|
115
|
+
|
88
116
|
private
|
89
117
|
|
90
118
|
def assets
|
@@ -95,6 +123,9 @@ module Metricky
|
|
95
123
|
if period? && valid_period?
|
96
124
|
@query = @query.group_by_period(period, period_column)
|
97
125
|
end
|
126
|
+
if group?
|
127
|
+
@query = @query.group(group)
|
128
|
+
end
|
98
129
|
if valid_type?
|
99
130
|
@query = @query.send(type, *columns)
|
100
131
|
else
|
@@ -108,6 +139,7 @@ module Metricky
|
|
108
139
|
@query
|
109
140
|
end
|
110
141
|
|
142
|
+
|
111
143
|
def format_value(value)
|
112
144
|
value
|
113
145
|
end
|
data/lib/metricky/helper.rb
CHANGED
@@ -6,6 +6,10 @@ module Metricky
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
def metricky_metric_path(metric, options = {})
|
10
|
+
metricky.metric_path(name: metric.name.underscore, query: request.query_parameters, options: options)
|
11
|
+
end
|
12
|
+
|
9
13
|
def render_metric(metric_name, options = {})
|
10
14
|
if metric_name.is_a?(String) || metric_name.is_a?(Symbol)
|
11
15
|
metric_name = metric_name.to_s
|
@@ -23,8 +27,12 @@ module Metricky
|
|
23
27
|
render metric, metric: metric
|
24
28
|
end
|
25
29
|
|
26
|
-
def metricky_chart(metric)
|
27
|
-
|
30
|
+
def metricky_chart(metric, options = {})
|
31
|
+
if metric.json?
|
32
|
+
send(metric.chart, metricky_metric_path(metric, options))
|
33
|
+
else
|
34
|
+
send(metric.chart, metric.results, options)
|
35
|
+
end
|
28
36
|
end
|
29
37
|
end
|
30
38
|
end
|
data/lib/metricky/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metricky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Brody
|
@@ -118,8 +118,10 @@ files:
|
|
118
118
|
- MIT-LICENSE
|
119
119
|
- README.md
|
120
120
|
- Rakefile
|
121
|
+
- app/controllers/metrics_controller.rb
|
121
122
|
- app/metrics/application_metric.rb
|
122
123
|
- app/views/metricky/_metric.html.erb
|
124
|
+
- config/routes.rb
|
123
125
|
- lib/generators/metricky/USAGE
|
124
126
|
- lib/generators/metricky/metric_generator.rb
|
125
127
|
- lib/generators/metricky/templates/application_metric.rb.tt
|