Class: Hyrax::WorkUsage

Inherits:
StatsUsagePresenter show all
Defined in:
app/presenters/hyrax/work_usage.rb

Overview

TODO: - Analytics do we still need this? Follows the model established by FileUsage.

Called by the stats controller, it finds cached work pageview data, and prepares it for visualization in /app/views/stats/work.html.erb

Instance Attribute Summary

Attributes inherited from StatsUsagePresenter

#id, #model

Instance Method Summary collapse

Methods inherited from StatsUsagePresenter

#created

Constructor Details

#initialize(id) ⇒ WorkUsage

Returns a new instance of WorkUsage.



10
11
12
# File 'app/presenters/hyrax/work_usage.rb', line 10

def initialize(id)
  self.model = Hyrax.query_service.find_by(id: id)
end

Instance Method Details

#to_flotObject

Package data for visualization using JQuery Flot



25
26
27
28
29
# File 'app/presenters/hyrax/work_usage.rb', line 25

def to_flot
  [
    { label: "Pageviews", data: pageviews }
  ]
end

#to_sObject



16
17
18
# File 'app/presenters/hyrax/work_usage.rb', line 16

def to_s
  model.title.first
end

#total_pageviewsObject



20
21
22
# File 'app/presenters/hyrax/work_usage.rb', line 20

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