saal 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90aa53b1093427163af28bee630532e79ccefea47de44463641c3e387f038640
4
- data.tar.gz: 41fca314cb32d91ca10bfb1982cf7e60a6b584c3c521b8ddcd148b18f465fd86
3
+ metadata.gz: 1a86991bf6a2c0ddf03cab4c239953c2c4e819f5019145398f4b7a527e928852
4
+ data.tar.gz: de08c727c732e4afb86cafcdcadfeec1f16fb127d675714b03bf388956bc6646
5
5
  SHA512:
6
- metadata.gz: ff26de3ff3cca4750a365b9672a82165d449f7c11fb3bd57d7f3f27758636a521d766ae99dc84b50cd30e940453eb30826ad485e44f9e50d723bb5625cd07915
7
- data.tar.gz: f93e18eacc3a2eb6555c95b9ea91f74506a39af91c6083ab6dbb3acc1ef2d83387db9ed59a573afcb7bbd1354cfdf7af51ec11122d9f48f287baf273c235debf
6
+ metadata.gz: db0fe9ccfd6e51da7bec292c9cd44c0b8c994ca238772cd817941f22f823f8ac8098ef005373e2f86dfcd9d121dc6470bdd3615ba961d1c514c620e8cf399095
7
+ data.tar.gz: fa64aa3d8cea43fc12e07db8d84def9ba45ca27655dbb95251e7b7c45e8c322b5c8ee0f58b02b4c63c9799f15a5db1316e0e174a6b246ee4725887d3ce12d823
data/bin/saal_envoy_read CHANGED
@@ -31,6 +31,14 @@ def fdisp_dec(val)
31
31
  end
32
32
  end
33
33
 
34
+ def fdispd(val)
35
+ if val
36
+ Time.at(val.to_i).strftime("%Y-%m-%d %k:%M:%S")
37
+ else
38
+ "n/a"
39
+ end
40
+ end
41
+
34
42
  def l(vals, name)
35
43
  sensor = vals[name]
36
44
  if sensor
@@ -137,7 +145,7 @@ inverters = envoy.create_sensors
137
145
  puts " Found #{envoy.inverters.size} inverters"
138
146
  envoy.inverters.each do |serial|
139
147
  puts " INVERTER: #{serial} \
140
- date:#{l(inverters,"inverters_#{serial}_last_report_date")} \
148
+ date:#{fdispd(l(inverters,"inverters_#{serial}_last_report_date"))} \
141
149
  lastWatts:#{l(inverters,"inverters_#{serial}_w_now")} \
142
150
  maxWatts:#{l(inverters,"inverters_#{serial}_w_max")} \
143
151
  "
data/lib/dbstore.rb CHANGED
@@ -35,6 +35,32 @@ module SAAL
35
35
  db_range("AVG", sensor, from, to)
36
36
  end
37
37
 
38
+ def weighted_average(sensor, from, to)
39
+ total_time = 0
40
+ total_value = 0.0
41
+ previous_value = nil
42
+ start_time = nil
43
+ initialized = false
44
+ db_query "SELECT date,value FROM sensor_reads
45
+ WHERE sensor = '#{db_quote(sensor.to_s)}'
46
+ AND date >= #{from.to_s}
47
+ AND date <= #{to.to_s}" do |r|
48
+ r.each do |row|
49
+ date = row["date"].to_i
50
+ value = row["value"].to_f
51
+ if start_time
52
+ elapsed = date - start_time
53
+ total_value += elapsed * previous_value
54
+ total_time += elapsed
55
+ initialized = true
56
+ end
57
+ start_time = date
58
+ previous_value = value
59
+ end
60
+ end
61
+ initialized ? total_value / total_time : nil
62
+ end
63
+
38
64
  def minimum(sensor, from, to)
39
65
  db_range("MIN", sensor, from, to)
40
66
  end
data/lib/denkovi.rb CHANGED
@@ -30,7 +30,7 @@ module SAAL
30
30
 
31
31
  class OutletGroup
32
32
  DEFAULT_TIMEOUT = 2
33
- DEFAULT_CACHE_TIMEOUT = 60
33
+ DEFAULT_CACHE_TIMEOUT = 5
34
34
  DEFAULT_OUTLETS = {}
35
35
  DEFAULT_DESCRIPTIONS = {}
36
36
 
data/lib/dinrelay.rb CHANGED
@@ -29,7 +29,7 @@ module SAAL
29
29
 
30
30
  class OutletGroup
31
31
  DEFAULT_TIMEOUT = 2
32
- DEFAULT_CACHE_TIMEOUT = 60
32
+ DEFAULT_CACHE_TIMEOUT = 5
33
33
 
34
34
  attr_accessor :host, :port, :user, :pass, :timeout, :cache_timeout
35
35
 
data/lib/envoy.rb CHANGED
@@ -16,7 +16,7 @@ module SAAL
16
16
  class PowerEnergy
17
17
  DEFAULT_HOST = "envoy.local"
18
18
  DEFAULT_TIMEOUT = 2
