rails_local_analytics 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ffdaa293f22790a92032f05322b5ceec16f7fa5ca6fe0d853f7ee2c22cb43a7
4
- data.tar.gz: 6d40a7a31467662aeda69cf7e2d6ad7f427c7cae14de922b70b8a0fc5003c7ce
3
+ metadata.gz: fbb7ca6534efc3666a302a04271092906ec9b2fc65a316d82b7811e2dd962668
4
+ data.tar.gz: 2cc17d06cf61d6b4b7fd2c559079965fa6c250b12d901b05a3317389e2d5b69d
5
5
  SHA512:
6
- metadata.gz: 5a3c7cd5cda651680348f9b6feaba06ca917e6b55380fc5b9ec26713391ead71dd89830b209435eff75a3021a624c93a82e69ae5a9173c05d3a4918646d014d7
7
- data.tar.gz: e1eda84eff2b599049bd837c69de93bfcf58614d31b9f437233f6a6e0ac881b0112746ea515275d5dac98b3de0d66ee13524f1038dfed0b33c24c02a003cf018
6
+ metadata.gz: 8d9e8dea022bb79486a8bc6395106841a4f9d056accf68f3534072bac1e205f40df426664ed071abd54715d38b0a00ef879aaa080b4a0a51f6ba3e31b207101e
7
+ data.tar.gz: e249aa1fb3f83ccaf75ffdb774192de6549889b8fb38b3537f5a99cc5edc6aab7da7d1b01caccb6012ffa4c4695739f2a15107ecbc49804db9e3e61c856ea13f
data/README.md CHANGED
@@ -138,6 +138,9 @@ Some examples of additional things you may want to track:
138
138
  * You may not need to store this in a new column, one example pattern could be to store this data in the existing `platform` database field
139
139
  - Country detection
140
140
  * Country detection is difficult. As such we dont try to include it by default.
141
+ * Consider using language detection instead
142
+ - Language detection
143
+ * You can gather the language from the `request.env["HTTP_ACCEPT_LANGUAGE"]` or `browser.accept_language.first.full`
141
144
  - Users or organizations
142
145
  * You may want to track your users or another model which is a core tenant to your particular application
143
146
 
@@ -2,6 +2,10 @@ body{
2
2
  padding-bottom: 20px;
3
3
  }
4
4
 
