Created
March 31, 2013 22:53
-
-
Save nippe/5282338 to your computer and use it in GitHub Desktop.
Logging datapoints to tempo-db.com.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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