Class: Blackbeard::MetricData::Unique

Inherits:
Base
  • Object
show all
Defined in:
lib/blackbeard/metric_data/unique.rb

Constant Summary collapse

DEFAULT_SEGMENT =
'uniques'

Instance Attribute Summary

Attributes inherited from Base

#cohort, #group, #metric

Instance Method Summary collapse

Methods inherited from Base

#hour_keys_for_day, #initialize, #key, #result_for_day, #segments, #uid

Methods included from ConfigurationMethods

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

Constructor Details

This class inherits a constructor from Blackbeard::MetricData::Base

Instance Method Details

#add(uid, amount = nil, segment = DEFAULT_SEGMENT) ⇒ Object



8
9
10
# File 'lib/blackbeard/metric_data/unique.rb', line 8

def add(uid, amount = nil, segment = DEFAULT_SEGMENT)
  add_at(tz.now, uid, amount, segment)
end

#add_at(time, uid, amount = nil, segment = DEFAULT_SEGMENT) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/blackbeard/metric_data/unique.rb', line 12

def add_at(time, uid, amount = nil, segment = DEFAULT_SEGMENT)
  #TODO: unsure time is in proper timezone
  key = key_for_hour(time)
  segment_key = segment_key(key, segment)

  db.set_add_member(hours_set_key, key)
  db.set_add_member(key, segment_key)
  db.set_add_member(segment_key, uid)
  #TODO: if not today, blow away rollup keys
end

#result_for_hour(time) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/blackbeard/metric_data/unique.rb', line 23

def result_for_hour(time)
  key = key_for_hour(time)
  segment_keys = db.set_members(key)
  result = {}
  segment_keys.each do |segment_key|
    segment = segment_key.split(/::/).last
    result[segment] = db.set_count(segment_key)
  end
  result
end

#segment_key(key, segment) ⇒ Object



34
35
36
# File 'lib/blackbeard/metric_data/unique.rb', line 34

def segment_key(key, segment)
  "#{key}::#{segment}"
end