Module: Blackbeard::Chartable

Included in:
Cohort, CohortMetric, GroupMetric, Metric
Defined in:
lib/blackbeard/chartable.rb

Instance Method Summary collapse

Instance Method Details

#recent_days(count = 28, starting_on = tz.now.to_date) ⇒ Object

In your class define 3 methods:

* chartable_segments
* chartable_result_for_hour
* chartable_result_for_day


9
10
11
12
13
14
15
# File 'lib/blackbeard/chartable.rb', line 9

def recent_days(count=28, starting_on = tz.now.to_date)
  Array(0..count-1).map do |offset|
    date = starting_on - offset
    result = chartable_result_for_day(date)
    Blackbeard::MetricDate.new(date, result)
  end
end

#recent_days_chart(count = 28, starting_on = tz.now.to_date) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/blackbeard/chartable.rb', line 36

def recent_days_chart(count = 28, starting_on = tz.now.to_date)
  data = recent_days(count, starting_on)
  Chart.new(
    :dom_id => 'recent_days_chart',
    :title => "Last #{count} Days",
    :columns => ['Day']+chartable_segments,
    :rows => data.reverse.map{ |metric_date| metric_date.result_rows(chartable_segments) }
  )
end

#recent_hours(count = 24, starting_at = tz.now) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/blackbeard/chartable.rb', line 17

def recent_hours(count = 24, starting_at = tz.now)
  Array(0..count-1).map do |offset|
    hour = starting_at - (offset * 3600)
    result = chartable_result_for_hour(hour)
    Blackbeard::MetricHour.new(hour, result)
  end
end

#recent_hours_chart(count = 24, starting_at = tz.now) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/blackbeard/chartable.rb', line 25

def recent_hours_chart(count = 24, starting_at = tz.now)
  data = recent_hours(count, starting_at)
  title = "Last #{count} Hours"
  Chart.new(
    :dom_id => 'recent_hour_chart',
    :title => title,
    :columns => ['Hour']+chartable_segments,
    :rows => data.reverse.map{ |metric_hour| metric_hour.result_rows(chartable_segments) }
  )
end