Skip to content

Instantly share code, notes, and snippets.

@bmneely
Last active December 22, 2015 08:19
Show Gist options
  • Save bmneely/6444202 to your computer and use it in GitHub Desktop.
Save bmneely/6444202 to your computer and use it in GitHub Desktop.
First method of bar.rb
def self.get_data_usage(thing)
bytes_in = thing.get_data_usage(method_name: :bytes_in)
bytes_out = thing.get_data_usage(method_name: :bytes_out)
total_bytes = thing.get_data_usage
return if total_bytes.nil?
zeros = 0
total_bytes.each do |u|
break if u > 0
zeros += 1
end
bytes_in.shift(zeros)
bytes_out.shift(zeros)
total_bytes.shift(zeros)
bytes_in
bytes_out
trendline_data = compute_trend_line_data(total_bytes)
a = trendline_data[:a]
b = trendline_data[:b]
n = bytes_in.count
usage_data = []
bytes_in.each_with_index do |b_in, i|
trend = (b * n + a) > 0 ? (b * n + a) : 0
usage_data << { time: DateTime.now + i.days, value1: b_in/1000000000.0, value2: bytes_out[i]/1000000000.0, value3: trend }
end
usage_data.to_json
end
def self.get_account_crossfilter_data_usage(account, start=nil, stop=nil, bucket_size=1.day)
usage_data = []
account.ecm_routers.each do |ecm_router|
bytes_in = ecm_router.router_config.get_data_usage(method_name: :bytes_in, bucket_start: start, bucket_stop: stop, bucket_size: bucket_size)
bytes_out = ecm_router.router_config.get_data_usage(method_name: :bytes_out, bucket_start: start, bucket_stop: stop, bucket_size: bucket_size)
total_bytes = ecm_router.router_config.get_data_usage(bucket_start: start, bucket_stop: stop, bucket_size: bucket_size)
bytes_in
bytes_out
bytes_in.each_with_index do |b_in, i|
usage_data << { date: (DateTime.now.to_i + i * bucket_size)*1000, bytes_in: b_in/1000000000.0, bytes_out: bytes_out[i]/1000000000.0, router_name: ecm_router.display_name, address: ecm_router.gmaps4rails_address }
end
usage_data
end
usage_data.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment