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)


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

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)


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

def by_depositor
  @by_depositor
end

#by_format#query

Returns:

  • (#query)


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

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

#depositor_summary#depositors

Returns:



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

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

#limitObject (readonly)

Returns the value of attribute limit.



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

def limit
  @limit
end

#stats_filtersObject (readonly)

Returns the value of attribute stats_filters.



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

def stats_filters
  @stats_filters
end

#system_stats#recent_users

Returns:



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

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

#works_counter#by_permission

Returns:

  • (#by_permission)


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

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

Instance Method Details

#active_usersObject



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

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

#date_filter_stringString

Returns:

  • (String)


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

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



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

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

#end_dateObject



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

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

#recent_usersObject



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

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



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

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

#top_formatsObject



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

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

#works_countObject



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

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