class Blackbeard::CohortMetric
Attributes
cohort[R]
metric[R]
Public Class Methods
new(cohort, metric)
click to toggle source
# File lib/blackbeard/cohort_metric.rb, line 8 def initialize(cohort, metric) @cohort = cohort @metric = metric end
Public Instance Methods
add(context, amount)
click to toggle source
# File lib/blackbeard/cohort_metric.rb, line 17 def add(context, amount) uid = context.unique_identifier hour_id = cohort.hour_id_for_participant(uid) metric_data.add_at(hour_id, uid, amount) unless hour_id.nil? end
chartable_result_for_day(date)
click to toggle source
# File lib/blackbeard/cohort_metric.rb, line 36 def chartable_result_for_day(date) participants = cohort.data.participants_for_day(date) result_per_participant( metric_data.result_for_day(date), participants) end
chartable_result_for_hour(hour)
click to toggle source
# File lib/blackbeard/cohort_metric.rb, line 31 def chartable_result_for_hour(hour) participants = cohort.data.participants_for_hour(hour) result_per_participant( metric_data.result_for_hour(hour), participants) end
chartable_segments()
click to toggle source
# File lib/blackbeard/cohort_metric.rb, line 27 def chartable_segments metric_data.segments.map{|s| "avg #{s}" } end
metric_data()
click to toggle source
# File lib/blackbeard/cohort_metric.rb, line 23 def metric_data @metric_data ||= MetricData.const_get(type.capitalize).new(metric, nil, cohort) end
result_per_participant(result, participants)
click to toggle source
# File lib/blackbeard/cohort_metric.rb, line 41 def result_per_participant(result, participants) participants = participants.to_f result.keys.each{|k| result["avg #{k}"] = result[k].to_f / participants } result end
type()
click to toggle source
# File lib/blackbeard/cohort_metric.rb, line 13 def type metric.type end