Class: Hyrax::Analytics::Results

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/analytics/results.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#resultsObject

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

#allObject


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

#listObject


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_csvObject


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_flotObject


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