Class: Hyrax::Statistics::OverTime

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/statistics/over_time.rb

Overview

An abstract class for generating cumulative graphs you must provide a ‘relation` method in the concrete class

Instance Method Summary collapse

Constructor Details

#initialize(delta_x: 7, x_min: 1.month.ago.beginning_of_day, x_max: Time.zone.now.end_of_day, x_output: ->(x) { x.to_i * 1000 }) ⇒ OverTime

Returns a new instance of OverTime.

Parameters:

  • delta_x (Fixnum) (defaults to: 7)

    change in x (in days)

  • x_min (Time) (defaults to: 1.month.ago.beginning_of_day)

    minimum date

  • x_max (Time) (defaults to: Time.zone.now.end_of_day)

    max date

  • x_output (Lambda) (defaults to: ->(x) { x.to_i * 1000 })

    a lambda for converting x to the desired output value. defaults to milliseconds since the epoch



12
13
14
15
16
17
18
19
20
# File 'app/services/hyrax/statistics/over_time.rb', line 12

def initialize(delta_x: 7,
               x_min: 1.month.ago.beginning_of_day,
               x_max: Time.zone.now.end_of_day,
               x_output: ->(x) { x.to_i * 1000 })
  @delta_x = delta_x
  @x_min = x_min
  @x_max = x_max
  @x_output = x_output
end

Instance Method Details

#pointsObject



22
23
24
25
26
27
28
29
30
# File 'app/services/hyrax/statistics/over_time.rb', line 22

def points
  Enumerator.new(size) do |y|
    x = @x_min
    while x <= @x_max
      x += @delta_x.days
      y.yield [@x_output.call(x), point(@x_min, x)]
    end
  end
end