Class: LesliAudit::AnalyticService

Inherits:
Lesli::ApplicationLesliService
  • Object
show all
Defined in:
app/services/lesli_audit/analytic_service.rb

Constant Summary collapse

LIMIT =
5

Instance Method Summary collapse

Instance Method Details

#controllersObject



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..audit.
    .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

#usersObject



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..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

#visitorsHash

Returns Paginated list of the records.

Parameters:

  • Has (query)

    of the formated queries/filters that will be applied to filter data

Returns:

  • (Hash)

    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..users


    requests = current_user..audit.
    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