Class: SystemStats

Inherits:
Object
  • Object
show all
Defined in:
app/models/system_stats.rb

Overview

A class that retrieves system level statistics about the system

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit_records = 5, start_date_str = nil, end_date_str = nil) ⇒ SystemStats

initialize the stats class setting the limitations



20
21
22
23
24
# File 'app/models/system_stats.rb', line 20

def initialize(limit_records = 5, start_date_str = nil, end_date_str = nil)
  @limit = validate_limit(limit_records)
  @start_date = DateTime.parse(start_date_str) unless start_date_str.blank?
  @end_date = DateTime.parse(end_date_str).end_of_day unless end_date_str.blank?
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



10
11
12
# File 'app/models/system_stats.rb', line 10

def end_date
  @end_date
end

#intObject (readonly)

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

Returns:

  • (Object)

    the current value of int



9
10
11
# File 'app/models/system_stats.rb', line 9

def int
  @int
end

#limitObject (readonly)

Returns the value of attribute limit.



10
11
12
# File 'app/models/system_stats.rb', line 10

def limit
  @limit
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



10
11
12
# File 'app/models/system_stats.rb', line 10

def start_date
  @start_date
end

Instance Method Details

#document_by_permissionHash

returns the total files in the system filtered by the start_date and end_date if present

Parameters:

  • [Number] (Hash)

    a customizable set of options

Returns:

  • (Hash)

    A hash with the total files by permission for the system



33
34
35
36
37
38
39
40
41
42
# File 'app/models/system_stats.rb', line 33

def document_by_permission
  return document_by_date_by_permission if start_date

  files_count = {}
  files_count[:total] = ::GenericFile.count
  files_count[:public] = ::GenericFile.where_public.count
  files_count[:registered] = ::GenericFile.where_registered.count
  files_count[:private] = files_count[:total] - (files_count[:registered] + files_count[:public])
  files_count
end

#recent_usersObject

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



62
63
64
65
66
67
# File 'app/models/system_stats.rb', line 62

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 … }



47
48
49
50
# File 'app/models/system_stats.rb', line 47

def top_depositors
  depositor_key = Solrizer.solr_name('depositor', :stored_searchable, type: :string)
  top_data(depositor_key, limit)
end

#top_formatsHash

returns a list (of size limit) of file formats (mime_types) that have the most files in the system

Returns:

  • (Hash)

    a hash with the file format as the key and the number of files as the value { ‘png’ => 25, ‘pdf’ => 24 … }



55
56
57
58
# File 'app/models/system_stats.rb', line 55

def top_formats
  format_key = Solrizer.solr_name('file_format', Solrizer::Descriptor.new(:string, :indexed, :multivalued))
  top_data(format_key, limit)
end

#users_countObject

returns [Number] the number of currently registered users



71
72
73
# File 'app/models/system_stats.rb', line 71

def users_count
  ::User.count
end