rails_local_analytics 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c1dffba4cbead6faa6192e3c1df830aa749f6f653bdc8f0eef6e9dbd3a2650b
|
4
|
+
data.tar.gz: b0b6a574e09786c7888c4e6194fff36616f9d0634d99773955e762417ee3c828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 021fcb8b029ce1d842415eb5a4a3ed39a433726851988891455f2aa1ec510a1f56acc9563bad3003b799624384a8ff74ef40183e0a81746df82bb1d3b68d2e24
|
7
|
+
data.tar.gz: 6c9d8b537f1de5f9b28b1b6e6baac6135a389a1ba65bb5dbc19a4ebdd7b73e1efaf855e6daaaa81b8b06b0a2d1913e0d0cdc97fd31635c794d545238751820c6
|
@@ -3,6 +3,7 @@ module RailsLocalAnalytics
|
|
3
3
|
PER_PAGE_LIMIT = 1000
|
4
4
|
|
5
5
|
helper_method :pagination_page_number
|
6
|
+
helper_method :display_columns
|
6
7
|
|
7
8
|
def index
|
8
9
|
params[:type] ||= "page"
|
@@ -17,17 +18,13 @@ module RailsLocalAnalytics
|
|
17
18
|
return
|
18
19
|
end
|
19
20
|
|
20
|
-
if params[:group_by].present? && !@klass.display_columns.include?(params[:group_by])
|
21
|
-
raise ArgumentError
|
22
|
-
end
|
23
|
-
|
24
21
|
if params[:start_date].present?
|
25
22
|
@start_date = Date.parse(params[:start_date])
|
26
23
|
else
|
27
24
|
@start_date = Date.today
|
28
25
|
end
|
29
26
|
|
30
|
-
if params[:end_date]
|
27
|
+
if params[:end_date].present?
|
31
28
|
@end_date = Date.parse(params[:end_date])
|
32
29
|
else
|
33
30
|
@end_date = Date.today
|
@@ -63,20 +60,18 @@ module RailsLocalAnalytics
|
|
63
60
|
|
64
61
|
prev_start_date, prev_end_date = get_prev_dates(start_date, end_date)
|
65
62
|
|
66
|
-
|
63
|
+
difference_where_conditions = params.require(:conditions).permit(*display_columns)
|
67
64
|
|
68
65
|
current_total = fetch_records(
|
69
66
|
start_date,
|
70
67
|
end_date,
|
71
|
-
|
72
|
-
pluck_columns: ["SUM(total)"],
|
68
|
+
difference_where_conditions: difference_where_conditions,
|
73
69
|
).first
|
74
70
|
|
75
71
|
prev_total = fetch_records(
|
76
72
|
prev_start_date,
|
77
73
|
prev_end_date,
|
78
|
-
|
79
|
-
pluck_columns: ["SUM(total)"],
|
74
|
+
difference_where_conditions: difference_where_conditions,
|
80
75
|
).first
|
81
76
|
|
82
77
|
if prev_total
|
@@ -90,13 +85,17 @@ module RailsLocalAnalytics
|
|
90
85
|
|
91
86
|
private
|
92
87
|
|
93
|
-
def fetch_records(start_date, end_date,
|
88
|
+
def fetch_records(start_date, end_date, difference_where_conditions: nil)
|
89
|
+
aggregate_sql_field = "SUM(total)"
|
90
|
+
|
94
91
|
tracked_requests = @klass
|
95
92
|
.where("day >= ?", start_date)
|
96
93
|
.where("day <= ?", end_date)
|
97
|
-
.order(
|
94
|
+
.order("#{aggregate_sql_field} DESC")
|
98
95
|
|
99
|
-
if
|
96
|
+
if difference_where_conditions
|
97
|
+
tracked_requests = tracked_requests.where(difference_where_conditions)
|
98
|
+
else
|
100
99
|
tracked_requests = tracked_requests
|
101
100
|
.limit(PER_PAGE_LIMIT)
|
102
101
|
.offset(PER_PAGE_LIMIT * (pagination_page_number-1))
|
@@ -104,7 +103,7 @@ module RailsLocalAnalytics
|
|
104
103
|
if params[:filter].present?
|
105
104
|
col, val = params[:filter].split("==")
|
106
105
|
|
107
|
-
if
|
106
|
+
if display_columns.include?(col)
|
108
107
|
tracked_requests = tracked_requests.where(col => val)
|
109
108
|
else
|
110
109
|
raise ArgumentError
|
@@ -112,24 +111,43 @@ module RailsLocalAnalytics
|
|
112
111
|
end
|
113
112
|
end
|
114
113
|
|
115
|
-
if where_conditions
|
116
|
-
tracked_requests = tracked_requests.where(where_conditions)
|
117
|
-
end
|
118
|
-
|
119
114
|
if params[:search].present?
|
120
115
|
tracked_requests = tracked_requests.multi_search(params[:search])
|
121
116
|
end
|
122
117
|
|
123
|
-
if params[:group_by].
|
124
|
-
|
125
|
-
pluck_columns = [params[:group_by], "SUM(total)"]
|
118
|
+
if params[:group_by].blank?
|
119
|
+
pluck_columns = display_columns.dup
|
126
120
|
else
|
127
|
-
|
128
|
-
|
121
|
+
case params[:group_by]
|
122
|
+
when "url_hostname_and_path"
|
123
|
+
if display_columns.include?("url_hostname") && display_columns.include?("url_path")
|
124
|
+
pluck_columns = [:url_hostname, :url_path]
|
125
|
+
else
|
126
|
+
raise ArgumentError
|
127
|
+
end
|
128
|
+
when "referrer_hostname_and_path"
|
129
|
+
if display_columns.include?("referrer_hostname") && display_columns.include?("referrer_path")
|
130
|
+
pluck_columns = [:referrer_hostname, :referrer_path]
|
131
|
+
else
|
132
|
+
raise ArgumentError
|
133
|
+
end
|
134
|
+
when *display_columns
|
135
|
+
pluck_columns = [params[:group_by]]
|
136
|
+
else
|
137
|
+
raise ArgumentError
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
group_by = pluck_columns.dup
|
142
|
+
|
143
|
+
if difference_where_conditions
|
144
|
+
pluck_columns = [aggregate_sql_field]
|
145
|
+
else
|
146
|
+
pluck_columns << aggregate_sql_field
|
129
147
|
end
|
130
148
|
|
131
149
|
tracked_requests
|
132
|
-
.group(*
|
150
|
+
.group(*group_by)
|
133
151
|
.pluck(*pluck_columns)
|
134
152
|
end
|
135
153
|
|
@@ -151,5 +169,9 @@ module RailsLocalAnalytics
|
|
151
169
|
return [prev_start_date, prev_end_date]
|
152
170
|
end
|
153
171
|
|
172
|
+
def display_columns
|
173
|
+
@display_columns ||= @klass.display_columns
|
174
|
+
end
|
175
|
+
|
154
176
|
end
|
155
177
|
end
|
@@ -1,9 +1,41 @@
|
|
1
|
-
<%
|
1
|
+
<%
|
2
|
+
data_columns = params[:group_by].present? ? [params[:group_by]] : display_columns
|
3
|
+
|
4
|
+
if data_columns.first == "url_hostname_and_path"
|
5
|
+
data_columns = ["URL Hostname", "URL Path"]
|
6
|
+
elsif data_columns.first == "referrer_hostname_and_path"
|
7
|
+
data_columns = ["Referrer Hostname", "Referrer Path"]
|
8
|
+
end
|
9
|
+
%>
|
10
|
+
|
11
|
+
<%
|
12
|
+
group_by_opts = [
|
13
|
+
["All", nil],
|
14
|
+
]
|
15
|
+
|
16
|
+
group_by_opts += display_columns.map{|x| [x.titleize.sub("Url ", "URL "), x] }
|
17
|
+
|
18
|
+
if display_columns.include?("url_hostname") && display_columns.include?("url_path")
|
19
|
+
index = group_by_opts.index(["URL Hostname", "url_hostname"])
|
20
|
+
group_by_opts.insert(
|
21
|
+
index,
|
22
|
+
["URL Hostname and Path", "url_hostname_and_path"],
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
if display_columns.include?("referrer_hostname") && display_columns.include?("referrer_path")
|
27
|
+
index = group_by_opts.index(["Referrer Hostname", "referrer_hostname"])
|
28
|
+
group_by_opts.insert(
|
29
|
+
index,
|
30
|
+
["Referrer Hostname and Path", "referrer_hostname_and_path"],
|
31
|
+
)
|
32
|
+
end
|
33
|
+
%>
|
2
34
|
|
3
35
|
<div class="well well-sm">
|
4
36
|
<%= form_tag url_for(params.except(:start_date, :to).to_unsafe_hash), method: "get", id: "search-form" do %>
|
5
37
|
<div>
|
6
|
-
<label style="margin-right: 10px;">Group By: <%= select_tag :group_by, options_for_select(
|
38
|
+
<label style="margin-right: 10px;">Group By: <%= select_tag :group_by, options_for_select(group_by_opts, params[:group_by]) %></label>
|
7
39
|
|
8
40
|
<label style="margin-right: 10px;">From: <%= date_field_tag :start_date, @start_date %></label>
|
9
41
|
<label style="margin-right: 10px;">To: <%= date_field_tag :end_date, @end_date %></label>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_local_analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weston Ganger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-html-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: database_cleaner
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|