5
+ table td{
6
+ overflow-wrap: anywhere;
7
+ }
8
+
5
9
  input, select {
6
10
  border-radius: 5px;
7
11
  border: 1px solid #333;
@@ -18,7 +18,7 @@ module RailsLocalAnalytics
18
18
  end
19
19
 
20
20
  if params[:group_by].present? && !@klass.display_columns.include?(params[:group_by])
21
- params[:group_by] = nil
21
+ raise ArgumentError
22
22
  end
23
23
 
24
24
  if params[:start_date].present?
@@ -100,6 +100,16 @@ module RailsLocalAnalytics
100
100
  tracked_requests = tracked_requests
101
101
  .limit(PER_PAGE_LIMIT)
102
102
  .offset(PER_PAGE_LIMIT * (pagination_page_number-1))
103
+
104
+ if params[:filter].present?
105
+ col, val = params[:filter].split("==")
106
+
107
+ if @klass.display_columns.include?(col)
108
+ tracked_requests = tracked_requests.where(col => val)
109
+ else
110
+ raise ArgumentError
111
+ end
112
+ end
103
113
  end
104
114
 
105
115
  if where_conditions
@@ -1,31 +1,44 @@
1
1
  <% data_columns = params[:group_by].present? ? [params[:group_by]] : @klass.display_columns %>
2
2
 
3
- <%= form_tag url_for(params.except(:start_date, :to).to_unsafe_hash), method: "get", class: "well well-sm", id: "search-form" do %>
4
- <div>
5
- <label style="margin-right: 10px;">Group By: <%= select_tag :group_by, options_for_select([["All", nil]] + @klass.display_columns.map{|x| [x.titleize.sub("Url ", "URL "), x]} , params[:group_by]) %></label>
3
+ <div class="well well-sm">
4
+ <%= form_tag url_for(params.except(:start_date, :to).to_unsafe_hash), method: "get", id: "search-form" do %>
5
+ <div>
6
+ <label style="margin-right: 10px;">Group By: <%= select_tag :group_by, options_for_select([["All", nil]] + @klass.display_columns.map{|x| [x.titleize.sub("Url ", "URL "), x]} , params[:group_by]) %></label>
6
7
 
7
- <label style="margin-right: 10px;">From: <%= date_field_tag :start_date, @start_date %></label>
8
- <label style="margin-right: 10px;">To: <%= date_field_tag :end_date, @end_date %></label>
8
+ <label style="margin-right: 10px;">From: <%= date_field_tag :start_date, @start_date %></label>
9
+ <label style="margin-right: 10px;">To: <%= date_field_tag :end_date, @end_date %></label>
9
10
 
10
- <label style="margin-right: 10px;">Search: <%= text_field_tag :search, params[:search] %></label>
11
- </div>
11
+ <label style="margin-right: 10px;">Search: <%= text_field_tag :search, params[:search] %></label>
12
+ <% end %>
13
+
14
+ <% if params[:filter] %>
15
+ <div>
16
+ <label>Active Filter:</label>
17
+ <div class="badge badge-primary" style="margin-top: 5px; margin-bottom: 10px;">
18
+ <% filter_col, filter_val = params[:filter].split("==") %>
19
+ <%= filter_col.titleize.sub("Url ", "URL ") %> = "<%= filter_val %>"
20
+ </div>
21
+ <%= link_to "Remove Filter", url_for(params.to_unsafe_h.merge(filter: nil)) %>
22
+ </div>
23
+ <% end %>
12
24
 
13
25
  <div>
14
- <%= link_to "Today", url_for(params.merge(start_date: Date.today, end_date: Date.today).to_unsafe_hash) %>
26
+ <%= link_to "Today", url_for(params.merge(start_date: Date.today, end_date: Date.today).to_unsafe_hash), style: ("font-weight: bold;" if @start_date == Date.today && @end_date == Date.today) %>
15
27
  |
16
- <%= link_to "Yesterday", url_for(params.merge(start_date: (Date.today - 1.day), end_date: (Date.today - 1.day)).to_unsafe_hash) %>
28
+ <% yesterday = Date.today - 1.day %>
29
+ <%= link_to "Yesterday", url_for(params.merge(start_date: yesterday, end_date: yesterday).to_unsafe_hash), style: ("font-weight: bold;" if @start_date == yesterday && @end_date == yesterday) %>
17
30
  |
18
- <%= link_to "Last 7 days", url_for(params.merge(start_date: 7.days.ago.to_date, end_date: Date.today).to_unsafe_hash) %>
31
+ <%= link_to "Last 7 days", url_for(params.merge(start_date: 7.days.ago.to_date, end_date: Date.today).to_unsafe_hash), style: ("font-weight: bold;" if @start_date == 7.days.ago.to_date && @end_date == Date.today) %>
19
32
  |
20
- <%= link_to "Last 30 days", url_for(params.merge(start_date: 30.days.ago.to_date, end_date: Date.today).to_unsafe_hash) %>
33
+ <%= link_to "Last 30 days", url_for(params.merge(start_date: 30.days.ago.to_date, end_date: Date.today).to_unsafe_hash), style: ("font-weight: bold;" if @start_date == 30.days.ago.to_date && @end_date == Date.today) %>
21
34
  |
22
- <%= link_to "Last 3 Months", url_for(params.merge(start_date: 3.months.ago.to_date, end_date: Date.today).to_unsafe_hash) %>
35
+ <%= link_to "Last 3 Months", url_for(params.merge(start_date: 3.months.ago.to_date, end_date: Date.today).to_unsafe_hash), style: ("font-weight: bold;" if @start_date == 3.months.ago.to_date && @end_date == Date.today) %>
23
36
  |
24
- <%= link_to "Last 6 Months", url_for(params.merge(start_date: 6.months.ago.to_date, end_date: Date.today).to_unsafe_hash) %>
37
+ <%= link_to "Last 6 Months", url_for(params.merge(start_date: 6.months.ago.to_date, end_date: Date.today).to_unsafe_hash), style: ("font-weight: bold;" if @start_date == 6.months.ago.to_date && @end_date == Date.today) %>
25
38
  |
26
- <%= link_to "Last Year", url_for(params.merge(start_date: 1.year.ago.to_date, end_date: Date.today).to_unsafe_hash) %>
39
+ <%= link_to "Last Year", url_for(params.merge(start_date: 1.year.ago.to_date, end_date: Date.today).to_unsafe_hash), style: ("font-weight: bold;" if @start_date == 1.year.ago.to_date && @end_date == Date.today) %>
27
40
  </div>
28
- <% end %>
41
+ </div>
29
42
 
30
43
  <h2>Requests by <%= params[:type].titleize %></h2>
31
44
 
@@ -33,7 +46,7 @@
33
46
  <thead>
34
47
  <% data_columns.each do |header| %>
35
48
  <th>
36
- <%= header.sub("Url ", "URL ") %>
49
+ <%= header.titleize.sub("Url ", "URL ") %>
37
50
  </th>
38
51
  <% end %>
39
52
 
@@ -42,22 +55,23 @@
42
55
  </th>
43
56
 
44
57
  <th>
45
- Difference from previous period
58
+ Prev Period Difference
46
59
  </th>
47
60
  </thead>
48
61
 
49
62
  <tbody>
50
63
  <% @results.each_with_index do |row, row_index| %>
51
64
  <tr>
52
- <% row[0..-2].each do |value| %>
65
+ <% row[0..-2].each_with_index do |value, col_index| %>
53
66
  <td>
54
- <%= value %>
67
+ <% filter_param = "#{data_columns[col_index]}==#{value}" %>
68
+ <%= link_to (value || ""), url_for(params.to_unsafe_h.merge(filter: filter_param)), title: "Filter" %>
55
69
  </td>
56
70
  <% end %>
57
71
 
58
72
  <td>
59
73
  <% total = row.last %>
60
- <%= total.to_fs(:delimited) %>
74
+ <%= number_with_delimiter(total) %>
61
75
  </td>
62
76
 
63
77
  <td>
@@ -85,7 +99,7 @@
85
99
  <% prev_period_row_index = @prev_period_results.index{|prev_period_row| row[0..-2] == prev_period_row[0..-2] } %>
86
100
 
87
101
  <% if prev_period_row_index.nil? %>
88
- +<%= total.to_fs(:delimited) %>
102
+ +<%= number_with_delimiter(total) %>
89
103
  <% else %>
90
104
  <% prev_period_row = @prev_period_results.delete_at(prev_period_row_index) %>
91
105
 
@@ -93,9 +107,9 @@
93
107
  <% diff = total - prev_period_total %>
94
108
 
95
109
  <% if diff >= 0 %>
96
- +<%= diff.to_fs(:delimited) %>
110
+ +<%= number_with_delimiter(diff) %>
97
111
  <% else %>
98
- <%= diff.to_fs(:delimited) %>
112
+ <%= number_with_delimiter(diff) %>
99
113
  <% end %>
100
114
  <% end %>
101
115
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module RailsLocalAnalytics
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
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.0
4
+ version: 0.2.1
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-04 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -97,7 +97,6 @@ files:
97
97
  - app/controllers/rails_local_analytics/dashboard_controller.rb
98
98
  - app/jobs/rails_local_analytics/application_job.rb
99
99
  - app/jobs/rails_local_analytics/record_request_job.rb
100
- - app/lib/rails_local_analytics/histogram.rb
101
100
  - app/models/rails_local_analytics/application_record.rb
102
101
  - app/models/tracked_requests_by_day_page.rb
103
102
  - app/models/tracked_requests_by_day_site.rb
@@ -1,47 +0,0 @@
1
- module RailsLocalAnalytics
2
- class Histogram
3
- attr_reader :bars, :from_date, :to_date
4
-
5
- def initialize(scope, from_date, to_date)
6
- @scope = scope
7
- @from_date, @to_date = from_date, to_date
8
- @bars = scope.map { |record| Bar.new(record.date, record.total, self) }
9
- fill_missing_days(@bars, @from_date, @to_date)
10
- end
11
-
12
- def fill_missing_days(bars, from, to)
13
- i = 0
14
- while (day = from + i) <= to
15
- if !@bars[i] || @bars[i].label != day
16
- @bars.insert(i, Bar.new(day, 0, self))
17
- end
18
- i += 1
19
- end
20
- @bars
21
- end
22
-
23
- def max_value
24
- @max_total ||= bars.map(&:value).max
25
- end
26
-
27
- def total
28
- @bars.reduce(0) { |sum, bar| sum += bar.value }
29
- end
30
-
31
- class Bar
32
- attr_reader :label, :value, :histogram
33
-
34
- def initialize(label, value, histogram)
35
- @label, @value, @histogram = label, value, histogram
36
- end
37
-
38
- def height
39
- if histogram.max_value > 0
40
- (value.to_f / histogram.max_value).round(2)
41
- else
42
- 0
43
- end
44
- end
45
- end
46
- end
47
- end