summaryrefslogtreecommitdiff
path: root/test.rb
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2020-09-27 20:56:34 +0200
committerPatrick Simianer <p@simianer.de>2020-09-27 20:56:34 +0200
commitae15ee1cdb06b00803f4426b0e965510661c3322 (patch)
treed5f6eadaae86f588ab91b50db26624cdadaab8de /test.rb
parent843bb50c48a8b11c572c1e64e0237d09d635e1f0 (diff)
2020-09-27
Diffstat (limited to 'test.rb')
-rw-r--r--test.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/test.rb b/test.rb
new file mode 100644
index 0000000..16ab18a
--- /dev/null
+++ b/test.rb
@@ -0,0 +1,27 @@
+int = Proc.new do |x|
+ x.to_i
+end
+float = Proc.new do |x|
+ x.to_f
+end
+str = Proc.new do |x|
+ x.to_s
+end
+
+def parse_to_hash s, conv
+ h = {}
+ puts s.split("\t").map { |i| i=i.split("::"); "#{i[0]} #{conv[i[0]].call}" }
+ return h
+end
+
+common_conv = { "db" => str, "timestamp"=>float, "device_type"=>str, "type"=>str, "device_id"=>str, "battery" => int, "battery_numeric" => int, "rssi" => int, "rssi_numeric" => int }
+rain_conv = {"rain_rate"=>float, "rain_total"=>float}.merge(common_conv)
+wind_conv = {"chill"=>float, "temperature"=>float,"average_speed"=>float,"direction"=>int,"gust"=>float}.merge(common_conv)
+temp_conv = {"humidity"=>float, "humidity_status"=>str,"humidity_status_numeric"=>int,"temperature"=>float}.merge(common_conv)
+conv = { "rain" => rain_conv, "wind" => wind_conv, "temp" => temp_conv }
+
+while line = STDIN.gets
+ db = line.split("\t").first.split("::")[1]
+ parse_to_hash line, conv[db]
+end
+