Class: SystemStats
- Inherits:
-
Object
- Object
- SystemStats
- Defined in:
- app/models/system_stats.rb
Overview
A class that retrieves system level statistics about the system
Instance Attribute Summary collapse
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#int ⇒ Object
readonly
limit limits the results returned from top_depositors and top_formats Default is 5, maximum is 20, minimum is 5.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
Instance Method Summary collapse
-
#document_by_permission ⇒ Hash
returns the total files in the system filtered by the start_date and end_date if present.
-
#initialize(limit_records = 5, start_date_str = nil, end_date_str = nil) ⇒ SystemStats
constructor
initialize the stats class setting the limitations.
-
#recent_users ⇒ Object
returns [Array<user>] a list (of size limit) of users most recently registered with the system.
-
#top_depositors ⇒ Hash
returns a list (of size limit) of system users (depositors) that have the most deposits in the system.
-
#top_formats ⇒ Hash
returns a list (of size limit) of file formats (mime_types) that have the most files in the system.
-
#users_count ⇒ Object
returns [Number] the number of currently registered users.
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_date ⇒ Object (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 |
#int ⇒ Object (readonly)
limit limits the results returned from top_depositors and top_formats Default is 5, maximum is 20, minimum is 5
9 10 11 |
# File 'app/models/system_stats.rb', line 9 def int @int end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
10 11 12 |
# File 'app/models/system_stats.rb', line 10 def limit @limit end |
#start_date ⇒ Object (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_permission ⇒ Hash
returns the total files in the system filtered by the start_date and end_date if present
33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/system_stats.rb', line 33 def return 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_users ⇒ Object
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_depositors ⇒ Hash
returns a list (of size limit) of system users (depositors) that have the most deposits in the system
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_formats ⇒ Hash
returns a list (of size limit) of file formats (mime_types) that have the most files in the system
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_count ⇒ Object
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 |