Class: Blackbeard::MetricData::Base
- Inherits:
-
Object
- Object
- Blackbeard::MetricData::Base
- Includes:
- ConfigurationMethods
- Defined in:
- lib/blackbeard/metric_data/base.rb
Instance Attribute Summary collapse
-
#cohort ⇒ Object
readonly
Returns the value of attribute cohort.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
Instance Method Summary collapse
- #hour_keys_for_day(date) ⇒ Object
-
#initialize(metric, group = nil, cohort = nil) ⇒ Base
constructor
TODO: refactor so you pass group and cohort in as options.
- #key ⇒ Object
- #result_for_day(date) ⇒ Object
- #segments ⇒ Object
- #uid ⇒ Object
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
#cohort ⇒ Object (readonly)
Returns the value of attribute cohort.
13 14 15 |
# File 'lib/blackbeard/metric_data/base.rb', line 13 def cohort @cohort end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
13 14 15 |
# File 'lib/blackbeard/metric_data/base.rb', line 13 def group @group end |
#metric ⇒ Object (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 |
#key ⇒ Object
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 |
#segments ⇒ Object
45 46 47 |
# File 'lib/blackbeard/metric_data/base.rb', line 45 def segments [self.class::DEFAULT_SEGMENT] end |
#uid ⇒ Object
41 42 43 |
# File 'lib/blackbeard/metric_data/base.rb', line 41 def uid uid = UidGenerator.new(self).uid end |