saal 0.2.25 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/chart.rb +1 -1
- data/lib/chart_data.rb +1 -1
- data/lib/dbstore.rb +15 -18
- data/lib/dinrelay.rb +1 -0
- data/lib/outliercache.rb +1 -1
- data/lib/saal.rb +2 -2
- data/saal.gemspec +6 -5
- data/test/chart_data_test.rb +1 -1
- data/test/chart_test.rb +0 -3
- data/test/daemon_test.rb +2 -2
- data/test/dbstore_test.rb +5 -2
- data/test/dinrelay_test.rb +1 -1
- data/test/sensors_test.rb +5 -5
- data/test/test_db.yml +3 -3
- data/test/test_helper.rb +1 -2
- data/test/test_sensors.yml +1 -1
- metadata +47 -39
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 39379f2c03a4d1dfe41a1d481d2d90484b9d4e11b2c498f03c0f9ec064918850
|
4
|
+
data.tar.gz: ab741ee35c0c4528b89dbdbf32e17ca591d134f126db27e7a6974ce51e4a9723
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b2532eff01ab6a191106abe8984b46aa0f9b9b0ca461b87b6b09b5174334c4d054ea8ac335e17551e5c733ca0a1dd31356bc25d68b0d38140b27f89b041f257b
|
7
|
+
data.tar.gz: 4bc1474527de78d0a7c80248376f0ae56a4fbc680cbfa991851f41931b5f2bd78c5073ae6ea4217d4edb3b55fec8e105963026b3ca229b90d0868e7f0cfc7179
|
data/lib/chart.rb
CHANGED
@@ -5,7 +5,7 @@ module SAAL
|
|
5
5
|
@name = name
|
6
6
|
@defs = defs
|
7
7
|
@alignlabels = (defs['alignlabels'] || :center).to_sym
|
8
|
-
@sensors = defs['sensors'].map{|
|
8
|
+
@sensors = defs['sensors'].map{|sname| sensors.send(sname)}
|
9
9
|
@num = defs['last']
|
10
10
|
@periods = defs['periods']
|
11
11
|
@alt = defs['alt']
|
data/lib/chart_data.rb
CHANGED
data/lib/dbstore.rb
CHANGED
@@ -46,54 +46,51 @@ module SAAL
|
|
46
46
|
WHERE sensor = '#{db_quote(sensor.to_s)}'
|
47
47
|
AND date > '#{Time.now.utc.to_i - MAX_LAST_VAL_AGE}'
|
48
48
|
ORDER BY date DESC LIMIT 1" do |r|
|
49
|
-
|
50
|
-
|
49
|
+
row = r.first
|
50
|
+
if row
|
51
|
+
_date, value = [row["date"].to_i, row["value"].to_f]
|
52
|
+
value
|
51
53
|
else
|
52
|
-
|
53
|
-
date, value = [row[0].to_i, row[1].to_f]
|
54
|
-
return value
|
54
|
+
nil
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def each
|
60
60
|
db_query "SELECT sensor,date,value FROM sensor_reads" do |r|
|
61
|
-
r.
|
62
|
-
row
|
63
|
-
yield [row[0],row[1].to_i, row[2].to_f]
|
61
|
+
r.each do |row|
|
62
|
+
yield [row["sensor"],row["date"].to_i, row["value"].to_f]
|
64
63
|
end
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
68
67
|
private
|
69
68
|
def db_range(function, sensor, from, to)
|
70
|
-
db_query "SELECT #{function}(value) AS
|
69
|
+
db_query "SELECT #{function}(value) AS func FROM sensor_reads
|
71
70
|
WHERE sensor = '#{db_quote(sensor.to_s)}'
|
72
71
|
AND date >= #{from.to_s}
|
73
72
|
AND date <= #{to.to_s}" do |r|
|
74
|
-
|
75
|
-
|
73
|
+
row = r.first
|
74
|
+
if row && row["func"]
|
75
|
+
row["func"].to_f
|
76
76
|
else
|
77
|
-
|
78
|
-
row[0] ? row[0].to_f : nil
|
77
|
+
nil
|
79
78
|
end
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
83
82
|
def db_quote(text)
|
84
|
-
|
83
|
+
Mysql2::Client.escape(text)
|
85
84
|
end
|
86
85
|
|
87
86
|
def db_query(query, opts={})
|
88
87
|
db = nil
|
89
88
|
begin
|
90
89
|
# connect to the MySQL server
|
91
|
-
db =
|
92
|
-
@dbopts['db'],@dbopts['port'],@dbopts['socket'],
|
93
|
-
@dbopts['flags'])
|
90
|
+
db = Mysql2::Client.new(@dbopts)
|
94
91
|
res = db.query(query)
|
95
92
|
yield res if block_given?
|
96
|
-
rescue
|
93
|
+
rescue Mysql2::Error => e
|
97
94
|
$stderr.puts "MySQL Error #{e.errno}: #{e.error}" if !(e.errno == opts[:ignoreerr])
|
98
95
|
ensure
|
99
96
|
db.close if db
|
data/lib/dinrelay.rb
CHANGED
data/lib/outliercache.rb
CHANGED
@@ -41,7 +41,7 @@ module SAAL
|
|
41
41
|
def valid_cache
|
42
42
|
@compcache.sort!
|
43
43
|
central = @compcache[1..(@compcache.size-2)]
|
44
|
-
sum = central.inject(0.0){|
|
44
|
+
sum = central.inject(0.0){|csum,el| csum+el}
|
45
45
|
return false if sum == 0.0
|
46
46
|
average = sum/central.size
|
47
47
|
central.each do |el|
|
data/lib/saal.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
require "
|
2
|
+
require "mysql2"
|
3
3
|
require 'ownet'
|
4
4
|
require 'nokogiri'
|
5
5
|
require 'erb'
|
@@ -10,7 +10,7 @@ module SAAL
|
|
10
10
|
DBCONF = CONFDIR+"database.yml"
|
11
11
|
CHARTSCONF = CONFDIR+"charts.yml"
|
12
12
|
|
13
|
-
VERSION = '0.
|
13
|
+
VERSION = '0.3.0'
|
14
14
|
end
|
15
15
|
|
16
16
|
require File.dirname(__FILE__)+'/dbstore.rb'
|
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.
|
10
|
-
s.date = '
|
9
|
+
s.version = '0.3.0'
|
10
|
+
s.date = '2018-06-02'
|
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
|
@@ -19,6 +19,7 @@ EOF
|
|
19
19
|
s.authors = ["Pedro Côrte-Real"]
|
20
20
|
s.email = 'pedro@pedrocr.net'
|
21
21
|
s.homepage = 'https://github.com/pedrocr/saal'
|
22
|
+
s.licenses = 'LGPL-2.1'
|
22
23
|
|
23
24
|
s.require_paths = %w[lib]
|
24
25
|
|
@@ -28,9 +29,9 @@ EOF
|
|
28
29
|
|
29
30
|
s.executables = Dir.glob("bin/*").map{|f| f.gsub('bin/','')}
|
30
31
|
|
31
|
-
s.
|
32
|
-
s.
|
33
|
-
s.
|
32
|
+
s.add_runtime_dependency 'ownet', "~>0.2"
|
33
|
+
s.add_runtime_dependency 'mysql2', "~>0.5"
|
34
|
+
s.add_runtime_dependency 'nokogiri', '~>1.8'
|
34
35
|
|
35
36
|
# = MANIFEST =
|
36
37
|
s.files = %w[
|
data/test/chart_data_test.rb
CHANGED
@@ -78,7 +78,7 @@ class TestChartData < Test::Unit::TestCase
|
|
78
78
|
Time.utc(2012, 3, 25, 23, 59, 59),
|
79
79
|
["0"]+(2..23).map{|s| s.to_s}+["0"],
|
80
80
|
Time.utc(2012, 3, 25, 23, 59, 59),
|
81
|
-
"
|
81
|
+
"_changing_timezone_test2","Europe/Lisbon")
|
82
82
|
|
83
83
|
assert_alignment_interval(24, :hours, Time.utc(2010, 12, 29, 16, 0, 0),
|
84
84
|
Time.utc(2010, 12, 30, 15, 59, 59),
|
data/test/chart_test.rb
CHANGED
@@ -16,7 +16,6 @@ class TestChart < Test::Unit::TestCase
|
|
16
16
|
|
17
17
|
def test_average
|
18
18
|
name = 'week'
|
19
|
-
defs = @defs[name]
|
20
19
|
chart = @charts.find(name)
|
21
20
|
assert_equal ['Fri','Sat','Sun','Mon','Tue','Wed','Thu'], chart.periodnames
|
22
21
|
chart.sensors.each {|s| s.mock_set(:average => 1)}
|
@@ -31,7 +30,6 @@ class TestChart < Test::Unit::TestCase
|
|
31
30
|
|
32
31
|
def test_min_max_avg_1arity
|
33
32
|
name = 'week'
|
34
|
-
defs = @defs[name]
|
35
33
|
chart = @charts.find(name)
|
36
34
|
assert_equal ['Fri','Sat','Sun','Mon','Tue','Wed','Thu'], chart.periodnames
|
37
35
|
v = {:minimum => 1.0, :maximum => 2.0, :average => 1.5}
|
@@ -43,7 +41,6 @@ class TestChart < Test::Unit::TestCase
|
|
43
41
|
|
44
42
|
def test_min_max_0arity
|
45
43
|
name = 'week'
|
46
|
-
defs = @defs[name]
|
47
44
|
chart = @charts.find(name)
|
48
45
|
assert_equal ['Fri','Sat','Sun','Mon','Tue','Wed','Thu'], chart.periodnames
|
49
46
|
v = {:minimum => 1.0, :maximum => 2.0, :average => 1.5}
|
data/test/daemon_test.rb
CHANGED
@@ -18,7 +18,7 @@ class TestDaemon < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
db_test_query("SELECT * FROM sensor_reads") do |res|
|
21
|
-
assert res.
|
21
|
+
assert res.count > 0, "No sensor reads in DB"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -38,7 +38,7 @@ class TestDaemon < Test::Unit::TestCase
|
|
38
38
|
end
|
39
39
|
|
40
40
|
db_test_query("SELECT * FROM sensor_reads") do |res|
|
41
|
-
assert res.
|
41
|
+
assert res.count == 0
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
data/test/dbstore_test.rb
CHANGED
@@ -9,8 +9,11 @@ class TestFileStore < Test::Unit::TestCase
|
|
9
9
|
@dbstore.write(:test_sensor, test_time, test_value)
|
10
10
|
|
11
11
|
db_test_query("SELECT * FROM sensor_reads") do |res|
|
12
|
-
assert_equal 1, res.
|
13
|
-
|
12
|
+
assert_equal 1, res.count
|
13
|
+
row = res.first
|
14
|
+
assert_equal "test_sensor", row["sensor"]
|
15
|
+
assert_equal test_time, row["date"].to_i
|
16
|
+
assert_equal test_value, row["value"].to_f
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
data/test/dinrelay_test.rb
CHANGED
@@ -151,7 +151,7 @@ class TestDINRelay < Test::Unit::TestCase
|
|
151
151
|
|
152
152
|
# Test that the cache times out
|
153
153
|
def test_cache_invalidation
|
154
|
-
|
154
|
+
_sensors = SAAL::Sensors.new(@test_sensors_dinrelay_file, TEST_DBCONF)
|
155
155
|
@og.cache_timeout = 0.1
|
156
156
|
with_webrick(:html=>create_index_html(@vals)) do |feedback|
|
157
157
|
@og.state(1)
|
data/test/sensors_test.rb
CHANGED
@@ -67,11 +67,11 @@ class TestSensors < Test::Unit::TestCase
|
|
67
67
|
end
|
68
68
|
|
69
69
|
db_test_query("SELECT * FROM sensor_reads") do |res|
|
70
|
-
assert_equal 1, res.
|
71
|
-
row = res.
|
72
|
-
assert_equal "fake_temp", row[
|
73
|
-
assert_in_delta Time.now.utc.to_i, row[
|
74
|
-
assert_instance_of Float, row[
|
70
|
+
assert_equal 1, res.count
|
71
|
+
row = res.first
|
72
|
+
assert_equal "fake_temp", row["sensor"]
|
73
|
+
assert_in_delta Time.now.utc.to_i, row["date"].to_i, 100
|
74
|
+
assert_instance_of Float, row["value"].to_f
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/test/test_db.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
host: localhost
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
username: sensor_reads
|
3
|
+
password: password
|
4
|
+
database: sensor_reads_test
|
data/test/test_helper.rb
CHANGED
data/test/test_sensors.yml
CHANGED
metadata
CHANGED
@@ -1,63 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Pedro Côrte-Real
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-06-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: ownet
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.2
|
19
|
+
version: '0.2'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
28
|
-
none: false
|
28
|
+
name: mysql2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0'
|
33
|
+
version: '0.5'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.5'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
39
|
-
none: false
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - "~>"
|
42
46
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
47
|
+
version: '1.8'
|
44
48
|
type: :runtime
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
47
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
description: "A daemon and libraries to create an abstraction layer that interfaces
|
48
56
|
with \nsensors and actuators, recording their state, responding to requests \nfor
|
49
57
|
current and historical values, and allowing changes of state.\n"
|
50
58
|
email: pedro@pedrocr.net
|
51
59
|
executables:
|
52
|
-
- saal_chart~
|
53
60
|
- dinrelaystatus
|
54
|
-
- saal_readall
|
55
|
-
- saal_dump_database
|
56
|
-
- saal_daemon
|
57
|
-
- saal_chart
|
58
|
-
- saal_daemon~
|
59
61
|
- dinrelayset
|
60
62
|
- saal_import_mysql
|
63
|
+
- saal_chart~
|
64
|
+
- saal_daemon~
|
65
|
+
- saal_dump_database
|
66
|
+
- saal_readall
|
67
|
+
- saal_chart
|
68
|
+
- saal_daemon
|
61
69
|
extensions: []
|
62
70
|
extra_rdoc_files:
|
63
71
|
- README.rdoc
|
@@ -71,7 +79,9 @@ files:
|
|
71
79
|
- bin/dinrelayset
|
72
80
|
- bin/dinrelaystatus
|
73
81
|
- bin/saal_chart
|
82
|
+
- bin/saal_chart~
|
74
83
|
- bin/saal_daemon
|
84
|
+
- bin/saal_daemon~
|
75
85
|
- bin/saal_dump_database
|
76
86
|
- bin/saal_import_mysql
|
77
87
|
- bin/saal_readall
|
@@ -104,33 +114,31 @@ files:
|
|
104
114
|
- test/test_helper.rb
|
105
115
|
- test/test_sensor_cleanups.yml
|
106
116
|
- test/test_sensors.yml
|
107
|
-
- bin/saal_chart~
|
108
|
-
- bin/saal_daemon~
|
109
117
|
homepage: https://github.com/pedrocr/saal
|
110
|
-
licenses:
|
118
|
+
licenses:
|
119
|
+
- LGPL-2.1
|
120
|
+
metadata: {}
|
111
121
|
post_install_message:
|
112
122
|
rdoc_options:
|
113
|
-
- -S
|
114
|
-
- -w 2
|
115
|
-
- -N
|
116
|
-
- -c utf8
|
123
|
+
- "-S"
|
124
|
+
- "-w 2"
|
125
|
+
- "-N"
|
126
|
+
- "-c utf8"
|
117
127
|
require_paths:
|
118
128
|
- lib
|
119
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
-
none: false
|
121
130
|
requirements:
|
122
|
-
- -
|
131
|
+
- - ">="
|
123
132
|
- !ruby/object:Gem::Version
|
124
133
|
version: '0'
|
125
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
-
none: false
|
127
135
|
requirements:
|
128
|
-
- -
|
136
|
+
- - ">="
|
129
137
|
- !ruby/object:Gem::Version
|
130
138
|
version: '0'
|
131
139
|
requirements: []
|
132
140
|
rubyforge_project:
|
133
|
-
rubygems_version:
|
141
|
+
rubygems_version: 2.7.6
|
134
142
|
signing_key:
|
135
143
|
specification_version: 2
|
136
144
|
summary: Thin abstraction layer for interfacing and recording sensors (currently onewire)
|