Sha256: 06529b6f05bd3f380920525b2bfda6bc407a6751b26a051c0130731237b20268

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

class FileUsage

  attr_accessor :id, :created, :path, :downloads, :pageviews

  def initialize id
    file = ::GenericFile.find(id)
    user = User.where(email: file.depositor).first
    user_id = user ? user.id : nil

    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(file.create_date)
    self.created = earliest > created ? earliest : created unless earliest.blank?
    self.downloads = FileDownloadStat.to_flots FileDownloadStat.statistics(id, created, user_id)
    self.pageviews = FileViewStat.to_flots FileViewStat.statistics(id, created, user_id)
  end

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

  def total_pageviews
    self.pageviews.reduce(0) { |total, result| total + result[1].to_i }
  end
  
  # Package data for visualization using JQuery Flot 
  def to_flot
    [
      { label: "Pageviews",  data: pageviews },
      { label: "Downloads",  data: downloads }
    ]
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
sufia-5.0.0 sufia-models/app/models/file_usage.rb
sufia-models-5.0.0 app/models/file_usage.rb
sufia-5.0.0.rc1 sufia-models/app/models/file_usage.rb
sufia-models-5.0.0.rc1 app/models/file_usage.rb
sufia-4.3.1 sufia-models/app/models/file_usage.rb
sufia-models-4.3.1 app/models/file_usage.rb