Class: Blackbeard::MetricData::Total

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

Constant Summary collapse

DEFAULT_SEGMENT =
'total'

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 = 1, segment = DEFAULT_SEGMENT) ⇒ Object



9
10
11
# File 'lib/blackbeard/metric_data/total.rb', line 9

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

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



13
14
15
16
17
18
19
# File 'lib/blackbeard/metric_data/total.rb', line 13

def add_at(time, uid, amount = 1, segment = DEFAULT_SEGMENT)
  # TODO: ensure time is in correct timezone
  key = key_for_hour(time)
  db.set_add_member(hours_set_key, key)
  db.hash_increment_by_float(key, segment, amount.to_f)
  # TODO: if not today, blow away rollup keys
end

#result_for_hour(time) ⇒ Object



21
22
23
24
25
26
# File 'lib/blackbeard/metric_data/total.rb', line 21

def result_for_hour(time)
  key = key_for_hour(time)
  result = db.hash_get_all(key)
  result.each{ |k,v| result[k] = v.to_f }
  result
end