Module: Hyrax::Analytics::Google::EventsDaily

Extended by:
Legato::Model
Defined in:
app/services/hyrax/analytics/google/events_daily.rb

Class Method Summary collapse

Class Method Details

.by_id(profile, start_date, end_date, id, action) ⇒ Object

returns a daily number of events for a specific action



34
35
36
37
38
39
40
41
# File 'app/services/hyrax/analytics/google/events_daily.rb', line 34

def self.by_id(profile, start_date, end_date, id, action)
  action = action.underscore
  response = EventsDaily.results(profile,
    start_date: start_date,
    end_date: end_date).for_id(id).send(action)
  dates = (start_date.to_date...end_date.to_date)
  results_array(response, dates)
end

.results_array(response, dates) ⇒ Object

takes all the dates in between the date range and generate an array [date, totalEvents]



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/services/hyrax/analytics/google/events_daily.rb', line 53

def self.results_array(response, dates)
  results = []
  response.to_a.each do |result|
    results.push([result.date.to_date, result.totalEvents.to_i])
  end
  new_results = []
  dates.each do |date|
    match = results.detect { |a, _b| a == date }
    if match
      new_results.push(match)
    else
      new_results.push([date, 0])
    end
  end
  Hyrax::Analytics::Results.new(new_results)
end

.summary(profile, start_date, end_date, action) ⇒ Object

returns a daily number of events for a specific action



24
25
26
27
28
29
30
31
# File 'app/services/hyrax/analytics/google/events_daily.rb', line 24

def self.summary(profile, start_date, end_date, action)
  action = action.underscore
  response = EventsDaily.results(profile,
    start_date: start_date,
    end_date: end_date).send(action)
  dates = (start_date.to_date...end_date.to_date)
  results_array(response, dates)
end