Class: Hyrax::Statistic

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
ActionDispatch::Routing::PolymorphicRoutes
Defined in:
app/models/hyrax/statistic.rb

Direct Known Subclasses

FileDownloadStat, FileViewStat, WorkViewStat

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_for(object, attrs) ⇒ Object



15
16
17
# File 'app/models/hyrax/statistic.rb', line 15

def build_for(object, attrs)
  new attrs.merge(filter(object))
end

.convert_date(date_time) ⇒ Object



19
20
21
# File 'app/models/hyrax/statistic.rb', line 19

def convert_date(date_time)
  date_time.to_datetime.to_i * 1000
end

.ga_statistics(start_date, object) ⇒ Object

Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download see Legato::ProfileMethods.method_name_from_klass



29
30
31
32
33
34
35
36
37
# File 'app/models/hyrax/statistic.rb', line 29

def ga_statistics(start_date, object)
  path = polymorphic_path(object)
  profile = Hyrax::Analytics.profile
  unless profile
    Rails.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.")
    return []
  end
  profile.hyrax__pageview(sort: 'date', start_date: start_date).for_path(path)
end

.statistics(object, start_date, user_id = nil) ⇒ Object



23
24
25
# File 'app/models/hyrax/statistic.rb', line 23

def statistics(object, start_date, user_id = nil)
  combined_stats object, start_date, cache_column, event_type, user_id
end

.statistics_for(object) ⇒ Object



11
12
13
# File 'app/models/hyrax/statistic.rb', line 11

def statistics_for(object)
  where(filter(object))
end

Instance Method Details

#to_flotObject



62
63
64
# File 'app/models/hyrax/statistic.rb', line 62

def to_flot
  [self.class.convert_date(date), send(cache_column)]
end