Class: Analytics::VisitorService
- Inherits:
-
Lesli::ApplicationLesliService
- Object
- Lesli::ApplicationLesliService
- Analytics::VisitorService
- Defined in:
- app/services/lesli_audit/analytics/visitor_service.rb
Constant Summary collapse
- LIMIT =
5
Instance Method Summary collapse
- #controllers ⇒ Object
- #devices ⇒ Object
- #users ⇒ Object
-
#visits ⇒ Hash
Paginated list of the records.
Instance Method Details
#controllers ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/services/lesli_audit/analytics/visitor_service.rb', line 122 def controllers requests = Lesli::User::Request.where(lesli_user: current_user.account.users).group("request_controller") requests = apply_filters(requests, query) requests = requests.limit(LIMIT).order("requests DESC").select( :request_controller, "sum(request_count) requests" ) return requests end |
#devices ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/services/lesli_audit/analytics/visitor_service.rb', line 109 def devices agents = ::User::Agent.where(user: current_user.account.users) agents = agents.group("platform", "browser") agents = agents.limit(LIMIT).order(sum_count: :desc).sum(:count).map do |req| { :device => req[0].join("/"), :visits => req[1] } end return agents end |
#users ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/services/lesli_audit/analytics/visitor_service.rb', line 86 def users requests = ::User::Request .joins(:user) .where(user: current_user.account.users) .group(:email) requests = apply_filters(requests, query) requests = requests.limit(LIMIT).order("requests DESC").select( :email, "count(user_requests.id) resources", "sum(user_requests.request_count) requests" ).map do |request| { :requests => request[:requests], :resources => request[:resources], :email => request[:email] } end return requests end |
#visits ⇒ Hash
Returns Paginated list of the records.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/services/lesli_audit/analytics/visitor_service.rb', line 43 def visits return Lesli::User::Request .group("DATE_TRUNC('day', created_at)").limit(30) .order("date DESC") .limit(30) .select( "count(id) resources", "sum(request_count) requests", "DATE_TRUNC('day', created_at) date" ).map do |request| { :requests => request[:requests], :resources => request[:resources], :date => Date2.new(request[:date]).date.to_s } end group = 'day' #group = params[:bygroup] if ['month','week','day'].include?(params[:bygroup]) # only the users of the account usrs = current_user.account.users requests = ::User::Request.where(user: usrs).group("DATE_TRUNC('month', created_at)") if group == 'month' requests = ::User::Request.where(user: usrs).group("DATE_TRUNC('week', created_at)") if group == 'week' requests = ::User::Request.where(user: usrs).group("DATE_TRUNC('day', created_at)") if group == 'day' requests = apply_filters(requests, query) requests.limit(30).order("date DESC").select( "count(id) resources", "sum(request_count) requests", "DATE_TRUNC('day', created_at) date" ).map do |request| { :requests => request[:requests], :resources => request[:resources], :date => Date2.new(request[:date]).date.to_s } end end |