aemo 0.1.27 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aemo/dispatchable.rb +4 -4
- data/lib/aemo/market.rb +30 -27
- data/lib/aemo/market/interval.rb +27 -23
- data/lib/aemo/msats.rb +218 -210
- data/lib/aemo/nem12.rb +165 -160
- data/lib/aemo/nem13.rb +1 -2
- data/lib/aemo/nmi.rb +91 -85
- data/lib/aemo/region.rb +12 -11
- data/lib/aemo/version.rb +3 -3
- data/lib/data/xml_to_json.rb +62 -0
- data/spec/aemo_spec.rb +1 -2
- data/spec/lib/aemo/market/interval_spec.rb +13 -13
- data/spec/lib/aemo/market_spec.rb +8 -6
- data/spec/lib/aemo/msats_spec.rb +14 -15
- data/spec/lib/aemo/nem12_spec.rb +8 -10
- data/spec/lib/aemo/nmi_spec.rb +79 -71
- data/spec/lib/aemo/region_spec.rb +5 -6
- data/spec/spec_helper.rb +38 -35
- metadata +16 -2
- data/lib/data/xml-to-json.rb +0 -61
@@ -2,17 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AEMO::Region do
|
4
4
|
describe '.REGIONS' do
|
5
|
-
it
|
5
|
+
it 'should be a hash' do
|
6
6
|
expect(AEMO::Region::REGIONS).to be_instance_of(Hash)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'creating a region' do
|
11
11
|
it 'should raise an error if invalid region' do
|
12
|
-
expect {AEMO::Region.new('BOTTOMS')}.to raise_error(ArgumentError)
|
12
|
+
expect { AEMO::Region.new('BOTTOMS') }.to raise_error(ArgumentError)
|
13
13
|
end
|
14
14
|
it 'should create if region valid' do
|
15
|
-
expect {AEMO::Region.new('NSW')}.not_to raise_error
|
15
|
+
expect { AEMO::Region.new('NSW') }.not_to raise_error
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -31,11 +31,11 @@ describe AEMO::Region do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should have a valid region' do
|
34
|
-
expect(@nsw.send(:
|
34
|
+
expect(@nsw.send(:valid_region?, 'NSW')).to eq(true)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should have return invalid for invalid region' do
|
38
|
-
expect(@nsw.send(:
|
38
|
+
expect(@nsw.send(:valid_region?, 'BOB')).to eq(false)
|
39
39
|
end
|
40
40
|
|
41
41
|
describe 'AEMO::Region dispatch information' do
|
@@ -46,7 +46,6 @@ describe AEMO::Region do
|
|
46
46
|
expect(@nsw.current_trading.count).to eq(AEMO::Market.current_trading(@nsw.abbr).count)
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
50
49
|
end
|
51
50
|
|
52
51
|
describe 'AEMO::Region class methods' do
|
data/spec/spec_helper.rb
CHANGED
@@ -2,55 +2,58 @@ require 'coveralls'
|
|
2
2
|
require 'simplecov'
|
3
3
|
require 'pry'
|
4
4
|
require 'webmock/rspec'
|
5
|
+
require 'aemo'
|
5
6
|
|
6
7
|
WebMock.disable_net_connect!(allow_localhost: true)
|
7
8
|
|
8
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
10
|
+
[
|
11
|
+
SimpleCov::Formatter::HTMLFormatter,
|
12
|
+
Coveralls::SimpleCov::Formatter
|
13
|
+
]
|
14
|
+
)
|
12
15
|
SimpleCov.start
|
13
16
|
|
14
|
-
require "aemo"
|
15
|
-
|
16
17
|
RSpec.configure do |config|
|
17
18
|
# WebMock
|
18
19
|
config.before(:each) do
|
20
|
+
csv_headers = { 'Content-Type' => 'text/csv' }
|
21
|
+
xml_headers = { 'Content-Type' => 'text/xml' }
|
22
|
+
|
19
23
|
# Market Data
|
20
|
-
stub_request(:get,
|
21
|
-
with(:
|
22
|
-
to_return(status: 200, body: File.new('spec/fixtures/GRAPH_5NSW1.csv'), headers:
|
23
|
-
stub_request(:get, 'http://www.nemweb.com.au/mms.GRAPHS/GRAPHS/GRAPH_30NSW1.csv')
|
24
|
-
with(:
|
25
|
-
to_return(status: 200, body: File.new('spec/fixtures/GRAPH_30NSW1.csv'), headers:
|
24
|
+
stub_request(:get, 'http://www.nemweb.com.au/mms.GRAPHS/GRAPHS/GRAPH_5NSW1.csv')
|
25
|
+
.with(headers: { 'Accept' => '*/*', 'User-Agent' => 'Ruby' })
|
26
|
+
.to_return(status: 200, body: File.new('spec/fixtures/GRAPH_5NSW1.csv'), headers: csv_headers)
|
27
|
+
stub_request(:get, 'http://www.nemweb.com.au/mms.GRAPHS/GRAPHS/GRAPH_30NSW1.csv')
|
28
|
+
.with(headers: { 'Accept' => '*/*', 'User-Agent' => 'Ruby' })
|
29
|
+
.to_return(status: 200, body: File.new('spec/fixtures/GRAPH_30NSW1.csv'), headers: csv_headers)
|
26
30
|
|
27
31
|
# MSATS
|
28
|
-
stub_request(:get,
|
29
|
-
with(headers: {'Accept'=>['text/xml'], 'Content-Type'=>'text/xml'})
|
30
|
-
to_return(status: 200, body: File.new('spec/fixtures/MSATS/c4.xml'), headers:
|
31
|
-
stub_request(:get,
|
32
|
-
with(headers: {'Accept'=>['text/xml'], 'Content-Type'=>'text/xml'})
|
33
|
-
to_return(status: 200, body: File.new('spec/fixtures/MSATS/msats_limits.xml'), headers:
|
34
|
-
stub_request(:get,
|
35
|
-
with(headers: {'Accept'=>['text/xml'], 'Content-Type'=>'text/xml'})
|
36
|
-
to_return(status: 200, body: File.new('spec/fixtures/MSATS/nmi_details.xml'), headers:
|
37
|
-
stub_request(:get,
|
38
|
-
with(headers: {'Accept'=>['text/xml'], 'Content-Type'=>'text/xml'})
|
39
|
-
to_return(status: 200, body: File.new('spec/fixtures/MSATS/nmi_discovery_by_address.xml'), headers:
|
40
|
-
stub_request(:get,
|
41
|
-
with(headers: {'Accept'=>'text/xml', 'Content-Type'=>'text/xml'})
|
42
|
-
to_return(status: 200, body: File.new('spec/fixtures/MSATS/participant_system_status.xml'), headers:
|
32
|
+
stub_request(:get, %r{msats.prod.nemnet.net.au\/msats\/ws\/C4\/ER})
|
33
|
+
.with(headers: { 'Accept' => ['text/xml'], 'Content-Type' => 'text/xml' })
|
34
|
+
.to_return(status: 200, body: File.new('spec/fixtures/MSATS/c4.xml'), headers: xml_headers)
|
35
|
+
stub_request(:get, %r{msats.prod.nemnet.net.au\/msats\/ws\/MSATSLimits\/ER})
|
36
|
+
.with(headers: { 'Accept' => ['text/xml'], 'Content-Type' => 'text/xml' })
|
37
|
+
.to_return(status: 200, body: File.new('spec/fixtures/MSATS/msats_limits.xml'), headers: xml_headers)
|
38
|
+
stub_request(:get, %r{msats.prod.nemnet.net.au\/msats\/ws\/NMIDetail\/ER})
|
39
|
+
.with(headers: { 'Accept' => ['text/xml'], 'Content-Type' => 'text/xml' })
|
40
|
+
.to_return(status: 200, body: File.new('spec/fixtures/MSATS/nmi_details.xml'), headers: xml_headers)
|
41
|
+
stub_request(:get, %r{msats.prod.nemnet.net.au\/msats\/ws\/NMIDiscovery\/ER})
|
42
|
+
.with(headers: { 'Accept' => ['text/xml'], 'Content-Type' => 'text/xml' })
|
43
|
+
.to_return(status: 200, body: File.new('spec/fixtures/MSATS/nmi_discovery_by_address.xml'), headers: xml_headers)
|
44
|
+
stub_request(:get, %r{msats.prod.nemnet.net.au\/msats\/ws\/ParticipantSystemStatus\/ER})
|
45
|
+
.with(headers: { 'Accept' => 'text/xml', 'Content-Type' => 'text/xml' })
|
46
|
+
.to_return(status: 200, body: File.new('spec/fixtures/MSATS/participant_system_status.xml'), headers: xml_headers)
|
43
47
|
# MSATS ERRORS
|
44
|
-
stub_request(:get,
|
45
|
-
with(headers: {'Accept'=>['text/xml'], 'Content-Type'=>'text/xml'})
|
46
|
-
to_return(status: 404, body:
|
47
|
-
stub_request(:get,
|
48
|
-
with(headers: {'Accept'=>['text/xml'], 'Content-Type'=>'text/xml'})
|
49
|
-
to_return(status: 404, body:
|
48
|
+
stub_request(:get, %r{msats.prod.nemnet.net.au\/msats\/ws\/C4\/ER\?.+?NMI=4001234566.+?})
|
49
|
+
.with(headers: { 'Accept' => ['text/xml'], 'Content-Type' => 'text/xml' })
|
50
|
+
.to_return(status: 404, body: '', headers: xml_headers)
|
51
|
+
stub_request(:get, %r{msats.prod.nemnet.net.au\/msats\/ws\/NMIDetail\/ER\?.+?nmi=4001234566.+?})
|
52
|
+
.with(headers: { 'Accept' => ['text/xml'], 'Content-Type' => 'text/xml' })
|
53
|
+
.to_return(status: 404, body: '', headers: xml_headers)
|
50
54
|
end
|
51
55
|
|
52
|
-
config.order =
|
53
|
-
|
56
|
+
config.order = 'random'
|
54
57
|
end
|
55
58
|
|
56
59
|
def fixture(filename)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aemo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Courtney
|
@@ -293,6 +293,20 @@ dependencies:
|
|
293
293
|
- - ">="
|
294
294
|
- !ruby/object:Gem::Version
|
295
295
|
version: '0'
|
296
|
+
- !ruby/object:Gem::Dependency
|
297
|
+
name: rubocop
|
298
|
+
requirement: !ruby/object:Gem::Requirement
|
299
|
+
requirements:
|
300
|
+
- - ">="
|
301
|
+
- !ruby/object:Gem::Version
|
302
|
+
version: '0'
|
303
|
+
type: :development
|
304
|
+
prerelease: false
|
305
|
+
version_requirements: !ruby/object:Gem::Requirement
|
306
|
+
requirements:
|
307
|
+
- - ">="
|
308
|
+
- !ruby/object:Gem::Version
|
309
|
+
version: '0'
|
296
310
|
description: Gem providing functionality for the Australian Energy Market Operator
|
297
311
|
data. Supports NMIs, NEM12, MSATS Web Services and more
|
298
312
|
email:
|
@@ -318,7 +332,7 @@ files:
|
|
318
332
|
- lib/data/aemo-dlf.xml
|
319
333
|
- lib/data/aemo-tni.json
|
320
334
|
- lib/data/aemo-tni.xml
|
321
|
-
- lib/data/
|
335
|
+
- lib/data/xml_to_json.rb
|
322
336
|
- spec/aemo_spec.rb
|
323
337
|
- spec/fixtures/GRAPH_30NSW1.csv
|
324
338
|
- spec/fixtures/GRAPH_5NSW1.csv
|
data/lib/data/xml-to-json.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'json'
|
3
|
-
require 'csv'
|
4
|
-
require 'active_support/all'
|
5
|
-
|
6
|
-
@path = Dir.pwd
|
7
|
-
@files = Dir.entries(@path).reject{|f| %w(. ..).include?(f)}
|
8
|
-
|
9
|
-
@mlf_data = {}
|
10
|
-
@dlf_data = {}
|
11
|
-
|
12
|
-
# Let's get the CSV Data first
|
13
|
-
|
14
|
-
# TNI to MLF
|
15
|
-
CSV.open(File.join(@path,"tni-mlf-codes.csv"), headers: true, converters: :numeric).each do |row|
|
16
|
-
@mlf_data[row["TNI"]] ||= { location: row['Location'], voltage: row['Voltage'], loss_factors: [] }
|
17
|
-
@mlf_data[row["TNI"]][:loss_factors] << { start: DateTime.parse('2015-07-01T00:00:00+1000'), finish: DateTime.parse('2016-07-01T00:00:00+1000'), value: row['FY16']}
|
18
|
-
@mlf_data[row["TNI"]][:loss_factors] << { start: DateTime.parse('2014-07-01T00:00:00+1000'), finish: DateTime.parse('2015-07-01T00:00:00+1000'), value: row['FY15']}
|
19
|
-
@mlf_data[row["TNI"]][:loss_factors] << { start: DateTime.parse('2013-07-01T00:00:00+1000'), finish: DateTime.parse('2014-07-01T00:00:00+1000'), value: row['FY14']}
|
20
|
-
end
|
21
|
-
|
22
|
-
# TNI to MLF
|
23
|
-
CSV.open(File.join(@path,"aemo-dlf-dnsp.csv"), headers: true, converters: :numeric).each do |row|
|
24
|
-
@dlf_data[row["dlf_code"]] ||= row['nsp_code']
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
# Now to create the DLF and TNI output JSON files for use
|
29
|
-
@files.select{|x| ['aemo-tni.xml','aemo-dlf.xml'].include?(x) }.each do |file|
|
30
|
-
output_file = file.gsub('.xml','.json')
|
31
|
-
output_data = {}
|
32
|
-
open_file = File.open(File.join(@path,file))
|
33
|
-
xml = Nokogiri::XML(open_file) {|c| c.options = Nokogiri::XML::ParseOptions::NOBLANKS }
|
34
|
-
open_file.close
|
35
|
-
|
36
|
-
xml.xpath("//Row").each do |row|
|
37
|
-
row_children = row.children
|
38
|
-
code = row_children.find{ |x| x.name == 'Code' }.children.first.text
|
39
|
-
output_data[code] ||= []
|
40
|
-
output_data_instance = {}
|
41
|
-
row_children.each do |row_child|
|
42
|
-
output_data_instance[row_child.name] = row_child.children.first.text
|
43
|
-
end
|
44
|
-
if file.match(/tni/)
|
45
|
-
puts "output_data_instance: #{output_data_instance.inspect}"
|
46
|
-
output_data_instance[:mlf_data] = {}
|
47
|
-
unless @mlf_data[code].nil?
|
48
|
-
output_data_instance[:mlf_data] = @mlf_data[code].deep_dup
|
49
|
-
output_data_instance[:mlf_data][:loss_factors] = output_data_instance[:mlf_data][:loss_factors].reject{|x| DateTime.parse(output_data_instance['ToDate']) < x[:start] || DateTime.parse(output_data_instance['FromDate']) >= x[:finish] }
|
50
|
-
puts "output_data_instance[:mlf_data][:loss_factors]: #{output_data_instance[:mlf_data][:loss_factors].inspect}"
|
51
|
-
end
|
52
|
-
elsif file.match(/dlf/)
|
53
|
-
output_data_instance[:nsp_code] = @dlf_data[code]
|
54
|
-
end
|
55
|
-
output_data[code] << output_data_instance
|
56
|
-
end
|
57
|
-
|
58
|
-
File.open(File.join(@path,output_file),'w') do |write_file|
|
59
|
-
write_file.write(output_data.to_json)
|
60
|
-
end
|
61
|
-
end
|