egauge 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -1
- data/README.rdoc +5 -5
- data/Version.txt +1 -1
- data/lib/egauge/data.rb +7 -7
- data/lib/egauge/register.rb +5 -5
- data/spec/egauge/data_spec.rb +4 -3
- data/spec/egauge/register_spec.rb +2 -1
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
-
== 1.0.
|
1
|
+
== 1.0.1 / 2012-10-09
|
2
|
+
|
3
|
+
* Update each_with_timestamp to more useful each_row that includes step size the row represents in seconds
|
4
|
+
* Clarify code and docs that serial is the configuration serial number not the device serial number
|
5
|
+
|
6
|
+
== 1.0.0 / 2012-10-09
|
2
7
|
|
3
8
|
* Initial revision
|
data/README.rdoc
CHANGED
@@ -12,7 +12,7 @@ A set of classes to enable parsing and using data from eGauge meters as native R
|
|
12
12
|
|
13
13
|
This gem facilitates interpreting incoming monitoring data and converting it into Ruby objects for easier
|
14
14
|
manipulation. It handles parsing the xml data posted by eGauge devices, converting them into Ruby objects
|
15
|
-
that can be manipulated
|
15
|
+
that can be manipulated more easily.
|
16
16
|
|
17
17
|
To use:
|
18
18
|
|
@@ -23,7 +23,7 @@ To use:
|
|
23
23
|
# the data posted to your server from the eGauge device
|
24
24
|
>> data = EGauge::Data.parse(request.body.read)
|
25
25
|
|
26
|
-
#
|
26
|
+
# What's the configuration serial number?
|
27
27
|
>> data.serial
|
28
28
|
=> '0x37cdd096'
|
29
29
|
|
@@ -35,15 +35,15 @@ To use:
|
|
35
35
|
>> data.row_count
|
36
36
|
=> 3
|
37
37
|
|
38
|
-
#
|
38
|
+
# Inspect one of the registers
|
39
39
|
>> reg = data.registers.first
|
40
40
|
>> reg.label
|
41
41
|
=> 'Solar'
|
42
42
|
>> reg.type_code
|
43
43
|
=> 'P'
|
44
44
|
|
45
|
-
# Get the data points from a given register, with timestamps
|
46
|
-
>> reg.
|
45
|
+
# Get the data points from a given register, with timestamps and seconds the value represents
|
46
|
+
>> reg.each_row do |ts, val, seconds|
|
47
47
|
>> puts "#{ts}: #{val}"
|
48
48
|
>> end
|
49
49
|
2012-10-09 13:50:00 -0400: 51140761685
|
data/Version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/egauge/data.rb
CHANGED
@@ -3,7 +3,7 @@ require 'nokogiri'
|
|
3
3
|
module EGauge
|
4
4
|
class Data
|
5
5
|
# Attributes
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :config_serial, :registers, :timestamp
|
7
7
|
|
8
8
|
# Parse XML and return an EGauge::Data object containing the data.
|
9
9
|
# This will be the primary entry point for most uses of this gem.
|
@@ -18,7 +18,7 @@ module EGauge
|
|
18
18
|
def initialize(xml)
|
19
19
|
# Store off Nokogiri xml tree
|
20
20
|
@xml = xml
|
21
|
-
@
|
21
|
+
@config_serial = @xml.group['serial']
|
22
22
|
|
23
23
|
# Get first data segment, which sets the register info for all data segments
|
24
24
|
data = @xml.group.data
|
@@ -51,7 +51,7 @@ module EGauge
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# Run each value in this register
|
54
|
-
def
|
54
|
+
def each_row
|
55
55
|
@xml.group.elements.each do |chunk|
|
56
56
|
# Set up for running this data chunk - prep timestamp and increment step from source xml
|
57
57
|
ts = EGauge::parse_time(chunk['time_stamp'])
|
@@ -60,17 +60,17 @@ module EGauge
|
|
60
60
|
# Run each row in the chunk, and yield our results
|
61
61
|
(chunk / './r').each do |row|
|
62
62
|
vals = (row / './c').collect {|c| c.text.to_i}
|
63
|
-
yield ts, vals
|
63
|
+
yield ts, vals, step
|
64
64
|
ts += step
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
# Return results as a 2D array, like so: [ [timestamp1, [val1, val2...]], [timestamp2, [val1, val2,...], ... ]
|
69
|
+
# Return results as a 2D array, like so: [ [timestamp1, [val1, val2...], seconds1], [timestamp2, [val1, val2,...], seconds2], ... ]
|
70
70
|
def to_a
|
71
71
|
res = []
|
72
|
-
|
73
|
-
res << [ts, vals]
|
72
|
+
each_row do |ts, vals, step|
|
73
|
+
res << [ts, vals, step]
|
74
74
|
end
|
75
75
|
res
|
76
76
|
end
|
data/lib/egauge/register.rb
CHANGED
@@ -14,7 +14,7 @@ module EGauge
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Run each value in this register, yielding |timestamp, value| for each
|
17
|
-
def
|
17
|
+
def each_row
|
18
18
|
@data.xml.group.elements.each do |chunk|
|
19
19
|
# Set up for running this data chunk - prep timestamp and increment step from source xml
|
20
20
|
ts = EGauge::parse_time(chunk['time_stamp'])
|
@@ -23,17 +23,17 @@ module EGauge
|
|
23
23
|
# Run each row in the chunk, and yield our results
|
24
24
|
(chunk / './r').each do |row|
|
25
25
|
val = (row / './c')[@index].text.to_i
|
26
|
-
yield ts, val
|
26
|
+
yield ts, val, step
|
27
27
|
ts += step
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
# Return results as a 2D array, like so: [ [timestamp1, val1], [timestamp2, val2], ... ]
|
32
|
+
# Return results as a 2D array, like so: [ [timestamp1, val1, seconds1], [timestamp2, val2, seconds2], ... ]
|
33
33
|
def to_a
|
34
34
|
res = []
|
35
|
-
|
36
|
-
res << [ts, val]
|
35
|
+
each_row do |ts, val, step|
|
36
|
+
res << [ts, val, step]
|
37
37
|
end
|
38
38
|
res
|
39
39
|
end
|
data/spec/egauge/data_spec.rb
CHANGED
@@ -12,8 +12,8 @@ describe EGauge::Data do
|
|
12
12
|
group.should_not be_nil
|
13
13
|
end
|
14
14
|
|
15
|
-
it 'should provide the serial number' do
|
16
|
-
@data1.
|
15
|
+
it 'should provide the configuration serial number' do
|
16
|
+
@data1.config_serial.should == '0x37cdd096'
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should provide the timestamp' do
|
@@ -35,10 +35,11 @@ describe EGauge::Data do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should allow access to full row data' do
|
38
|
-
@data1.
|
38
|
+
@data1.each_row do |ts, values, step|
|
39
39
|
ts.should be_a(Time)
|
40
40
|
values.should be_a(Array)
|
41
41
|
values.count.should == 3
|
42
|
+
step.should == 60
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -24,9 +24,10 @@ describe EGauge::Register do
|
|
24
24
|
|
25
25
|
it 'should allow iterating over values with timestamps' do
|
26
26
|
counter = 0
|
27
|
-
@reg.
|
27
|
+
@reg.each_row do |ts, val, step|
|
28
28
|
val.should be_a(Integer)
|
29
29
|
ts.should be_a(Time)
|
30
|
+
step.should == 60
|
30
31
|
counter += 1
|
31
32
|
end
|
32
33
|
counter.should == 3
|