Class: Hyrax::Analytics::Results
- Inherits:
-
Object
- Object
- Hyrax::Analytics::Results
- Defined in:
- app/services/hyrax/analytics/results.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
- #all ⇒ Object
- #day(date = Time.zone.today) ⇒ Object
-
#initialize(results) ⇒ Results
constructor
A new instance of Results.
- #list ⇒ Object
- #month(date = Time.zone.today) ⇒ Object
- #range(start_date = Time.zone.today - 1.month, end_date = Time.zone.today) ⇒ Object
- #to_csv ⇒ Object
- #to_flot ⇒ Object
- #week(date = Time.zone.today) ⇒ Object
- #year(date = Time.zone.today) ⇒ Object
Constructor Details
#initialize(results) ⇒ Results
Returns a new instance of Results.
9 10 11 |
# File 'app/services/hyrax/analytics/results.rb', line 9 def initialize(results) @results ||= results end |
Instance Attribute Details
#results ⇒ Object
Returns the value of attribute results.
7 8 9 |
# File 'app/services/hyrax/analytics/results.rb', line 7 def results @results end |
Instance Method Details
#all ⇒ Object
13 14 15 |
# File 'app/services/hyrax/analytics/results.rb', line 13 def all results.inject(0) { |sum, a| sum + a[1] } end |
#day(date = Time.zone.today) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/services/hyrax/analytics/results.rb', line 17 def day(date = Time.zone.today) start_date = date.at_beginning_of_day end_date = date.at_end_of_day range_results = [] results.each do |result| range_results.push(result) if (start_date..end_date).cover?(result[0]) end range_results.inject(0) { |sum, a| sum + a[1] } end |
#list ⇒ Object
69 70 71 |
# File 'app/services/hyrax/analytics/results.rb', line 69 def list results.inject([]) { |line, row| line << row }.reverse end |
#month(date = Time.zone.today) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/services/hyrax/analytics/results.rb', line 37 def month(date = Time.zone.today) start_date = date.at_beginning_of_month end_date = date.at_end_of_month range_results = [] results.each do |result| range_results.push(result) if (start_date..end_date).cover?(result[0]) end range_results.inject(0) { |sum, a| sum + a[1] } end |
#range(start_date = Time.zone.today - 1.month, end_date = Time.zone.today) ⇒ Object
57 58 59 60 61 62 63 |
# File 'app/services/hyrax/analytics/results.rb', line 57 def range(start_date = Time.zone.today - 1.month, end_date = Time.zone.today) range_results = [] results.each do |result| range_results.push(result) if (start_date..end_date).cover?(result[0]) end range_results.inject(0) { |sum, a| sum + a[1] } end |
#to_csv ⇒ Object
65 66 67 |
# File 'app/services/hyrax/analytics/results.rb', line 65 def to_csv results.inject([]) { |csv, row| csv << CSV.generate_line(row) }.join("") end |
#to_flot ⇒ Object
73 74 75 76 |
# File 'app/services/hyrax/analytics/results.rb', line 73 def to_flot fields = [:date, :pageviews] results.map { |row| fields.zip(row).to_h } end |
#week(date = Time.zone.today) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/services/hyrax/analytics/results.rb', line 27 def week(date = Time.zone.today) start_date = date.at_beginning_of_week end_date = date.at_end_of_week range_results = [] results.each do |result| range_results.push(result) if (start_date..end_date).cover?(result[0]) end range_results.inject(0) { |sum, a| sum + a[1] } end |
#year(date = Time.zone.today) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/services/hyrax/analytics/results.rb', line 47 def year(date = Time.zone.today) start_date = date.at_beginning_of_year end_date = date.at_end_of_year range_results = [] results.each do |result| range_results.push(result) if (start_date..end_date).cover?(result[0]) end range_results.inject(0) { |sum, a| sum + a[1] } end |