Class: LesliAudit::AnalyticService
- Inherits:
-
Lesli::ApplicationLesliService
- Object
- Lesli::ApplicationLesliService
- LesliAudit::AnalyticService
- Defined in:
- app/services/lesli_audit/analytic_service.rb
Constant Summary collapse
- LIMIT =
5
Instance Method Summary collapse
- #controllers ⇒ Object
- #users ⇒ Object
-
#visitors ⇒ Hash
Paginated list of the records.
Instance Method Details
#controllers ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/services/lesli_audit/analytic_service.rb', line 78 def controllers requests = current_user.account.audit.account_requests .group("request_controller").limit(30) requests = apply_filters(requests, query) requests = requests.limit(LIMIT).order("requests DESC").select( :request_controller, "sum(request_count) requests" ) end |
#users ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/services/lesli_audit/analytic_service.rb', line 66 def users current_user.account.audit.user_requests .joins(:user) .group(:email) .limit(LIMIT).order("requests DESC").select( :email, "count(lesli_audit_user_requests.id) resources", "sum(lesli_audit_user_requests.request_count) requests" ) end |
#visitors ⇒ 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 |
# File 'app/services/lesli_audit/analytic_service.rb', line 43 def visitors group = 'day' #group = params[:bygroup] if ['month','week','day'].include?(params[:bygroup]) # only the users of the account usrs = current_user.account.users requests = current_user.account.audit.account_requests requests = requests.group("DATE_TRUNC('month', created_at)") if group == 'month' requests = requests.group("DATE_TRUNC('week', created_at)") if group == 'week' requests = requests.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" ) end |