Class: Blackbeard::MetricData::Base

Inherits:
Object
  • Object
show all
Includes:
ConfigurationMethods
Defined in:
lib/blackbeard/metric_data/base.rb

Direct Known Subclasses

Total, Unique

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigurationMethods

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

Constructor Details

#initialize(metric, group = nil, cohort = nil) ⇒ Base

TODO: refactor so you pass group and cohort in as options



16
17
18
19
20
# File 'lib/blackbeard/metric_data/base.rb', line 16

def initialize(metric, group = nil, cohort = nil)
  @metric = metric
  @group = group
  @cohort = cohort
end

Instance Attribute Details

#cohortObject (readonly)

Returns the value of attribute cohort.



13
14
15
# File 'lib/blackbeard/metric_data/base.rb', line 13

def cohort
  @cohort
end

#groupObject (readonly)

Returns the value of attribute group.



13
14
15
# File 'lib/blackbeard/metric_data/base.rb', line 13

def group
  @group
end

#metricObject (readonly)

Returns the value of attribute metric.



13
14
15
# File 'lib/blackbeard/metric_data/base.rb', line 13

def metric
  @metric
end

Instance Method Details

#hour_keys_for_day(date) ⇒ Object



22
23
24
25
# File 'lib/blackbeard/metric_data/base.rb', line 22

def hour_keys_for_day(date)
  start_of_day = date.to_time
  Array(0..23).map{|x| start_of_day + (3600 * x) }.map{|t| key_for_hour(t) }
end

#keyObject



35
36
37
38
39
# File 'lib/blackbeard/metric_data/base.rb', line 35

def key
  @key ||= begin
    "data::#{uid}"
  end
end

#result_for_day(date) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/blackbeard/metric_data/base.rb', line 27

def result_for_day(date)
  key = key_for_date(date)
  result = db.hash_get_all(key)
  result = generate_result_for_day(date) if result.empty?
  result.each { |k,v| result[k] = v.to_f }
  result
end

#segmentsObject



45
46
47
# File 'lib/blackbeard/metric_data/base.rb', line 45

def segments
  [self.class::DEFAULT_SEGMENT]
end

#uidObject



41
42
43
# File 'lib/blackbeard/metric_data/base.rb', line 41

def uid
  uid = UidGenerator.new(self).uid
end