Skip to content

Instantly share code, notes, and snippets.

@nippe

nippe/gist:5282338

Created Mar 31, 2013
Embed
What would you like to do?
Logging datapoints to tempo-db.com.
require 'tempodb'
def get_path_for_family path, directory_path
family = File.open(File.join(path, directory_path, 'family')).gets.strip.to_i
if family == 28
File.join(path, directory_path, 'temperature')
elsif family == 26
File.join(path, directory_path, 'humidity')
else
nil
end
end
def get_tempodb_series_key entry
if entry == '28.1061D6020000'
'temperature-outside-roof'
elsif entry == '28.10521C040000'
'temperature-attic'
elsif entry == '26.0ECE3B010000'
'humidity-attic'
else
nil
end
end
# TODO: Check if args exist
path = ARGV[0]
tempodb_client = TempoDB::Client.new('xxxxxxx', 'xxxxxxxxx')
Dir.entries(path).each do |entry|
if entry.match(/^[0-9]/)
unless get_path_for_family(path, entry).nil?
value = File.open( get_path_for_family(path, entry) ).gets.strip.to_f
series_key = get_tempodb_series_key(entry)
data = [TempoDB::DataPoint.new(Time.now, value)]
tempodb_client.write_key(series_key, data)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment