Class: Blackbeard::Cohort

Inherits:
Storable show all
Includes:
Chartable
Defined in:
lib/blackbeard/cohort.rb

Instance Attribute Summary

Attributes inherited from Storable

#id, #new_record

Instance Method Summary collapse

Methods included from Chartable

#recent_days, #recent_days_chart, #recent_hours, #recent_hours_chart

Methods inherited from Storable

#==, all, all_keys, count, create, find, find_or_create, #initialize, #key, key_for, #master_key, master_key, new_from_key, new_from_keys, #new_record?, on_reload, on_reload_methods, on_save, on_save_methods, #reload, #save, set_master_key

Methods included from StorableAttributes

included

Methods included from StorableHasSet

included

Methods included from StorableHasMany

included

Methods included from ConfigurationMethods

#config, #db, #guest_method, included, #tz

Constructor Details

This class inherits a constructor from Blackbeard::Storable

Instance Method Details

#add(context, timestamp = nil, force = false) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/blackbeard/cohort.rb', line 11

def add(context, timestamp = nil, force = false)
  save if new_record?
  uid = context.unique_identifier
  #TODO: Make sure timestamp is in correct tz
  timestamp ||= tz.now
  return (force) ? data.add_with_force(uid, timestamp) : data.add_without_force(uid, timestamp)
end

#chartable_result_for_day(date) ⇒ Object



43
44
45
# File 'lib/blackbeard/cohort.rb', line 43

def chartable_result_for_day(date)
  {'participants' => data.participants_for_day(date) }
end

#chartable_result_for_hour(hour) ⇒ Object



39
40
41
# File 'lib/blackbeard/cohort.rb', line 39

def chartable_result_for_hour(hour)
  {'participants' => data.participants_for_hour(hour) }
end

#chartable_segmentsObject



35
36
37
# File 'lib/blackbeard/cohort.rb', line 35

def chartable_segments
  ['participants']
end

#dataObject



19
20
21
# File 'lib/blackbeard/cohort.rb', line 19

def data
  @data ||= CohortData.new(self)
end

#hour_id_for_participant(uid) ⇒ Object



31
32
33
# File 'lib/blackbeard/cohort.rb', line 31

def hour_id_for_participant(uid)
  data.hour_id_for_participant(uid)
end

#metric_data(metric) ⇒ Object



27
28
29
# File 'lib/blackbeard/cohort.rb', line 27

def metric_data(metric)
  CohortMetric.new(self,metric).metric_data
end

#nameObject



23
24
25
# File 'lib/blackbeard/cohort.rb', line 23

def name
  storable_attributes_hash['name'] || id
end