Class: WorkUsage

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/work_usage.rb

Overview

class WorkUsage 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 collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ WorkUsage

Returns a new instance of WorkUsage.



8
9
10
11
12
13
14
15
16
# File 'app/presenters/work_usage.rb', line 8

def initialize(id)
  @work = CurationConcerns::WorkRelation.new.find(id)
  user = User.find_by(email: work.depositor)
  user_id = user ? user.id : nil

  self.id = id
  self.created = date_for_analytics(work)
  self.pageviews = WorkViewStat.to_flots WorkViewStat.statistics(work, created, user_id)
end

Instance Attribute Details

#createdObject

Returns the value of attribute created.



6
7
8
# File 'app/presenters/work_usage.rb', line 6

def created
  @created
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'app/presenters/work_usage.rb', line 6

def id
  @id
end

#pageviewsObject

Returns the value of attribute pageviews.



6
7
8
# File 'app/presenters/work_usage.rb', line 6

def pageviews
  @pageviews
end

#workObject

Returns the value of attribute work.



6
7
8
# File 'app/presenters/work_usage.rb', line 6

def work
  @work
end

Instance Method Details

#to_flotObject

Package data for visualization using JQuery Flot



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

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

#total_pageviewsObject



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

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