Sha256: a5369390001fde226e3ab5607f9a5a4d8b4af1c292cbf13e1acde1e1996bf2dd

Contents?: true

Size: 924 Bytes

Versions: 6

Compression:

Stored size: 924 Bytes

Contents

# frozen_string_literal: true
# Called by the stats controller, it finds cached file pageview data,
# and prepares it for visualization in /app/views/stats/file.html.erb
module Hyrax
  class FileUsage < StatsUsagePresenter
    def initialize(id)
      self.model = ::FileSet.find(id)
    end

    alias file model

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

    def total_pageviews
      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

    private

    def downloads
      to_flots(FileDownloadStat.statistics(model, created, user_id))
    end

    def pageviews
      to_flots(FileViewStat.statistics(model, created, user_id))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hyrax-3.0.2 app/presenters/hyrax/file_usage.rb
hyrax-3.0.1 app/presenters/hyrax/file_usage.rb
hyrax-3.0.0 app/presenters/hyrax/file_usage.rb
hyrax-3.0.0.pre.rc4 app/presenters/hyrax/file_usage.rb
hyrax-3.0.0.pre.rc3 app/presenters/hyrax/file_usage.rb
hyrax-3.0.0.pre.rc2 app/presenters/hyrax/file_usage.rb