Class: StatBoard::GraphHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/stat_board/graph_helper.rb

Instance Method Summary collapse

Instance Method Details

#date_stepsObject

number of days per interval on the graph’s x axis



5
6
7
# File 'lib/stat_board/graph_helper.rb', line 5

def date_steps
  @date_steps ||= date_range.count / [date_range.count, 50].min
end

#first_day_everObject



9
10
11
# File 'lib/stat_board/graph_helper.rb', line 9

def first_day_ever
  @first_day_ever ||= first_day_of_each_model.sort.first
end

#resources_by_date(klass_name) ⇒ Object

a string of the array of the count of (klass) objects along the date_range, on every displayed interval



15
16
17
18
19
20
21
22
# File 'lib/stat_board/graph_helper.rb', line 15

def resources_by_date(klass_name)
  klass       = klass_name.to_s.constantize
  created_ats = klass.pluck(:created_at).compact.map(&:to_date)

  date_range.step(date_steps).map do |date|
    created_ats.count{|c_a| c_a < date}
  end.to_s
end