home_io_meas_receiver 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -3
- data/Rakefile +0 -10
- data/VERSION +1 -1
- data/lib/meas_receiver.rb +0 -1
- data/lib/meas_receiver/meas_type_buffer.rb +14 -2
- data/lib/meas_receiver/meas_type_receiver.rb +21 -6
- metadata +26 -16
- data/lib/meas_receiver/receiver.rb +0 -8
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
colorize (0.5.8)
|
4
5
|
diff-lcs (1.1.3)
|
5
6
|
git (1.2.5)
|
6
7
|
jeweler (1.6.4)
|
@@ -8,8 +9,8 @@ GEM
|
|
8
9
|
git (>= 1.2.5)
|
9
10
|
rake
|
10
11
|
mean (0.1.0)
|
11
|
-
multi_json (1.
|
12
|
-
rake (0.
|
12
|
+
multi_json (1.5.0)
|
13
|
+
rake (10.0.3)
|
13
14
|
rspec (2.3.0)
|
14
15
|
rspec-core (~> 2.3.0)
|
15
16
|
rspec-expectations (~> 2.3.0)
|
@@ -24,13 +25,14 @@ GEM
|
|
24
25
|
multi_json (~> 1.0)
|
25
26
|
simplecov-html (~> 0.7.1)
|
26
27
|
simplecov-html (0.7.1)
|
27
|
-
tzinfo (0.3.
|
28
|
+
tzinfo (0.3.35)
|
28
29
|
|
29
30
|
PLATFORMS
|
30
31
|
ruby
|
31
32
|
|
32
33
|
DEPENDENCIES
|
33
34
|
bundler (~> 1.0.0)
|
35
|
+
colorize
|
34
36
|
jeweler (~> 1.6.4)
|
35
37
|
mean
|
36
38
|
rspec (~> 2.3.0)
|
data/Rakefile
CHANGED
@@ -42,16 +42,6 @@ end
|
|
42
42
|
|
43
43
|
task :default => :spec
|
44
44
|
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "simple_metar_parser #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
54
|
-
|
55
45
|
desc "Run RSpec with code coverage"
|
56
46
|
task :coverage do
|
57
47
|
`rake spec COVERAGE=true`
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/meas_receiver.rb
CHANGED
@@ -7,6 +7,9 @@ module MeasReceiver
|
|
7
7
|
class MeasTypeBuffer
|
8
8
|
def initialize(_meas_type)
|
9
9
|
@meas_type = _meas_type
|
10
|
+
@logger = @meas_type.logger
|
11
|
+
@debug = @meas_type.debug
|
12
|
+
@name = @meas_type.name
|
10
13
|
|
11
14
|
@coefficients = _meas_type.coefficients
|
12
15
|
@storage = _meas_type.storage
|
@@ -22,8 +25,7 @@ module MeasReceiver
|
|
22
25
|
end
|
23
26
|
|
24
27
|
attr_accessor :buffer, :time_from, :time_to, :coefficients, :storage
|
25
|
-
|
26
|
-
attr_reader :storage_last_i, :storage_buffer, :size
|
28
|
+
attr_reader :storage_last_i, :storage_buffer, :size, :name
|
27
29
|
|
28
30
|
# add raw value
|
29
31
|
def add!(v)
|
@@ -32,6 +34,8 @@ module MeasReceiver
|
|
32
34
|
@buffer << v
|
33
35
|
@time_from ||= Time.now
|
34
36
|
@time_to = Time.now
|
37
|
+
|
38
|
+
@logger.debug("Added #{v.to_s.yellow} to buffer, size #{@size.to_s.blue}") if @debug
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
@@ -98,6 +102,8 @@ module MeasReceiver
|
|
98
102
|
# Executed by scheduler to store important values
|
99
103
|
def perform_storage!
|
100
104
|
@mutex.synchronize do
|
105
|
+
@logger.debug("Performing storage for #{self.name.red}") if @debug
|
106
|
+
|
101
107
|
_range = storage_calculate_range
|
102
108
|
_avg = storage_calculate_averaged(_range)
|
103
109
|
_indexes = storage_get_ranges_to_store(_avg, _range)
|
@@ -110,10 +116,13 @@ module MeasReceiver
|
|
110
116
|
end
|
111
117
|
|
112
118
|
# call proc
|
119
|
+
@logger.debug("Storage buffer size is #{@storage_buffer.size.to_s.cyan}") if @debug
|
113
120
|
if @storage[:proc]
|
114
121
|
@storage[:proc].call(@storage_buffer)
|
115
122
|
end
|
116
123
|
|
124
|
+
@logger.debug("Storage completed for #{self.name.red}") if @debug
|
125
|
+
|
117
126
|
return @storage_buffer
|
118
127
|
end
|
119
128
|
end
|
@@ -124,6 +133,9 @@ module MeasReceiver
|
|
124
133
|
_from = @storage_last_i
|
125
134
|
# only check measurements up to
|
126
135
|
_to = @buffer.size - 1
|
136
|
+
|
137
|
+
@logger.debug("Range to store #{_from.to_s.magenta}..#{_to.to_s.magenta}") if @debug
|
138
|
+
|
127
139
|
return _from.._to
|
128
140
|
end
|
129
141
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'colorize'
|
1
3
|
require 'rufus/scheduler'
|
2
4
|
require 'meas_receiver/meas_type_buffer'
|
3
5
|
|
@@ -11,15 +13,23 @@ module MeasReceiver
|
|
11
13
|
def initialize(_options)
|
12
14
|
@options = _options
|
13
15
|
|
16
|
+
@options[:logger] ||= Hash.new
|
17
|
+
@options[:logger][:output] ||= STDOUT
|
18
|
+
@options[:logger][:level] ||= Logger::INFO
|
19
|
+
@logger = Logger.new(@options[:logger][:output])
|
20
|
+
@logger.level = @options[:logger][:level]
|
21
|
+
@debug = (@options[:logger][:level] == Logger::DEBUG)
|
22
|
+
|
14
23
|
@fetch_interval = _options[:fetch_interval] || DEFAULT_FETCH_INTERVAL
|
15
24
|
@fetch_interval = MIN_FETCH_INTERVAL if @fetch_interval < MIN_FETCH_INTERVAL
|
16
25
|
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
26
|
+
@name = @options[:name]
|
27
|
+
@command = @options[:command]
|
28
|
+
@response_size = @options[:response_size]
|
29
|
+
@coefficients = @options[:coefficients] || Hash.new
|
20
30
|
@coefficients[:linear] ||= 1.0
|
21
31
|
@coefficients[:offset] ||= 0.0
|
22
|
-
@storage =
|
32
|
+
@storage = @options[:storage] || Hash.new
|
23
33
|
@storage[:min_time_interval] ||= @fetch_interval
|
24
34
|
@storage[:min_unit_interval] = (@storage[:min_time_interval] / @fetch_interval).floor
|
25
35
|
@storage[:max_time_interval] ||= 3600
|
@@ -30,9 +40,11 @@ module MeasReceiver
|
|
30
40
|
@meas_buffer = MeasTypeBuffer.new(self)
|
31
41
|
end
|
32
42
|
|
33
|
-
attr_reader :fetch_interval, :command, :response_size, :coefficients, :storage
|
43
|
+
attr_reader :fetch_interval, :command, :response_size, :coefficients, :storage, :name, :logger, :debug
|
34
44
|
|
35
45
|
def start
|
46
|
+
@logger.debug("MeasReceiver started for #{self.name.red}") if @debug
|
47
|
+
|
36
48
|
@scheduler = Rufus::Scheduler.start_new(frequency: SCH_MIN_INTERVAL)
|
37
49
|
@scheduler.every "#{@fetch_interval}s" do
|
38
50
|
fetch
|
@@ -45,12 +57,15 @@ module MeasReceiver
|
|
45
57
|
|
46
58
|
def stop
|
47
59
|
@scheduler.stop
|
60
|
+
@logger.debug("MeasReceiver stopped for #{self.name.red}") if @debug
|
48
61
|
end
|
49
62
|
|
50
63
|
def fetch
|
51
64
|
v = @comm_object.g
|
52
|
-
puts v
|
53
65
|
@meas_buffer.add!(v)
|
66
|
+
|
67
|
+
@logger.debug("Fetched #{self.name.red} = #{v.to_s.yellow}") if @debug
|
68
|
+
|
54
69
|
return v
|
55
70
|
end
|
56
71
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: home_io_meas_receiver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rufus-scheduler
|
16
|
-
requirement: &
|
16
|
+
requirement: &15527060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15527060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mean
|
27
|
-
requirement: &
|
27
|
+
requirement: &15558520 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *15558520
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: colorize
|
38
|
+
requirement: &15557820 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *15557820
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rspec
|
38
|
-
requirement: &
|
49
|
+
requirement: &15557180 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: 2.3.0
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *15557180
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: bundler
|
49
|
-
requirement: &
|
60
|
+
requirement: &15556540 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: 1.0.0
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *15556540
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: jeweler
|
60
|
-
requirement: &
|
71
|
+
requirement: &15555820 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 1.6.4
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *15555820
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: simplecov
|
71
|
-
requirement: &
|
82
|
+
requirement: &15555060 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,7 +87,7 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *15555060
|
80
91
|
description: Receive measurements from IoServer (part if HomeIO).
|
81
92
|
email: bobikx@poczta.fm
|
82
93
|
executables: []
|
@@ -95,7 +106,6 @@ files:
|
|
95
106
|
- lib/meas_receiver/comm_protocol.rb
|
96
107
|
- lib/meas_receiver/meas_type_buffer.rb
|
97
108
|
- lib/meas_receiver/meas_type_receiver.rb
|
98
|
-
- lib/meas_receiver/receiver.rb
|
99
109
|
homepage: http://github.com/akwiatkowski/meas_receiver
|
100
110
|
licenses:
|
101
111
|
- LGPLv3
|
@@ -111,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
121
|
version: '0'
|
112
122
|
segments:
|
113
123
|
- 0
|
114
|
-
hash:
|
124
|
+
hash: 2619819358904249746
|
115
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
126
|
none: false
|
117
127
|
requirements:
|