Class: Hyrax::AdminStatsPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/hyrax/admin_stats_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stats_filters, limit, by_depositor: Hyrax::Statistics::Works::ByDepositor, by_format: Hyrax::Statistics::FileSets::ByFormat, depositor_summary: Hyrax::Statistics::Depositors::Summary, system_stats: Hyrax::Statistics::SystemStats, works_counter: Hyrax::Statistics::Works::Count) ⇒ AdminStatsPresenter

Returns a new instance of AdminStatsPresenter.

Parameters:

  • stats_filters (Hash<Symbol, Object>)
  • limit (FixNum)
  • by_depositor (#query) (defaults to: Hyrax::Statistics::Works::ByDepositor)
  • by_format (#query) (defaults to: Hyrax::Statistics::FileSets::ByFormat)
  • depositor_summary (#depositors) (defaults to: Hyrax::Statistics::Depositors::Summary)
  • system_stats (#recent_users) (defaults to: Hyrax::Statistics::SystemStats)
  • works_counter (#by_permission) (defaults to: Hyrax::Statistics::Works::Count)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 33

def initialize(stats_filters, limit,
               by_depositor:      Hyrax::Statistics::Works::ByDepositor,
               by_format:         Hyrax::Statistics::FileSets::ByFormat,
               depositor_summary: Hyrax::Statistics::Depositors::Summary,
               system_stats:      Hyrax::Statistics::SystemStats,
               works_counter:     Hyrax::Statistics::Works::Count)
  @stats_filters = stats_filters
  @limit = limit

  self.by_depositor      = by_depositor
  self.by_format         = by_format
  self.depositor_summary = depositor_summary
  self.system_stats      = system_stats
  self.works_counter     = works_counter
end

Instance Attribute Details

#by_depositor#query

Returns:

  • (#query)


17
18
19
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 17

def by_depositor
  @by_depositor
end

#by_format#query

Returns:

  • (#query)


17
18
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 17

attr_accessor :by_depositor, :by_format, :depositor_summary, :system_stats,
:works_counter

#depositor_summary#depositors

Returns:



17
18
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 17

attr_accessor :by_depositor, :by_format, :depositor_summary, :system_stats,
:works_counter

#limitObject (readonly)

Returns the value of attribute limit.



4
5
6
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 4

def limit
  @limit
end

#stats_filtersObject (readonly)

Returns the value of attribute stats_filters.



4
5
6
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 4

def stats_filters
  @stats_filters
end

#system_stats#recent_users

Returns:



17
18
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 17

attr_accessor :by_depositor, :by_format, :depositor_summary, :system_stats,
:works_counter

#works_counter#by_permission

Returns:

  • (#by_permission)


17
18
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 17

attr_accessor :by_depositor, :by_format, :depositor_summary, :system_stats,
:works_counter

Instance Method Details

#active_usersObject



82
83
84
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 82

def active_users
  @active_users ||= by_depositor.query(limit: limit)
end

#date_filter_stringString

Returns:

  • (String)


99
100
101
102
103
104
105
106
107
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 99

def date_filter_string
  if start_date.blank?
    "unfiltered"
  elsif end_date.blank?
    "#{start_date.to_date.to_formatted_s(:standard)} to #{Date.current.to_formatted_s(:standard)}"
  else
    "#{start_date.to_date.to_formatted_s(:standard)} to #{end_date.to_date.to_formatted_s(:standard)}"
  end
end

#depositorsObject



68
69
70
71
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 68

def depositors
  @depositors ||=
    depositor_summary.depositors(start_date: start_date, end_date: end_date)
end

#end_dateObject



54
55
56
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 54

def end_date
  @end_date ||= extract_date_from_stats_filters(key: :end_date, as_of: :end_of_day)
end

#recent_usersObject



74
75
76
77
78
79
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 74

def recent_users
  @recent_users ||=
    system_stats.recent_users(limit: limit,
                              start_date: start_date,
                              end_date: end_date)
end

#start_dateObject

rubocop:enable Metrics/ParameterLists



50
51
52
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 50

def start_date
  @start_date ||= extract_date_from_stats_filters(key: :start_date, as_of: :beginning_of_day)
end

#top_formatsObject



87
88
89
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 87

def top_formats
  @top_formats ||= by_format.query(limit: limit)
end

#works_countObject



92
93
94
95
# File 'app/presenters/hyrax/admin_stats_presenter.rb', line 92

def works_count
  @works_count ||=
    works_counter.by_permission(start_date: start_date, end_date: end_date)
end