Sha256: deac2f27317116f566e692b5cf2a99a97eca3b9cf5efc92e31058fd0e61bb414

Contents?: true

Size: 933 Bytes

Versions: 19

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true
module Hyrax
  ##
  # Called by the stats controller, it finds cached file pageview data,
  # and prepares it for visualization in /app/views/stats/file.html.erb
  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

19 entries across 19 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/presenters/hyrax/file_usage.rb
hyrax-5.0.0 app/presenters/hyrax/file_usage.rb
hyrax-5.0.0.rc3 app/presenters/hyrax/file_usage.rb
hyrax-5.0.0.rc2 app/presenters/hyrax/file_usage.rb
hyrax-5.0.0.rc1 app/presenters/hyrax/file_usage.rb
hyrax-3.6.0 app/presenters/hyrax/file_usage.rb
hyrax-4.0.0 app/presenters/hyrax/file_usage.rb
hyrax-4.0.0.rc3 app/presenters/hyrax/file_usage.rb
hyrax-4.0.0.rc2 app/presenters/hyrax/file_usage.rb
hyrax-4.0.0.rc1 app/presenters/hyrax/file_usage.rb
hyrax-3.5.0 app/presenters/hyrax/file_usage.rb
hyrax-4.0.0.beta2 app/presenters/hyrax/file_usage.rb
hyrax-3.4.2 app/presenters/hyrax/file_usage.rb
hyrax-4.0.0.beta1 app/presenters/hyrax/file_usage.rb
hyrax-3.4.1 app/presenters/hyrax/file_usage.rb
hyrax-3.4.0 app/presenters/hyrax/file_usage.rb
hyrax-3.3.0 app/presenters/hyrax/file_usage.rb
hyrax-3.2.0 app/presenters/hyrax/file_usage.rb
hyrax-3.1.0 app/presenters/hyrax/file_usage.rb