Module: DataSets
- Defined in:
- lib/city_watch/util/datasets.rb
Instance Method Summary collapse
- #add_to_data_set(data_set_name, val, time = Time.now, host = host) ⇒ Object
- #data_set_key(data_set_name, host = host) ⇒ Object
- #dataset(name, &block) ⇒ Object
- #get_data_set(data_set_name, s_time, e_time = Time.now, host = host) ⇒ Object
- #run_dataset_collector(dat, rcv = nil, host = nil) ⇒ Object
Instance Method Details
#add_to_data_set(data_set_name, val, time = Time.now, host = host) ⇒ Object
27 28 29 |
# File 'lib/city_watch/util/datasets.rb', line 27 def add_to_data_set(data_set_name,val,time=Time.now,host=host) CityWatch.redis.zadd data_set_key(data_set_name,host), time.to_i, "#{Time.now.to_i},#{val}" end |
#data_set_key(data_set_name, host = host) ⇒ Object
21 22 23 24 25 |
# File 'lib/city_watch/util/datasets.rb', line 21 def data_set_key(data_set_name,host=host) CityWatch.redis.sadd "#{CityWatch.config[:prefix]}::#{host}::data_sets", data_set_name CityWatch.redis.sadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::data_sets", data_set_name "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::data_set::#{data_set_name}" end |
#dataset(name, &block) ⇒ Object
3 4 5 6 |
# File 'lib/city_watch/util/datasets.rb', line 3 def dataset(name,&block) @datasets ||= {} @datasets[name] = block end |
#get_data_set(data_set_name, s_time, e_time = Time.now, host = host) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/city_watch/util/datasets.rb', line 14 def get_data_set(data_set_name,s_time,e_time=Time.now,host=host) CityWatch.redis.zrevrangebyscore(data_set_key(data_set_name,host), s_time.to_i, e_time.to_i, :with_scores => true).map do |(val,score)| ,value = val.split(",") [Time.at(.to_i),value] end end |
#run_dataset_collector(dat, rcv = nil, host = nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/city_watch/util/datasets.rb', line 8 def run_dataset_collector(dat,rcv=nil,host=nil) @datasets.map do |(name,dataset)| dataset.call(dat) end if @datasets end |