Sha256: 241c608b70f0ff060a632fa77d5a86b4ba12743d06674f56db6d3a9a54a02931

Contents?: true

Size: 1010 Bytes

Versions: 17

Compression:

Stored size: 1010 Bytes

Contents

module DataSets
	
	def dataset(name,&block)
		@datasets ||= {}
		@datasets[name] = block
	end
	
	def run_dataset_collector(dat,rcv=nil,host=nil)
		@datasets.map do |(name,dataset)|
			dataset.call(dat)
		end if @datasets
	end
	
	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)|
			timestamp,value = val.split(",")
			[Time.at(timestamp.to_i),value]
		end
	end
	
	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
	
	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
	
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
city-watch-0.7.9 lib/city_watch/util/datasets.rb
city-watch-0.7.8 lib/city_watch/util/datasets.rb
city-watch-0.7.7 lib/city_watch/util/datasets.rb
city-watch-0.7.6 lib/city_watch/util/datasets.rb
city-watch-0.7.5 lib/city_watch/util/datasets.rb
city-watch-0.7.4 lib/city_watch/util/datasets.rb
city-watch-0.7.3 lib/city_watch/util/datasets.rb
city-watch-0.7.2 lib/city_watch/util/datasets.rb
city-watch-0.7.1 lib/city_watch/util/datasets.rb
city-watch-0.7.0 lib/city_watch/util/datasets.rb
city-watch-0.6.9 lib/city_watch/util/datasets.rb
city-watch-0.6.8 lib/city_watch/util/datasets.rb
city-watch-0.6.7 lib/city_watch/util/datasets.rb
city-watch-0.6.6 lib/city_watch/util/datasets.rb
city-watch-0.6.5 lib/city_watch/util/datasets.rb
city-watch-0.6.4 lib/city_watch/util/datasets.rb
city-watch-0.6.3 lib/city_watch/util/datasets.rb