class Rhcf::Timeseries::Manager
Constants
- DEFAULT_STRATEGY
Attributes
prefix[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 35 def initialize(options = {}) @strategy = ( options[:strategy] || DEFAULT_STRATEGY).new @resolution_ids = options[:resolutions] || DEFAULT_RESOLUTIONS @prefix = [(options[:prefix] || DEFAULT_PREFIX) , @strategy.id].join(NAMESPACE_SEPARATOR) @connection_to_use = options[:connection] end
Public Instance Methods
connection_to_use()
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 49 def connection_to_use @connection_to_use || fail("No connection given") end
crunch_values(subject, resolution_id, point, filter, limit = 1000)
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 115 def crunch_values(subject, resolution_id, point, filter, limit = 1000) @strategy.crunch_values(self, subject, resolution_id, point, filter, limit) end
descend(path, do_descend = true , &block)
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 91 def descend(path, do_descend = true , &block) return if path.empty? or path == "." block.call(path) descend(File.dirname(path), do_descend, &block) if do_descend end
find(subject, from, to = Time.now, filter = nil, limit = 1000)
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 101 def find(subject, from, to = Time.now, filter = nil, limit = 1000) Rhcf::Timeseries::Query.new(subject, from, to, self, filter, limit) end
on_connection(conn) { |self| ... }
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 42 def on_connection(conn) old_connection = @connection_to_use @connection_to_use = conn yield self @connection_to_use = old_connection end
resolution(id)
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 105 def resolution(id) res = DEFAULT_RESOLUTIONS_MAP[id] # TODO configurable fail ArgumentError, "Invalid resolution name #{id} for this time series" if res.nil? res.merge(:id => id) end
resolution_value_at(moment, res_id)
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 74 def resolution_value_at(moment, res_id) res_config = DEFAULT_RESOLUTIONS_MAP[res_id] # TODO configurable if res_config.nil? fail "No resolution config for id: #{res_id.class}:#{res_id}" end time_resolution_formater = res_config[:formatter] case time_resolution_formater when String moment.strftime(time_resolution_formater) when Proc time_resolution_formater.call(moment) else fail ArgumentError, "Unexpected moment formater type #{time_resolution_formater.class}" end end
resolutions()
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 111 def resolutions @_resolutions ||= @resolution_ids.map { |id| resolution(id) } end
resolutions_of(moment)
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 68 def resolutions_of(moment) @resolution_ids.collect do |res_id| [res_id, resolution_value_at(moment, res_id)] end end
store(subject, event_point_hash, moment = Time.now, descend_subject = true, descend_event = true)
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 53 def store(subject, event_point_hash, moment = Time.now, descend_subject = true, descend_event = true) resolutions = resolutions_of(moment) descend(subject, descend_subject) do |subject_path| event_point_hash.each do |event, point_value| descend(event, descend_event) do |event_path| resolutions.each do |res| resolution_name, resolution_value = *res store_point_value(subject_path, resolution_name, resolution_value, point_value, event_path) end end end end end
store_point_value( subject_path, resolution_name, resolution_value, point_value, event_path)
click to toggle source
# File lib/rhcf/timeseries/manager.rb, line 97 def store_point_value( subject_path, resolution_name, resolution_value, point_value, event_path) @strategy.store_point_value(self, subject_path, resolution_name, resolution_value, point_value, event_path) end