rails_server_analytics 0.1.0 → 0.1.1

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: ceecf3d520444f52ee03e83e013c11c051060c8f7aa68a6f51daade9f4ac7d32
4
- data.tar.gz: aba1fbf7819d6b292a9900ee29cd1d162b96057aa4d88ccf3bbfe4c9aed13252
3
+ metadata.gz: d4cf58448dd0c85fe840e2261ceaf35d3ddd1a99141a70f16891ba6e0dcc46fe
4
+ data.tar.gz: 18f97b3624a472f957466d4313f875d3ab2e3e9a6d8098ab420a7dac270f2c6a
5
5
  SHA512:
6
- metadata.gz: 0663736f3c8feb23bdae41ec480b2342a521e183deae4da9e4de7d6d8bcea711485cafb5c55e8f48e3d81e04c21f8ebe310fc46625b9341149832dfa05365958
7
- data.tar.gz: '092920b9405f6d39516a267c6001d33aed1c93b598e3c7908a7d9a41baaa34db0ebc2e2356fbcd1a5365285e0be546c190b4f20f6cdca128f2c679cd83903749'
6
+ metadata.gz: f28602990dc8c0d9b2f5bf43bb56ffcf468e6dafd67b56cbfd00fbb57aa775d22fd4f762f2858f095bb1ac72eed821d6ae60964f52bdc63ddc17800c285985db
7
+ data.tar.gz: 22fc488ca4e4cf21e5e1e64b890a274419f9cbd02b3b9bd0728f56b3f5ba88810a24fb4495d7c1567244d8f4db97109ca175c9a62a16a78417eb675f71410502
@@ -16,7 +16,7 @@ class AnalyticsController < ApplicationController
16
16
  end
17
17
 
18
18
  def process_raw_analytics
19
- request_count = @analytics.count
19
+ @request_count = @analytics.count
20
20
  total_request_per_day = @analytics.where(updated_at: (Time.now - 1.day)..Time.now).pluck(:updated_at).count
21
21
 
22
22
  average_response_time = get_average("time_spent")
@@ -31,7 +31,7 @@ class AnalyticsController < ApplicationController
31
31
 
32
32
  @analytics_json = {
33
33
  analytics: @analytics,
34
- request_count: request_count,
34
+ request_count: @request_count,
35
35
  total_request_per_day: total_request_per_day,
36
36
  average_response_time: average_response_time,
37
37
  most_frequent_request: most_frequent_request,
@@ -45,6 +45,8 @@ class AnalyticsController < ApplicationController
45
45
  end
46
46
 
47
47
  def get_most_frequent(data)
48
+ return "None" if no_request
49
+
48
50
  all_request = @analytics.map(&:analytics_data).pluck(data)
49
51
  all_request.detect { |r| all_request.count(r) > 1 }
50
52
 
@@ -53,7 +55,13 @@ class AnalyticsController < ApplicationController
53
55
  end
54
56
 
55
57
  def get_average(data)
58
+ return 0.00 if no_request
59
+
56
60
  all_data = @analytics.map(&:analytics_data).pluck(data)
57
61
  (all_data.sum / @analytics.count).truncate(3)
58
62
  end
63
+
64
+ def no_request
65
+ @request_count == 0
66
+ end
59
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsServerAnalytics
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_server_analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chong Wei Jie