saal 0.2.11 → 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO +1 -0
- data/bin/saal_chart +7 -8
- data/lib/dinrelay.rb +17 -10
- data/lib/saal.rb +1 -1
- data/saal.gemspec +2 -2
- data/test/dinrelay_test.rb +35 -1
- metadata +4 -4
data/TODO
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
TODO
|
2
|
+
- Make the sensor storage in saal_daemon threaded so a single sensor read can't stall everything else for a long time
|
2
3
|
!-Index the value column of the sensor reads for minimum and maximum
|
3
4
|
- Change the filtering operations (e.g., outliercache) so that the raw value is always stored in the database
|
4
5
|
- Make the outliercache filter based on the expected sensor range (e.g. -20-50 in temperature and 800-1200 in pressure) so as to not be overly sensitive when around 0)
|
data/bin/saal_chart
CHANGED
@@ -12,9 +12,7 @@ if ARGV.size != 1
|
|
12
12
|
exit (2)
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
[:hum_exterior, [0,100]],
|
17
|
-
[:pressao, [950,1050]]]
|
15
|
+
SENSOR_RANGES = {:temperature=>[-15, 45], :humidity=>[0,100], :pressure=>[950,1050]}
|
18
16
|
|
19
17
|
|
20
18
|
SAAL::Charts.new.each do |chart|
|
@@ -27,13 +25,14 @@ SAAL::Charts.new.each do |chart|
|
|
27
25
|
@maxs = chart.maximum
|
28
26
|
@avgs = chart.average
|
29
27
|
@minmax = {}
|
30
|
-
|
28
|
+
chart.sensors.each do |s|
|
29
|
+
s = s.name.to_sym
|
31
30
|
@minmax[s] = {:maximum => @maxs[s], :minimum => @mins[s], :average => @avgs[s]}
|
32
31
|
end
|
33
32
|
|
34
33
|
File.open(ymlfile, 'w').write(YAML::dump(@minmax))
|
35
34
|
|
36
|
-
def normalize_data(data, min, max
|
35
|
+
def normalize_data(data, min, max)
|
37
36
|
data.map do |i|
|
38
37
|
if i.nil?
|
39
38
|
-1.0
|
@@ -42,7 +41,7 @@ SAAL::Charts.new.each do |chart|
|
|
42
41
|
elsif i > max
|
43
42
|
100.0
|
44
43
|
else
|
45
|
-
(((i-min)/(max-min).to_f)*1000).round/10.0
|
44
|
+
(((i-min)/(max-min).to_f)*1000).round/10.0
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
@@ -51,8 +50,8 @@ SAAL::Charts.new.each do |chart|
|
|
51
50
|
@numperiods = @periodnames.size
|
52
51
|
@averages = chart.average(NUM_VALUES)
|
53
52
|
|
54
|
-
@data =
|
55
|
-
normalize_data(@averages[sensor], *
|
53
|
+
@data = chart.sensors.map do |sensor|
|
54
|
+
normalize_data(@averages[sensor.name.to_sym], *(SENSOR_RANGES[sensor.sensor_type]))
|
56
55
|
end
|
57
56
|
|
58
57
|
@dataurl = @data.map {|values| values.join(",")}.join('|')
|
data/lib/dinrelay.rb
CHANGED
@@ -28,11 +28,16 @@ module SAAL
|
|
28
28
|
end
|
29
29
|
|
30
30
|
class OutletGroup
|
31
|
+
DEFAULT_TIMEOUT = 2
|
32
|
+
|
33
|
+
attr_reader :timeout
|
34
|
+
|
31
35
|
def initialize(opts={})
|
32
36
|
@host = opts[:host] || opts['host'] || 'localhost'
|
33
37
|
@port = opts[:port] || opts['port'] || 80
|
34
38
|
@user = opts[:user] || opts['user'] || 'admin'
|
35
39
|
@pass = opts[:pass] || opts['pass'] || '1234'
|
40
|
+
@timeout = opts[:timeout] || DEFAULT_TIMEOUT
|
36
41
|
end
|
37
42
|
|
38
43
|
def state(num)
|
@@ -48,17 +53,19 @@ module SAAL
|
|
48
53
|
private
|
49
54
|
def do_get(path)
|
50
55
|
begin
|
51
|
-
Net::HTTP.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
http = Net::HTTP.new(@host,@port)
|
57
|
+
# Timeout faster when the other side doesn't respond
|
58
|
+
http.open_timeout = @timeout
|
59
|
+
http.read_timeout = @timeout
|
60
|
+
req = Net::HTTP::Get.new(path)
|
61
|
+
req.basic_auth @user, @pass
|
62
|
+
response = http.request(req)
|
63
|
+
if response.code != "200"
|
64
|
+
#$stderr.puts "ERROR: Code #{response.code}"
|
65
|
+
#$stderr.puts response.body
|
66
|
+
return nil
|
61
67
|
end
|
68
|
+
return response
|
62
69
|
rescue Exception
|
63
70
|
return nil
|
64
71
|
end
|
data/lib/saal.rb
CHANGED
data/saal.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
|
8
8
|
s.name = 'saal'
|
9
|
-
s.version = '0.2.
|
10
|
-
s.date = '2011-
|
9
|
+
s.version = '0.2.13'
|
10
|
+
s.date = '2011-06-03'
|
11
11
|
|
12
12
|
s.summary = "Thin abstraction layer for interfacing and recording sensors (currently onewire) and actuators (currently dinrelay)"
|
13
13
|
s.description = <<EOF
|
data/test/dinrelay_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__)+'/test_helper.rb'
|
2
2
|
require 'webrick'
|
3
|
-
|
3
|
+
require 'benchmark'
|
4
4
|
|
5
5
|
class TestDINRelay < Test::Unit::TestCase
|
6
6
|
SERVICE_OPTS = {:host => 'localhost', :port => 33333,
|
@@ -16,8 +16,10 @@ class TestDINRelay < Test::Unit::TestCase
|
|
16
16
|
@pass = opts[:pass]
|
17
17
|
@status = opts[:status] || 200
|
18
18
|
@feedback = opts[:feedback] || {}
|
19
|
+
@sleep = opts[:sleep] || 0
|
19
20
|
end
|
20
21
|
def do_GET(req, res)
|
22
|
+
sleep @sleep
|
21
23
|
@feedback[:uri] = req.request_uri.to_s
|
22
24
|
WEBrick::HTTPAuth.basic_auth(req, res, "My Realm") {|user, pass|
|
23
25
|
user == @user && pass == @pass
|
@@ -134,4 +136,36 @@ class TestDINRelay < Test::Unit::TestCase
|
|
134
136
|
end
|
135
137
|
end
|
136
138
|
end
|
139
|
+
|
140
|
+
def test_fast_open_timeout
|
141
|
+
#FIXME: Find a way to make this test address more generic
|
142
|
+
@og=SAAL::DINRelay::OutletGroup.new(SERVICE_OPTS.merge(:host => "10.254.254.254",
|
143
|
+
:timeout=>0.1))
|
144
|
+
with_webrick(:html=>create_index_html(@vals)) do |feedback|
|
145
|
+
time = Benchmark.measure do
|
146
|
+
@vals.each do |num, state|
|
147
|
+
assert_equal nil, @og.state(num), "Read not timing out?"
|
148
|
+
assert !@og.set_state(num,"ON"), "State change not timing out?"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
total_time = @og.timeout*2*@vals.keys.size
|
152
|
+
assert time.total < total_time
|
153
|
+
"Doing the reads took too long, are we really timing out?"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_fast_read_timeout
|
158
|
+
@og=SAAL::DINRelay::OutletGroup.new(SERVICE_OPTS.merge(:timeout=>0.1))
|
159
|
+
with_webrick(:html=>create_index_html(@vals),:sleep=>10) do |feedback|
|
160
|
+
time = Benchmark.measure do
|
161
|
+
@vals.each do |num, state|
|
162
|
+
assert_equal nil, @og.state(num), "Read not timing out?"
|
163
|
+
assert !@og.set_state(num,"ON"), "State change not timing out?"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
total_time = @og.timeout*2*@vals.keys.size
|
167
|
+
assert time.total < total_time
|
168
|
+
"Doing the reads took too long, are we really timing out?"
|
169
|
+
end
|
170
|
+
end
|
137
171
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 13
|
10
|
+
version: 0.2.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Pedro C\xC3\xB4rte-Real"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|