get_stats 0.0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +22 -0
- data/README.md +142 -37
- data/app/assets/.DS_Store +0 -0
- data/app/models/stats.rb +129 -27
- data/app/views/_display_graph.html.erb +92 -12
- data/app/views/_display_table.html.erb +12 -0
- data/get_stats.gemspec +2 -2
- data/lib/get_stats/version.rb +1 -1
- data/lib/get_stats.rb +0 -38
- data/multiple_column_chart.png +0 -0
- data/multiple_line_chart.png +0 -0
- data/signups_column.png +0 -0
- data/signups_line.png +0 -0
- metadata +12 -5
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 meghagulati
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
There are lot of analytics tools out there which you can integrate with your application and get
|
1
|
+
There are lot of analytics tools out there which you can integrate with your application and get stats you need, but they do not always provide full control over the information, plus you always have to go back to there site to get the information.
|
2
2
|
|
3
|
-
|
3
|
+
GetStats is a simple way to measure key metrics in your Rails app.
|
4
4
|
|
5
5
|
[https://github.com/megharastogi/get_stats](https://github.com/megharastogi/get_stats)
|
6
6
|
|
7
|
-
If you have any
|
7
|
+
If you have any questions or feedback, please reach out to me on [Twitter](https://twitter.com/megharastogi).
|
8
8
|
|
9
9
|
Installation
|
10
10
|
------------
|
11
11
|
|
12
|
-
- Add `
|
12
|
+
- Add `'get_stats'` to your Gemfile.
|
13
13
|
- Run `bundle install`.
|
14
|
-
- Restart your server
|
15
14
|
- rails generate get_stats
|
16
15
|
- rake db:migrate
|
16
|
+
- Restart your server
|
17
|
+
|
17
18
|
|
18
19
|
This will create a stats table in your database to store all the information.
|
19
20
|
|
20
21
|
GetStats Usage
|
21
22
|
----------------
|
22
23
|
|
23
|
-
To
|
24
|
+
To track a metric, all you need to add to your code is:
|
24
25
|
|
25
26
|
```
|
26
27
|
Stats.increment('stats_name')
|
27
28
|
```
|
28
|
-
Where 'stats_name' is the name you want to assign to
|
29
|
+
Where 'stats_name' is the name you want to assign to the metric (ex: 'signup','liked_page')
|
29
30
|
|
30
|
-
Examples
|
31
|
-
|
31
|
+
Usage Examples
|
32
|
+
--------------
|
32
33
|
|
33
34
|
If you want to track number of signups everyday, you can add a call to Stats in 'after_create' to log the amount of signups every day.
|
34
35
|
|
35
36
|
```
|
36
37
|
class User < ActiveRecord::Base
|
37
38
|
def after_create
|
38
|
-
Stats.increment('
|
39
|
+
Stats.increment('signup')
|
39
40
|
end
|
40
41
|
end
|
41
42
|
```
|
42
|
-
If the '
|
43
|
-
existing stats.
|
43
|
+
If the stat 'signup' does not exists it will create one, otherwise it will just increment the existing stat for the current day.
|
44
44
|
|
45
|
-
|
45
|
+
To track number of succesfull payments made everyday you can do something like
|
46
46
|
|
47
47
|
```
|
48
48
|
class Payment < ActiveRecord::Base
|
@@ -56,11 +56,13 @@ class Payment < ActiveRecord::Base
|
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
59
|
-
|
59
|
+
Optionally, you can pass a date parameter to the 'increment' method to store the stat for a given date.
|
60
|
+
|
61
|
+
For example, if want to track how many users signed up on each day, you can add something like this to a rake task:
|
60
62
|
|
61
63
|
```
|
62
64
|
@users.each do |u|
|
63
|
-
Stats.increment('
|
65
|
+
Stats.increment('signup', u.created_at)
|
64
66
|
end
|
65
67
|
```
|
66
68
|
|
@@ -73,56 +75,159 @@ You can also pass the date attribute with 'increment' method to back fill data.
|
|
73
75
|
end
|
74
76
|
end
|
75
77
|
```
|
76
|
-
|
78
|
+
|
79
|
+
Retreiving Daily Stats
|
80
|
+
----------------------
|
81
|
+
|
82
|
+
Now that you have stored all the information, you just need to call Stats.daily_stats(stat_name)
|
77
83
|
|
78
84
|
```
|
79
|
-
Stats.
|
80
|
-
Stats.
|
81
|
-
Stats.show('successful_payment')
|
85
|
+
Stats.daily_stats('signup')
|
86
|
+
Stats.daily_stats('successful_payment')
|
82
87
|
```
|
83
|
-
By default it will
|
88
|
+
By default, it will output the data collected over last 7 days, but you can also pass options for viewing data for the trailing month, or a particular time range.
|
84
89
|
|
85
90
|
```
|
86
|
-
Stats.
|
87
|
-
Stats.
|
88
|
-
Stats.
|
91
|
+
Stats.daily_stats(stat_name,'week') // get trailing 7 days - default
|
92
|
+
Stats.daily_stats(stat_name,'month') // get trailing 30 days
|
93
|
+
Stats.daily_stats(stat_name,'time_range', start_date, end_date) // custom date range
|
89
94
|
|
90
95
|
```
|
91
96
|
```
|
92
|
-
Stats.
|
93
|
-
Stats.
|
94
|
-
Stats.
|
97
|
+
Stats.daily_stats('signup','week')
|
98
|
+
Stats.daily_stats('signup','month')
|
99
|
+
Stats.daily_stats('signup','time_range', Date.today - 15.days, Date.today)
|
100
|
+
|
101
|
+
```
|
95
102
|
|
103
|
+
Stats.daily_stats returns an array of data with count everyday
|
104
|
+
|
105
|
+
```
|
106
|
+
Stats.daily_stats('signup','week')
|
107
|
+
[["signup", Sat, 16 Feb 2013, 0], ["signup", Sun, 17 Feb 2013, 2], ["signup", Mon, 18 Feb 2013, 4], ["signup", Tue, 19 Feb 2013, 5], ["signup", Wed, 20 Feb 2013, 0], ["signup", Thu, 21 Feb 2013, 0]]
|
96
108
|
```
|
97
109
|
|
98
|
-
|
99
|
-
|
110
|
+
Retreiving Weekly Stats
|
111
|
+
----------------------
|
100
112
|
|
101
|
-
|
113
|
+
To view stored information aggregated over each week, you just need to call Stats.weekly_stats(stat_name)
|
102
114
|
|
103
115
|
```
|
104
|
-
Stats.
|
105
|
-
|
116
|
+
Stats.weekly_stats('signup')
|
117
|
+
Stats.weekly_stats('successful_payment')
|
118
|
+
```
|
119
|
+
By default, it will output the data collected over last 5 weeks, but you can also pass options for a particular time range.
|
120
|
+
|
106
121
|
```
|
122
|
+
Stats.weekly_stats(stat_name) // get trailing 5 weeks - default
|
123
|
+
Stats.weekly_stats(stat_name, start_date, end_date) // custom date range
|
107
124
|
|
108
|
-
|
109
|
-
|
110
|
-
|
125
|
+
```
|
126
|
+
```
|
127
|
+
Stats.weekly_stats('signup')
|
128
|
+
Stats.weekly_stats('signup', Date.today - 15.days, Date.today)
|
129
|
+
|
130
|
+
```
|
131
|
+
|
132
|
+
Stats.weekly_stats returns an array of data with count everyweek
|
133
|
+
|
134
|
+
```
|
135
|
+
Stats.weekly_stats('signup')
|
136
|
+
[["signup", Mon, 21 Jan 2013, 316], ["signup", Mon, 28 Jan 2013, 204], ["signup", Mon, 04 Feb 2013, 161], ["signup", Mon, 11 Feb 2013, 141], ["signup", Mon, 18 Feb 2013, 195], ["signup", Mon, 25 Feb 2013, 22]]
|
137
|
+
```
|
138
|
+
|
139
|
+
Retreiving Monthly Stats
|
140
|
+
----------------------
|
141
|
+
|
142
|
+
To view stored information aggregated over each month, you just need to call Stats.monthly_stats(stat_name)
|
143
|
+
|
144
|
+
```
|
145
|
+
Stats.monthly_stats('signup')
|
146
|
+
Stats.monthly_stats('successful_payment')
|
147
|
+
```
|
148
|
+
By default, it will output the data collected over last 5 months, but you can also pass options for a particular time range.
|
149
|
+
|
150
|
+
```
|
151
|
+
Stats.monthly_stats(stat_name) // get trailing 5 months - default
|
152
|
+
Stats.monthly_stats(stat_name, start_date, end_date) // custom date range
|
153
|
+
|
154
|
+
```
|
155
|
+
```
|
156
|
+
Stats.monthly_stats('signup')
|
157
|
+
Stats.monthly_stats('signup', Date.today - 8.months, Date.today)
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
Stats.monthly_stats returns an array of data with count every month
|
162
|
+
|
163
|
+
```
|
164
|
+
Stats.monthly_stats('signup')
|
165
|
+
[["signup", Mon, 01 Oct 2012, 1378], ["signup", Thu, 01 Nov 2012, 253], ["signup", Sat, 01 Dec 2012, 474], ["signup", Tue, 01 Jan 2013, 1391], ["signup", Mon, 25 Feb 2013, 565]]
|
166
|
+
```
|
167
|
+
|
168
|
+
Retreiving All Stat Names
|
169
|
+
-------------------------
|
170
|
+
|
171
|
+
To view list of all the stat_names stored in the system you can call
|
172
|
+
|
173
|
+
```
|
174
|
+
Stats.show_all_stat_names
|
175
|
+
```
|
176
|
+
Which will return an array of all the stat_names stored in the system
|
177
|
+
|
178
|
+
Displaying Graphs or Table
|
179
|
+
--------------------------
|
180
|
+
For displaying beautiful graphs, the gem uses [highcharts.js](http://www.highcharts.com/).
|
181
|
+
|
182
|
+
To add graphs to views, include highcharts.js (already added in the assets) and then use the partial 'display_graph'. Example below:
|
111
183
|
|
112
184
|
```
|
113
185
|
<%= javascript_include_tag :highcharts %>
|
114
186
|
|
115
|
-
<% @signups = Stats.
|
187
|
+
<% @signups = Stats.daily_stats('signups','week') %>
|
116
188
|
<%= render :partial => "./display_graph", :locals => {:stats => @signups,:graph_type => "line"}%>
|
189
|
+
<%= render :partial => "./display_graph", :locals => {:stats => @signups,:graph_type => "column"}%>
|
190
|
+
|
191
|
+
```
|
192
|
+
![Sample Single Line Graph](./signups_line.png)
|
193
|
+
![Sample Single Column Graph](./signups_column.png)
|
194
|
+
|
195
|
+
If you want to display more than one metric in a graph you can pass an array of different metrics to stats variable and pass variable 'multiple' true for example:
|
196
|
+
|
197
|
+
```
|
198
|
+
<%= javascript_include_tag :highcharts %>
|
199
|
+
|
200
|
+
<% @signups = Stats.daily_stats('signup','week') %>
|
201
|
+
<% @free_plan = Stats.daily_stats('Free Plan signups','week') %>
|
202
|
+
<% @paid_plan = Stats.daily_stats('Paid Plan signups','week') %>
|
203
|
+
|
204
|
+
<%= render :partial => "./display_graph", :locals => {:stats => [@signups,@free_plan,@paid_plan],:graph_type => "line",:multiple => "true"}%>
|
205
|
+
|
206
|
+
<%= render :partial => "./display_graph", :locals => {:stats => [@signups,@free_plan,@paid_plan],:graph_type => "column",:multiple => "true"}%>
|
207
|
+
|
117
208
|
```
|
118
|
-
|
209
|
+
![Sample Multi Line Graph](./multiple_line_chart.png)
|
210
|
+
![Sample Multi Column Graph](./multiple_column_chart.png)
|
211
|
+
|
212
|
+
Supported options for graph_type:
|
119
213
|
- 'line'
|
120
214
|
- 'area'
|
121
215
|
- 'bar'
|
122
216
|
- 'column'
|
123
217
|
|
218
|
+
You can also display the same information in table using 'display_table' partial.
|
219
|
+
|
220
|
+
```
|
221
|
+
<% @signups = Stats.show('signup','week') %>
|
222
|
+
|
223
|
+
<%= render :partial => "./display_table", :locals => {:stats => @signups}%>
|
224
|
+
|
225
|
+
```
|
226
|
+
|
227
|
+
More options are under development!
|
228
|
+
|
124
229
|
Feedback
|
125
230
|
--------
|
126
|
-
[Source code available on Github](https://github.com/megharastogi/get_stats). Feedback
|
231
|
+
[Source code available on Github](https://github.com/megharastogi/get_stats). Feedback would be greatly appreciated (this is my first Gem!)
|
127
232
|
|
128
233
|
|
Binary file
|
data/app/models/stats.rb
CHANGED
@@ -10,34 +10,136 @@ class Stats < ActiveRecord::Base
|
|
10
10
|
else
|
11
11
|
stat = Stats.create!(:stat_name => field,:stat_date => date.to_date,:count => 1)
|
12
12
|
end
|
13
|
-
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
def self.show(field,time_range="week",report_start_date=nil,report_end_date=nil)
|
16
|
+
end_date = Date.today
|
17
|
+
case time_range
|
18
|
+
when 'week'
|
19
|
+
start_date = end_date - 1.week
|
20
|
+
when 'month'
|
21
|
+
start_date = end_date - 1.month
|
22
|
+
else
|
23
|
+
start_date = end_date - 1.month
|
24
|
+
end
|
25
|
+
if !report_start_date.nil? && !report_end_date.nil?
|
26
|
+
start_date = report_start_date.to_date
|
27
|
+
end_date = report_end_date.to_date
|
28
|
+
end
|
29
|
+
@stats = Stats.find(:all,:conditions =>["stat_name=? and stat_date >=? and stat_date <=?",field,start_date,end_date])
|
30
|
+
@return_stat = []
|
31
|
+
now = start_date
|
32
|
+
while (now <= end_date) do
|
33
|
+
today_stats = @stats.select{|c| c if c.stat_date == now }
|
34
|
+
if today_stats.blank?
|
35
|
+
@return_stat << [field,now,0]
|
36
|
+
else
|
37
|
+
@return_stat << [field,today_stats[0].stat_date,today_stats[0].count]
|
28
38
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
now = now + 1.day
|
40
|
+
end
|
41
|
+
return @return_stat
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.daily_stats(field,time_range="last_week",report_start_date=nil,report_end_date=nil)
|
45
|
+
end_date = Date.today
|
46
|
+
case time_range
|
47
|
+
when 'week'
|
48
|
+
start_date = end_date - 1.week
|
49
|
+
when 'last_week'
|
50
|
+
start_date = end_date - 1.week
|
51
|
+
when 'month'
|
52
|
+
start_date = end_date - 1.month
|
53
|
+
when 'last_month'
|
54
|
+
start_date = end_date - 1.month
|
55
|
+
else
|
56
|
+
start_date = end_date - 1.month
|
57
|
+
end
|
58
|
+
if !report_start_date.nil? && !report_end_date.nil?
|
59
|
+
start_date = report_start_date.to_date
|
60
|
+
end_date = report_end_date.to_date
|
61
|
+
end
|
62
|
+
@stats = Stats.find(:all,:conditions =>["stat_name=? and stat_date >=? and stat_date <=?",field,start_date,end_date])
|
63
|
+
@return_stat = []
|
64
|
+
now = start_date
|
65
|
+
while (now <= end_date) do
|
66
|
+
today_stats = @stats.select{|c| c if c.stat_date == now }
|
67
|
+
if today_stats.blank?
|
68
|
+
@return_stat << [field,now,0]
|
69
|
+
else
|
70
|
+
@return_stat << [field,today_stats[0].stat_date,today_stats[0].count]
|
40
71
|
end
|
41
|
-
|
42
|
-
end
|
72
|
+
now = now + 1.day
|
73
|
+
end
|
74
|
+
return @return_stat
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.weekly_stats(field,report_start_date=nil,report_end_date=nil)
|
78
|
+
if report_end_date.nil?
|
79
|
+
report_end_date = Date.today
|
80
|
+
end
|
81
|
+
|
82
|
+
if report_start_date.nil? || report_start_date >= report_end_date
|
83
|
+
report_start_date = report_end_date - 1.month
|
84
|
+
end
|
85
|
+
report_start_date = report_start_date - report_start_date.wday + 1
|
86
|
+
@stats = Stats.find(:all,:conditions =>["stat_name=? and stat_date >=? and stat_date <=?",field,report_start_date,report_end_date])
|
87
|
+
now = report_start_date
|
88
|
+
@return_stat = []
|
89
|
+
week_collection = 0
|
90
|
+
while (now <= report_end_date) do
|
91
|
+
today_stats = @stats.select{|c| c if c.stat_date == now }
|
92
|
+
if !today_stats.blank?
|
93
|
+
week_collection = week_collection + today_stats[0].count
|
94
|
+
end
|
95
|
+
if now.monday? && now != report_start_date
|
96
|
+
@return_stat << [field,now - 1.week ,week_collection]
|
97
|
+
week_collection = 0
|
98
|
+
end
|
99
|
+
|
100
|
+
if now == report_end_date && !now.monday?
|
101
|
+
@return_stat << [field,now - now.wday + 1,week_collection]
|
102
|
+
end
|
103
|
+
now = now + 1.day
|
104
|
+
end
|
105
|
+
return @return_stat
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.monthly_stats(field,report_start_date=nil,report_end_date=nil)
|
109
|
+
if report_end_date.nil?
|
110
|
+
report_end_date = Date.today
|
111
|
+
end
|
112
|
+
|
113
|
+
if report_start_date.nil? || report_start_date >= report_end_date
|
114
|
+
report_start_date = report_end_date - 4.months
|
115
|
+
end
|
116
|
+
report_start_date = report_start_date - report_start_date.mday + 1
|
117
|
+
@stats = Stats.find(:all,:conditions =>["stat_name=? and stat_date >=? and stat_date <=?",field,report_start_date,report_end_date])
|
118
|
+
now = report_start_date
|
119
|
+
@return_stat = []
|
120
|
+
month_collection = 0
|
121
|
+
while (now <= report_end_date) do
|
122
|
+
today_stats = @stats.select{|c| c if c.stat_date == now }
|
123
|
+
if !today_stats.blank?
|
124
|
+
month_collection = month_collection + today_stats[0].count
|
125
|
+
end
|
126
|
+
if now.mday == 1 && now != report_start_date
|
127
|
+
@return_stat << [field,now - 1.month ,month_collection]
|
128
|
+
month_collection = 0
|
129
|
+
end
|
130
|
+
if now + 1.day == report_end_date && (now + 1.day).mday != 1
|
131
|
+
@return_stat << [field,now ,month_collection]
|
132
|
+
end
|
133
|
+
now = now + 1.day
|
134
|
+
end
|
135
|
+
return @return_stat
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
def self.show_all_stat_names
|
140
|
+
@stats = Stats.find(:all,:group => 'stat_name')
|
141
|
+
@stat_names = []
|
142
|
+
@stats.each{|s| @stat_names << s.stat_name}
|
143
|
+
return @stat_names
|
144
|
+
end
|
43
145
|
end
|
@@ -1,15 +1,16 @@
|
|
1
|
-
|
1
|
+
<%rand = rand(100) %>
|
2
|
+
<% if (defined? multiple) && multiple == "true"%>
|
2
3
|
<script>
|
3
4
|
$(function () {
|
4
5
|
var chart;
|
5
6
|
$(document).ready(function() {
|
6
7
|
chart = new Highcharts.Chart({
|
7
8
|
chart: {
|
8
|
-
renderTo: "container<%=stats.first[0]%>",
|
9
|
+
renderTo: "container<%=stats.first.first[0]%><%=rand%>",
|
9
10
|
type: "<%= graph_type %>"
|
10
11
|
},
|
11
12
|
title: {
|
12
|
-
text: "<%=stats.first[0]%>"
|
13
|
+
text: "<%=stats.first.first[0]%>"
|
13
14
|
},
|
14
15
|
subtitle: {
|
15
16
|
text: ""
|
@@ -21,14 +22,91 @@
|
|
21
22
|
},
|
22
23
|
xAxis: {
|
23
24
|
categories: [
|
24
|
-
<% stats.each_with_index do |c,i|%>
|
25
|
+
<% stats.first.each_with_index do |c,i|%>
|
25
26
|
"<%= c[1].strftime("%m/%d")%>"
|
26
|
-
<%if i != (stats.length - 1) %>
|
27
|
+
<%if i != (stats.first.length - 1) %>
|
27
28
|
,
|
28
29
|
<% end %>
|
29
30
|
<% end %>
|
30
31
|
]
|
31
32
|
},
|
33
|
+
yAxis: {
|
34
|
+
title: {
|
35
|
+
text: 'Number of ' + "<%=stats.first.first[0]%>"
|
36
|
+
}
|
37
|
+
},
|
38
|
+
tooltip: {
|
39
|
+
enabled: false,
|
40
|
+
formatter: function() {
|
41
|
+
return '<b>'+ this.series.name +'</b><br/>'+
|
42
|
+
this.x +': '+ this.y +'°C';
|
43
|
+
}
|
44
|
+
},
|
45
|
+
plotOptions: {
|
46
|
+
line: {
|
47
|
+
dataLabels: {
|
48
|
+
enabled: true
|
49
|
+
},
|
50
|
+
enableMouseTracking: false
|
51
|
+
}
|
52
|
+
},
|
53
|
+
series: [
|
54
|
+
<% stats.each_with_index do |s,k| %>
|
55
|
+
{
|
56
|
+
name: "<%=s.first[0]%>",
|
57
|
+
data: [<% s.each_with_index do |c,i|%>
|
58
|
+
<%= c[2]%>
|
59
|
+
<%if i != (s.length - 1) %>
|
60
|
+
,
|
61
|
+
<% end %>
|
62
|
+
<% end %>]
|
63
|
+
}
|
64
|
+
<%if k != (stats.length - 1) %>
|
65
|
+
,
|
66
|
+
<% end %>
|
67
|
+
<% end %>
|
68
|
+
]
|
69
|
+
});
|
70
|
+
});
|
71
|
+
|
72
|
+
});
|
73
|
+
</script>
|
74
|
+
<div style="<%=stats.first.length <= 8 ? 'width:700px;' : 'width:1500px;'%>">
|
75
|
+
<div id="container<%=stats.first.first[0]%><%=rand%>" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
|
76
|
+
</div>
|
77
|
+
|
78
|
+
<% else %>
|
79
|
+
|
80
|
+
<script>
|
81
|
+
$(function () {
|
82
|
+
var chart;
|
83
|
+
$(document).ready(function() {
|
84
|
+
chart = new Highcharts.Chart({
|
85
|
+
chart: {
|
86
|
+
renderTo: "container<%=stats.first[0]%><%=rand%>",
|
87
|
+
type: "<%= graph_type %>"
|
88
|
+
},
|
89
|
+
title: {
|
90
|
+
text: "<%=stats.first[0]%>"
|
91
|
+
},
|
92
|
+
subtitle: {
|
93
|
+
text: ""
|
94
|
+
// <% if session[:report_type] == 'custom' %>
|
95
|
+
// "From: <%=session[:report_start_date] %> to <%=session[:report_end_date]%>"
|
96
|
+
// <% else %>
|
97
|
+
// "From: <%= session[:report_type] == 'month' ? Date.today - 1.month : Date.today - 1.week%> to <%=Date.today%>"
|
98
|
+
// <%end %>
|
99
|
+
},
|
100
|
+
xAxis: {
|
101
|
+
categories: [
|
102
|
+
<% stats.each_with_index do |c,i|%>
|
103
|
+
"<%= c[1].strftime("%m/%d")%>"
|
104
|
+
<%if i != (stats.length - 1) %>
|
105
|
+
,
|
106
|
+
<% end %>
|
107
|
+
<% end %>
|
108
|
+
]
|
109
|
+
},
|
32
110
|
yAxis: {
|
33
111
|
title: {
|
34
112
|
text: 'Number of ' + "<%=stats.first[0]%>"
|
@@ -52,10 +130,10 @@
|
|
52
130
|
series: [{
|
53
131
|
name: '',
|
54
132
|
data: [<% stats.each_with_index do |c,i|%>
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
133
|
+
<%= c[2]%>
|
134
|
+
<%if i != (stats.length - 1) %>
|
135
|
+
,
|
136
|
+
<% end %>
|
59
137
|
<% end %>]
|
60
138
|
}]
|
61
139
|
});
|
@@ -63,6 +141,8 @@
|
|
63
141
|
|
64
142
|
});
|
65
143
|
</script>
|
66
|
-
<div style="<%=stats.length <= 8 ? 'width:700px;' : 'width:1500px;'%>">
|
67
|
-
<div id="container<%=stats.first[0]%>" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
|
68
|
-
</div>
|
144
|
+
<div style="<%=stats.first.length <= 8 ? 'width:700px;' : 'width:1500px;'%>">
|
145
|
+
<div id="container<%=stats.first[0]%><%=rand%>" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
|
146
|
+
</div>
|
147
|
+
|
148
|
+
<% end %>
|
data/get_stats.gemspec
CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/get_stats/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["megha"]
|
6
6
|
gem.email = ["meghagulati30@gmail.com"]
|
7
|
-
gem.description = %q{
|
8
|
-
gem.summary = %q{Provides
|
7
|
+
gem.description = %q{Dead simply statistics for Rails.}
|
8
|
+
gem.summary = %q{Provides a simple API for developers to log & view stats within their app. Uses highcharts.js for displaying beautiful graphs with one simple call.}
|
9
9
|
gem.homepage = ""
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
data/lib/get_stats/version.rb
CHANGED
data/lib/get_stats.rb
CHANGED
@@ -2,42 +2,4 @@ module GetStats
|
|
2
2
|
|
3
3
|
require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
4
4
|
|
5
|
-
# def self.increment(field,date= Time.now)
|
6
|
-
# stat = Stats.find(:first,:conditions =>["stat_name=? and stat_date =?",field,date.to_date])
|
7
|
-
# if stat
|
8
|
-
# stat.update_attributes(:count => stat.count + 1)
|
9
|
-
# else
|
10
|
-
# stat = Stats.create(:stat_name => field,:stat_date => date.to_date,:count => 1)
|
11
|
-
# end
|
12
|
-
# end
|
13
|
-
|
14
|
-
# def self.show(field,time_range="week",report_start_date=nil,report_end_date=nil)
|
15
|
-
# end_date = Date.today
|
16
|
-
# case time_range
|
17
|
-
# when 'week'
|
18
|
-
# start_date = end_date - 1.week
|
19
|
-
# when 'month'
|
20
|
-
# start_date = end_date - 1.month
|
21
|
-
# else
|
22
|
-
# start_date = end_date - 1.month
|
23
|
-
# end
|
24
|
-
# if !report_start_date.nil? && !report_end_date.nil?
|
25
|
-
# start_date = report_start_date.to_date
|
26
|
-
# end_date = report_end_date.to_date
|
27
|
-
# end
|
28
|
-
# @stats = Stats.find(:all,:conditions =>["stat_name=? and stat_date >=? and stat_date <=?",field,start_date,end_date])
|
29
|
-
# @return_stat = []
|
30
|
-
# now = start_date
|
31
|
-
# while (now <= end_date) do
|
32
|
-
# today_stats = @stats.select{|c| c if c.stat_date == now }
|
33
|
-
# if today_stats.blank?
|
34
|
-
# @return_stat << [now,0]
|
35
|
-
# else
|
36
|
-
# @return_stat << [today_stats[0].stat_date,today_stats[0].count]
|
37
|
-
# end
|
38
|
-
# now = now + 1.day
|
39
|
-
# end
|
40
|
-
# return @return_stat
|
41
|
-
# end
|
42
|
-
|
43
5
|
end
|
Binary file
|
Binary file
|
data/signups_column.png
ADDED
Binary file
|
data/signups_line.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: get_stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Dead simply statistics for Rails.
|
15
15
|
email:
|
16
16
|
- meghagulati30@gmail.com
|
17
17
|
executables: []
|
@@ -20,11 +20,14 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- .gitignore
|
22
22
|
- Gemfile
|
23
|
+
- LICENSE
|
23
24
|
- README.md
|
24
25
|
- Rakefile
|
26
|
+
- app/assets/.DS_Store
|
25
27
|
- app/assets/javascripts/highcharts.js
|
26
28
|
- app/models/stats.rb
|
27
29
|
- app/views/_display_graph.html.erb
|
30
|
+
- app/views/_display_table.html.erb
|
28
31
|
- get_stats.gemspec
|
29
32
|
- lib/application_helper.rb
|
30
33
|
- lib/engine.rb
|
@@ -36,6 +39,10 @@ files:
|
|
36
39
|
- lib/rails/generators/get_stats/templates/migration.rb
|
37
40
|
- lib/rails/generators/get_stats/templates/schema.rb
|
38
41
|
- lib/rails/railties/tasks.rake
|
42
|
+
- multiple_column_chart.png
|
43
|
+
- multiple_line_chart.png
|
44
|
+
- signups_column.png
|
45
|
+
- signups_line.png
|
39
46
|
homepage: ''
|
40
47
|
licenses: []
|
41
48
|
post_install_message:
|
@@ -59,6 +66,6 @@ rubyforge_project:
|
|
59
66
|
rubygems_version: 1.8.24
|
60
67
|
signing_key:
|
61
68
|
specification_version: 3
|
62
|
-
summary: Provides
|
63
|
-
with
|
69
|
+
summary: Provides a simple API for developers to log & view stats within their app.
|
70
|
+
Uses highcharts.js for displaying beautiful graphs with one simple call.
|
64
71
|
test_files: []
|