parse_p1 0.0.7 → 0.0.8
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/CHANGELOG +3 -0
- data/lib/parse_p1/base.rb +1 -1
- data/lib/parse_p1/electricity.rb +4 -4
- data/lib/parse_p1/gas.rb +4 -4
- data/lib/parse_p1/version.rb +1 -1
- data/test/parse_p1_test.rb +22 -1
- metadata +4 -4
data/CHANGELOG
CHANGED
data/lib/parse_p1/base.rb
CHANGED
data/lib/parse_p1/electricity.rb
CHANGED
@@ -5,16 +5,16 @@ module ParseP1
|
|
5
5
|
module Electricity
|
6
6
|
|
7
7
|
def electra_meter_id
|
8
|
-
match_within_one_p1_record('0:96
|
8
|
+
match_within_one_p1_record('0:96\.1\.1\S(\d{1}[A-Z]{1}\d{1,96})\S')
|
9
9
|
end
|
10
10
|
|
11
11
|
def electricity_tariff_indicator
|
12
|
-
result = match_within_one_p1_record('0-0:96
|
12
|
+
result = match_within_one_p1_record('0-0:96\.14\.0\S(\d{1,9})\S')
|
13
13
|
result.to_i if result
|
14
14
|
end
|
15
15
|
|
16
16
|
def electricity_actual_threshold
|
17
|
-
electricity('0-0:17
|
17
|
+
electricity('0-0:17\.0\.0')
|
18
18
|
end
|
19
19
|
|
20
20
|
def electra_import_low
|
@@ -57,7 +57,7 @@ module ParseP1
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def get_actual_electricity(type)
|
60
|
-
power = get_electricity("1-0:#{first_electricity_code(type)}
|
60
|
+
power = get_electricity("1-0:#{first_electricity_code(type)}\.7\.0")
|
61
61
|
(power * 1000).to_i if power#Return as watts instead of kW
|
62
62
|
end
|
63
63
|
|
data/lib/parse_p1/gas.rb
CHANGED
@@ -5,21 +5,21 @@ module ParseP1
|
|
5
5
|
module Gas
|
6
6
|
|
7
7
|
def gas_meter_id
|
8
|
-
match_within_one_p1_record('1:96
|
8
|
+
match_within_one_p1_record('1:96\.1\.0\S(\d{1,96})\S')
|
9
9
|
end
|
10
10
|
|
11
11
|
#Only 2 digits for year!
|
12
12
|
def last_hourly_reading_gas
|
13
|
-
result = match_within_one_p1_record('0-1:24
|
13
|
+
result = match_within_one_p1_record('0-1:24\.3\.0\S(\d{12})\S')
|
14
14
|
DateTime.new(('20'+result[0..1]).to_i, result[2..3].to_i, result[4..5].to_i, result[6..7].to_i, result[8..9].to_i) if result
|
15
15
|
end
|
16
16
|
|
17
17
|
def measurement_unit_gas
|
18
|
-
match_within_one_p1_record('0-1:24
|
18
|
+
match_within_one_p1_record('0-1:24\.2\.1\S\S(\w+)\S')
|
19
19
|
end
|
20
20
|
|
21
21
|
def gas_usage
|
22
|
-
result = match_within_one_p1_record('\S0-1:24
|
22
|
+
result = match_within_one_p1_record('\S0-1:24\.2\.1\S\S\w+\S\W{1,2}\S(\d{5}\.\d{3})\S')
|
23
23
|
result.to_f if result
|
24
24
|
end
|
25
25
|
|
data/lib/parse_p1/version.rb
CHANGED
data/test/parse_p1_test.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'helper'
|
2
4
|
|
3
5
|
class TestParseP1 < Test::Unit::TestCase
|
4
6
|
|
5
7
|
def setup
|
6
8
|
#Data string as received on a Ruby on Rails application with some uncleared data in front of it
|
7
|
-
@data
|
9
|
+
@data = "sBs\u0012C\u0002\u0002\nK*r\"CKR[Wh)\r\n1-0:2.8.1(00000.000*kWh)\r\n1-0:2.8.2(00000.\r\n/ABc1\\1AB123-4567\r\n\r\n0-0:96.1.1(1A123456789012345678901234567890)\r\n1-0:1.8.1(00136.787*kWh)\r\n1-0:1.8.2(00131.849*kWh)\r\n1-0:2.8.1(00002.345*kWh)\r\n1-0:2.8.2(00054.976*kWh)\r\n0-0:96.14.0(0002)\r\n1-0:1.7.0(0003.20*kW)\r\n1-0:2.7.0(0000.12*kW)\r\n0-0:17.0.0(0999.00*kW)\r\n0-0:96.3.10(1)\r\n0-0:96.13.1()\r\n0-0:96.13.0()\r\n0-1:24.1.0(3)\r\n0-1:96.1.0(1234567890123456789012345678901234)\r\n0-1:24.3.0(120502150000)(00)(60)(1)(0-1:24.2.1)(m3)\r\n(00092.112)\r\n0-1:24.4.0(1)\r\n!"
|
10
|
+
@data2 = "//ABc1\u0001AB123-4567\n0-0:96.1.1(1A123456789012345678901234567890)\n1-0:1.8.1(02145.375*kWh)\n1-0:1.8.2(02043.840*kWh)\n1-0:2.8.1(00000.000*kWh)\n1-0:2.8.2(00000.001*kWh)\n0-0:96.14.0(0001)\n1-0:1.7.0(0000.82*kW)\n1-0:2.7.0(0000.00*kW)\n0-0:17.0.0(0999.00*kW)\n0-0:96.3.10(1)\n0-0:96.13.1()\n0-0:96.13.0()\n0-1:24.1.0(3)\n0-1:96.1.0(3338303034303031313338323831383131)\n0-1:24.3.0(130406220000)(00)(60)(1)(0-1:24.2.1)(m3)\n(01878.044)\n0-1:24.4.0(1)\n!"
|
11
|
+
@data3 = "//ABc1\\1AB123-4567\n0-0:96.1.1(1A123456789012345678901234567890)\n1-0:1.8.1(02145.452*kWh)\n1-0:1.8.2(02043.840*kWh)\n1-0:2.8.1(00000.000*kWh)\n1-0:2.8.2(00000.001*kWh)\n0-0:96.14.0(0001)\n1-0:1.7.0(0000.80*kW)\n1-0:2.7.0(0000.00*kW)\n0-0:17.0.0(0999.00*kW)\n0-0:96.3.10(1)\n0-0:96.13.1()\n0-0:96.13.0()\n0-1:24.1.0(3)\n0-1:96.1.0(3338303034303031313338323831383131)\n0-1:24.3.0(130406220000)(00)(60)(1)(0-1:24.2.1)(m3)\n(01878.044)\n0-1:24.4.0(1)\n!"
|
12
|
+
|
8
13
|
@p1 = ParseP1::Base.new(@data)
|
9
14
|
end
|
10
15
|
|
@@ -108,4 +113,20 @@ class TestParseP1 < Test::Unit::TestCase
|
|
108
113
|
|
109
114
|
end
|
110
115
|
|
116
|
+
context 'Data with irregularities' do
|
117
|
+
setup do
|
118
|
+
@p2 = ParseP1::Base.new(@data2)
|
119
|
+
@p3 = ParseP1::Base.new(@data3)
|
120
|
+
|
121
|
+
end
|
122
|
+
should 'return the device_id of the meter' do
|
123
|
+
assert @p2.device_id
|
124
|
+
assert @p3.device_id
|
125
|
+
end
|
126
|
+
should 'return the gas_usage of the meter' do
|
127
|
+
assert_equal 1878.044, @p2.gas_usage
|
128
|
+
assert_equal 1878.044, @p3.gas_usage
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
111
132
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parse_p1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
segments:
|
108
108
|
- 0
|
109
|
-
hash: -
|
109
|
+
hash: -4033320981012269
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
111
|
none: false
|
112
112
|
requirements:
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
segments:
|
117
117
|
- 0
|
118
|
-
hash: -
|
118
|
+
hash: -4033320981012269
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project: parse_p1
|
121
121
|
rubygems_version: 1.8.25
|