Sha256: 1c985a7a90d7654c4bda12101e2270db31a56826c77601a1a6a2dfac882ab668

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 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(id)
    earliest = Sufia.config.analytic_start_date
    self.created = ::GenericFile.find(id).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-models-6.0.0 app/models/file_usage.rb
sufia-6.0.0 sufia-models/app/models/file_usage.rb
sufia-6.0.0.rc4 sufia-models/app/models/file_usage.rb
sufia-models-6.0.0.rc4 app/models/file_usage.rb
sufia-6.0.0.rc3 sufia-models/app/models/file_usage.rb
sufia-models-6.0.0.rc3 app/models/file_usage.rb