Class: Sufia::Statistics::SystemStats
- Inherits:
-
Object
- Object
- Sufia::Statistics::SystemStats
- Defined in:
- app/services/sufia/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
-
#end_date ⇒ Time
readonly
Filters the statistics returned by the class to before end date nil means today.
-
#limit ⇒ Integer
readonly
limits the results returned from top_depositors and top_formats Default is 5, maximum is 20, minimum is 5.
-
#start_date ⇒ Time
readonly
Filters the statistics returned by the class to after the start date nil means no filter.
Instance Method Summary collapse
-
#initialize(limit_records = 5, start_date = nil, end_date = nil) ⇒ SystemStats
constructor
A new instance of SystemStats.
-
#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.
Constructor Details
#initialize(limit_records = 5, start_date = nil, end_date = nil) ⇒ SystemStats
Returns a new instance of SystemStats.
18 19 20 21 22 |
# File 'app/services/sufia/statistics/system_stats.rb', line 18 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_date ⇒ Time (readonly)
Filters the statistics returned by the class to before end date nil means today
12 13 14 |
# File 'app/services/sufia/statistics/system_stats.rb', line 12 def end_date @end_date end |
#limit ⇒ Integer (readonly)
limits the results returned from top_depositors and top_formats Default is 5, maximum is 20, minimum is 5
12 13 14 |
# File 'app/services/sufia/statistics/system_stats.rb', line 12 def limit @limit end |
#start_date ⇒ Time (readonly)
Filters the statistics returned by the class to after the start date nil means no filter
12 13 14 |
# File 'app/services/sufia/statistics/system_stats.rb', line 12 def start_date @start_date end |
Instance Method Details
#recent_users ⇒ Object
returns [Array<user>] a list (of size limit) of users most recently registered with the system
35 36 37 38 39 40 |
# File 'app/services/sufia/statistics/system_stats.rb', line 35 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
27 28 29 |
# File 'app/services/sufia/statistics/system_stats.rb', line 27 def top_depositors TermQuery.new(limit).results(depositor_field) end |