19
- DEFAULT_CACHE_TIMEOUT = 50
19
+ DEFAULT_CACHE_TIMEOUT = 5
20
20
  DEFAULT_SOURCES = [
21
21
  "production_inverters",
22
22
  "production_phase1", "production_phase2", "production_phase3", "production_total",
@@ -140,7 +140,7 @@ module SAAL
140
140
  class ACQuality
141
141
  DEFAULT_HOST = "envoy.local"
142
142
  DEFAULT_TIMEOUT = 2
143
- DEFAULT_CACHE_TIMEOUT = 50
143
+ DEFAULT_CACHE_TIMEOUT = 5
144
144
  DEFAULT_SOURCES = ["total","phase1","phase2","phase3",]
145
145
  DEFAULT_TYPES = ["frequency","voltage"]
146
146
  DEFAULT_PREFIX = "ac"
data/lib/saal.rb CHANGED
@@ -10,7 +10,7 @@ module SAAL
10
10
  DBCONF = CONFDIR+"database.yml"
11
11
  CHARTSCONF = CONFDIR+"charts.yml"
12
12
 
13
- VERSION = '0.3.3'
13
+ VERSION = '0.3.4'
14
14
  end
15
15
 
16
16
  require File.dirname(__FILE__)+'/dbstore.rb'
data/lib/sensor.rb CHANGED
@@ -72,6 +72,11 @@ module SAAL
72
72
  apply_offset @dbstore.average(@name, from, to)
73
73
  end
74
74
 
75
+ def weighted_average(from, to)
76
+ return @mock_opts[:weighted_average] if @mock_opts[:weighted_average]
77
+ apply_offset @dbstore.weighted_average(@name, from, to)
78
+ end
79
+
75
80
  def minimum(from, to)
76
81
  return @mock_opts[:minimum] if @mock_opts[:minimum]
77
82
  apply_offset @dbstore.minimum(@name, from, to)
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.3.3'
10
- s.date = '2020-12-28'
9
+ s.version = '0.3.4'
10
+ s.date = '2021-04-04'
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/dbstore_test.rb CHANGED
@@ -42,6 +42,21 @@ class TestFileStore < Test::Unit::TestCase
42
42
  assert_nil @dbstore.average(:test_sensor, 50, 60)
43
43
  end
44
44
 
45
+ def test_weighted_average
46
+ db_setup
47
+ test_values = [[10, 7.323],[12, 5.432],[23, -2.125], [44, 0.123]]
48
+ test_average = ((12-10)*7.323+(23-12)*5.432+(44-23)*(-2.125)) / (44-10)
49
+ test_values.each do |values|
50
+ @dbstore.write(:test_sensor, *values)
51
+ end
52
+
53
+ assert_instance_of Float, @dbstore.average(:test_sensor, 10, 44)
54
+ assert_in_delta test_average, @dbstore.weighted_average(:test_sensor, 10, 44), 0.001
55
+
56
+ # when there are no points it's nil
57
+ assert_nil @dbstore.weighted_average(:test_sensor, 50, 60)
58
+ end
59
+
45
60
  def test_min_max
46
61
  db_setup
47
62
  test_values = [[10, 7.323],[12, 5.432],[23, -2.125], [44, 0.123]]
data/test/sensor_test.rb CHANGED
@@ -31,6 +31,9 @@ class MockDBStore
31
31
  def average(sensor, from, to)
32
32
  @value
33
33
  end
34
+ def weighted_average(sensor, from, to)
35
+ @value
36
+ end
34
37
  def minimum(sensor, from, to)
35
38
  @value
36
39
  end
@@ -112,6 +115,7 @@ class TestSensor < Test::Unit::TestCase
112
115
  assert_equal corrected, sensor.minimum(0,100)
113
116
  assert_equal corrected, sensor.maximum(0,100)
114
117
  assert_equal corrected, sensor.average(0,100)
118
+ assert_equal corrected, sensor.weighted_average(0,100)
115
119
  end
116
120
 
117
121
  def test_linear_correction
@@ -125,6 +129,7 @@ class TestSensor < Test::Unit::TestCase
125
129
  assert_equal corrected, sensor.minimum(0,100)
126
130
  assert_equal corrected, sensor.maximum(0,100)
127
131
  assert_equal corrected, sensor.average(0,100)
132
+ assert_equal corrected, sensor.weighted_average(0,100)
128
133
  end
129
134
 
130
135
  def test_sensor_type
@@ -145,9 +150,10 @@ class TestSensor < Test::Unit::TestCase
145
150
  assert_equal 2.0, @mockable.read
146
151
  @mockable.write(3.0)
147
152
  assert_equal 3.0, @mockable.read
148
- @mockable.mock_set(:minimum => 1.0, :average => 2.0, :maximum => 3.0, :last_value => 5.0)
153
+ @mockable.mock_set(:minimum => 1.0, :average => 2.0, :weighted_average => 2.5, :maximum => 3.0, :last_value => 5.0)
149
154
  assert_equal 1.0, @mockable.minimum(0,100)
150
155
  assert_equal 2.0, @mockable.average(0,100)
156
+ assert_equal 2.5, @mockable.weighted_average(0,100)
151
157
  assert_equal 3.0, @mockable.maximum(0,100)
152
158
  assert_equal 5.0, @mockable.last_value
153
159
  assert_equal 3.0, @mockable.read
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Côrte-Real
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ownet