Class: Hyrax::Statistics::SystemStats

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/statistics/system_stats.rb

Overview

A class that retrieves system level statistics about the system TODO: this class could be refactored into several classes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit_records = 5, start_date = nil, end_date = nil) ⇒ SystemStats

Returns a new instance of SystemStats.

Parameters:

  • limit_records (Fixnum) (defaults to: 5)

    limits the results returned from top_depositors and top_formats. Maximum is 20, minimum is 5

  • start_date (Time) (defaults to: nil)

    Filters the statistics returned by the class to after this date. nil means no filter

  • end_date (Time) (defaults to: nil)

    Filters the statistics returned by the class to before this date. nil means today



27
28
29
30
31
# File 'app/services/hyrax/statistics/system_stats.rb', line 27

def initialize(limit_records = 5, start_date = nil, end_date = nil)
  @limit = validate_limit(limit_records)
  @start_date = start_date
  @end_date = end_date
end

Instance Attribute Details

#end_dateTime (readonly)

Filters the statistics returned by the class to before end date nil means today

Returns:

  • (Time)

    the current value of end_date



12
13
14
# File 'app/services/hyrax/statistics/system_stats.rb', line 12

def end_date
  @end_date
end

#limitInteger (readonly)

limits the results returned from top_depositors and top_formats Default is 5, maximum is 20, minimum is 5

Returns:

  • (Integer)

    the current value of limit



12
13
14
# File 'app/services/hyrax/statistics/system_stats.rb', line 12

def limit
  @limit
end

#start_dateTime (readonly)

Filters the statistics returned by the class to after the start date nil means no filter

Returns:

  • (Time)

    the current value of start_date



12
13
14
# File 'app/services/hyrax/statistics/system_stats.rb', line 12

def start_date
  @start_date
end

Class Method Details

.recent_users(limit: 5, start_date: nil, end_date: nil) ⇒ Array<User>

Parameters:

  • limit_records (Fixnum)

    limits the results returned from top_depositors and top_formats. Maximum is 20, minimum is 5

  • start_date (Time) (defaults to: nil)

    Filters the statistics returned by the class to after this date. nil means no filter

  • end_date (Time) (defaults to: nil)

    Filters the statistics returned by the class to before this date. nil means today

Returns:



20
21
22
# File 'app/services/hyrax/statistics/system_stats.rb', line 20

def self.recent_users(limit: 5, start_date: nil, end_date: nil)
  new(limit, start_date, end_date).recent_users
end

Instance Method Details

#recent_usersObject

returns [Array<user>] a list (of size limit) of users most recently registered with the system



44
45
46
47
48
49
# File 'app/services/hyrax/statistics/system_stats.rb', line 44

def recent_users
  # no dates return the top few based on limit
  return ::User.order('created_at DESC').limit(limit) if start_date.blank?

  ::User.recent_users start_date, end_date
end

#top_depositorsHash

returns a list (of size limit) of system users (depositors) that have the most deposits in the system

Returns:

  • (Hash)

    a hash with the user name as the key and the number of deposits as the value { ‘cam156’ => 25, ‘hjc14’ => 24 … }



36
37
38
# File 'app/services/hyrax/statistics/system_stats.rb', line 36

def top_depositors
  TermQuery.new(limit).results(depositor_field)
end