Class: FileUsage
- Inherits:
-
Object
- Object
- FileUsage
- Defined in:
- app/models/file_usage.rb
Instance Attribute Summary collapse
-
#created ⇒ Object
Returns the value of attribute created.
-
#downloads ⇒ Object
Returns the value of attribute downloads.
-
#id ⇒ Object
Returns the value of attribute id.
-
#pageviews ⇒ Object
Returns the value of attribute pageviews.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(id) ⇒ FileUsage
constructor
A new instance of FileUsage.
-
#to_flot ⇒ Object
Package data for visualization using JQuery Flot.
- #total_downloads ⇒ Object
- #total_pageviews ⇒ Object
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
#created ⇒ Object
Returns the value of attribute created.
3 4 5 |
# File 'app/models/file_usage.rb', line 3 def created @created end |
#downloads ⇒ Object
Returns the value of attribute downloads.
3 4 5 |
# File 'app/models/file_usage.rb', line 3 def downloads @downloads end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'app/models/file_usage.rb', line 3 def id @id end |
#pageviews ⇒ Object
Returns the value of attribute pageviews.
3 4 5 |
# File 'app/models/file_usage.rb', line 3 def pageviews @pageviews end |
#path ⇒ Object
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_flot ⇒ Object
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_downloads ⇒ Object
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_pageviews ⇒ Object
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 |