metricky 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/lib/generators/metricky/metric_generator.rb +1 -0
- data/lib/metricky/base.rb +17 -7
- data/lib/metricky/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ba909df61c99a49ddea9e6bc914eb941796f18c38443e6becdecf3766542522
|
4
|
+
data.tar.gz: 3c69b7adda470fe9d06e7fb0383213d988b191a0224b3be4d6cf1518c450887a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 924c1ded4febd716dbbd9d01885581668cd3dfb014595fb630efe2e5c92d3e280fdc7b04ad87d5797fc528b2f639fc67585f392755cf1dfd68046a36c8fb9d62
|
7
|
+
data.tar.gz: 25309a6bd7a3836ab5a6b69b85301c958c64023638a0d3b4100b9c8fd117d263a1376cd13dedb7ad728bbfe6ac2c0d397a17255d5f30dd7a9a59d139fc8d9594
|
data/README.md
CHANGED
@@ -7,6 +7,9 @@ Make this in Ruby:
|
|
7
7
|
|
8
8
|
<img src="https://i.imgur.com/PQhFyAE.png" alt="Metricky example">
|
9
9
|
|
10
|
+
## Generate it
|
11
|
+
|
12
|
+
`rails g metricky:metric User --scope User --type :count --period :day`
|
10
13
|
In your view where you want to display the metric:
|
11
14
|
|
12
15
|
```erbruby
|
@@ -29,7 +32,7 @@ class UsersMetric < Metricky::Base
|
|
29
32
|
:id
|
30
33
|
end
|
31
34
|
|
32
|
-
def
|
35
|
+
def period
|
33
36
|
:day
|
34
37
|
end
|
35
38
|
end
|
@@ -72,12 +75,12 @@ def columns
|
|
72
75
|
end
|
73
76
|
```
|
74
77
|
|
75
|
-
### Grouping
|
78
|
+
### Grouping by date
|
76
79
|
|
77
|
-
In your metric, define what
|
80
|
+
In your metric, define what period:
|
78
81
|
|
79
82
|
```ruby
|
80
|
-
def
|
83
|
+
def period
|
81
84
|
:day
|
82
85
|
end
|
83
86
|
```
|
@@ -87,7 +90,7 @@ This can be any one of `Groupdate::PERIODS`
|
|
87
90
|
Define what column should be used:
|
88
91
|
|
89
92
|
```ruby
|
90
|
-
def
|
93
|
+
def period_column
|
91
94
|
:created_at
|
92
95
|
end
|
93
96
|
```
|
data/lib/metricky/base.rb
CHANGED
@@ -123,6 +123,11 @@ module Metricky
|
|
123
123
|
# [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week,
|
124
124
|
# :hour_of_day, :minute_of_hour, :day_of_month, :month_of_year]
|
125
125
|
def trend
|
126
|
+
ActiveSupport::Deprecation.warn('Use period instead')
|
127
|
+
period
|
128
|
+
end
|
129
|
+
|
130
|
+
def period
|
126
131
|
nil
|
127
132
|
end
|
128
133
|
|
@@ -132,18 +137,23 @@ module Metricky
|
|
132
137
|
end
|
133
138
|
|
134
139
|
# What column to specify for the trend calculation. Normally `created_at`
|
135
|
-
def
|
140
|
+
def period_column
|
136
141
|
'created_at'
|
137
142
|
end
|
138
143
|
|
144
|
+
def trend_column
|
145
|
+
ActiveSupport::Deprecation.warn('Use period_column instead')
|
146
|
+
period_column
|
147
|
+
end
|
148
|
+
|
139
149
|
def range
|
140
150
|
params.dig(form_name, :range)
|
141
151
|
end
|
142
152
|
|
143
153
|
private
|
144
154
|
|
145
|
-
def
|
146
|
-
|
155
|
+
def period?
|
156
|
+
period.present?
|
147
157
|
end
|
148
158
|
|
149
159
|
def assets
|
@@ -152,16 +162,16 @@ module Metricky
|
|
152
162
|
else
|
153
163
|
@query = scope
|
154
164
|
end
|
155
|
-
if
|
165
|
+
if period? && valid_period?
|
156
166
|
@query = @query.group_by_period(trend, trend_column)
|
157
167
|
end
|
158
168
|
@query = @query.send(type, *columns)
|
159
169
|
@query
|
160
170
|
end
|
161
171
|
|
162
|
-
def
|
163
|
-
return true if Groupdate::PERIODS.include?(
|
164
|
-
raise NameError, "
|
172
|
+
def valid_period?
|
173
|
+
return true if Groupdate::PERIODS.include?(period.to_sym)
|
174
|
+
raise NameError, "period must be one of #{Groupdate::PERIODS}. It is #{period}."
|
165
175
|
end
|
166
176
|
|
167
177
|
def check_type
|
data/lib/metricky/version.rb
CHANGED