Class: Sufia::Statistic

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
ActionDispatch::Routing::PolymorphicRoutes
Defined in:
app/models/sufia/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/sufia/statistic.rb', line 15

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

.convert_date(date_time) ⇒ Object



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

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

.ga_statistics(start_date, object) ⇒ Object

Sufia::Download is sent to Sufia::Analytics.profile as #sufia__download see Legato::ProfileMethods.method_name_from_klass



33
34
35
36
# File 'app/models/sufia/statistic.rb', line 33

def ga_statistics(start_date, object)
  path = polymorphic_path(object)
  Sufia::Analytics.profile.sufia__pageview(sort: 'date', start_date: start_date).for_path(path)
end

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



27
28
29
# File 'app/models/sufia/statistic.rb', line 27

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/sufia/statistic.rb', line 11

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

.to_flots(stats) ⇒ Object



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

def to_flots(stats)
  stats.map(&:to_flot)
end

Instance Method Details

#to_flotObject



61
62
63
# File 'app/models/sufia/statistic.rb', line 61

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