Class: FileUsage

Inherits:
Object
  • Object
show all
Defined in:
app/models/file_usage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ FileUsage

Returns a new instance of FileUsage.



5
6
7
8
9
10
11
12
13
# File 'app/models/file_usage.rb', line 5

def initialize id
  self.id = id
  self.path = Sufia::Engine.routes.url_helpers.generic_file_path(Sufia::Noid.noidify(id))
  earliest = Sufia.config.analytic_start_date
  self.created = DateTime.parse(::GenericFile.find(id).create_date)
  self.created = earliest > created ? earliest : created unless earliest.blank?
  self.downloads = FileDownloadStat.to_flots FileDownloadStat.statistics(id, created)
  self.pageviews = FileViewStat.to_flots FileViewStat.statistics(id, created)
end

Instance Attribute Details

#createdObject

Returns the value of attribute created.



3
4
5
# File 'app/models/file_usage.rb', line 3

def created
  @created
end

#downloadsObject

Returns the value of attribute downloads.



3
4
5
# File 'app/models/file_usage.rb', line 3

def downloads
  @downloads
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'app/models/file_usage.rb', line 3

def id
  @id
end

#pageviewsObject

Returns the value of attribute pageviews.



3
4
5
# File 'app/models/file_usage.rb', line 3

def pageviews
  @pageviews
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'app/models/file_usage.rb', line 3

def path
  @path
end

Instance Method Details

#to_flotObject

Package data for visualization using JQuery Flot



24
25
26
27
28
29
# File 'app/models/file_usage.rb', line 24

def to_flot
  [
    { label: "Pageviews",  data: pageviews },
    { label: "Downloads",  data: downloads }
  ]
end

#total_downloadsObject



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

def total_downloads
  self.downloads.reduce(0) { |total, result| total + result[1].to_i }
end

#total_pageviewsObject



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

def total_pageviews
  self.pageviews.reduce(0) { |total, result| total + result[1].to_i }
end