aemo 0.1.4 → 0.1.5

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.
@@ -0,0 +1,54 @@
1
+ require 'nokogiri'
2
+ require 'json'
3
+ require 'csv'
4
+
5
+ @path = Dir.pwd
6
+ @files = Dir.entries(@path).reject{|f| %w(. ..).include?(f)}
7
+
8
+ @mlf_data = {}
9
+ @dlf_data = {}
10
+
11
+ # Let's get the CSV Data first
12
+
13
+ # TNI to MLF
14
+ CSV.open(File.join(@path,"tni-mlf-codes.csv"), headers: true, converters: :numeric).each do |row|
15
+ @mlf_data[row["TNI"]] ||= { location: row['Location'], voltage: row['Voltage'], loss_factors: [] }
16
+ @mlf_data[row["TNI"]][:loss_factors] << { start: Date.parse('2014-07-01'), finish: Date.parse('2015-06-30'), value: row['FY15']}
17
+ @mlf_data[row["TNI"]][:loss_factors] << { start: Date.parse('2013-07-01'), finish: Date.parse('2014-06-30'), value: row['FY14']}
18
+ end
19
+
20
+ # TNI to MLF
21
+ CSV.open(File.join(@path,"aemo-dlf-dnsp.csv"), headers: true, converters: :numeric).each do |row|
22
+ @dlf_data[row["dlf_code"]] ||= row['nsp_code']
23
+ end
24
+
25
+
26
+ # Now to create the DLF and TNI output JSON files for use
27
+ @files.select{|x| ['aemo-tni.xml','aemo-dlf.xml'].include?(x) }.each do |file|
28
+ output_file = file.gsub('.xml','.json')
29
+ output_data = {}
30
+ open_file = File.open(File.join(@path,file))
31
+ xml = Nokogiri::XML(open_file) {|c| c.options = Nokogiri::XML::ParseOptions::NOBLANKS }
32
+ open_file.close
33
+
34
+ xml.xpath("//Row").each do |row|
35
+ row_children = row.children
36
+ code = row_children.find{ |x| x.name == 'Code' }.children.first.text
37
+ output_data[code] ||= []
38
+ output_data_instance = {}
39
+ row_children.each do |row_child|
40
+ output_data_instance[row_child.name] = row_child.children.first.text
41
+ end
42
+ if file.match(/tni/)
43
+ output_data_instance[:mlf_data] = @mlf_data[code]
44
+ elsif file.match(/dlf/)
45
+ output_data_instance[:nsp_code] = @dlf_data[code]
46
+ end
47
+ output_data[code] << output_data_instance
48
+ end
49
+
50
+ File.open(File.join(@path,output_file),'w') do |write_file|
51
+ write_file.write(output_data.to_json)
52
+ end
53
+ end
54
+
@@ -31,7 +31,6 @@ describe AEMO::NEM12 do
31
31
  describe '.parse_nem12_file' do
32
32
  it 'should parse a file' do
33
33
  Dir.entries(File.join(File.dirname(__FILE__),'..','fixtures','NEM12')).reject{|f| %w(. .. .DS_Store).include?(f)}.each do |file|
34
- puts file
35
34
  nem12 = AEMO::NEM12.parse_nem12_file(File.join(File.dirname(__FILE__),'..','fixtures','NEM12',file))
36
35
  end
37
36
  end
@@ -0,0 +1,131 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+ require 'json'
3
+
4
+ describe AEMO::NMI do
5
+ # ---
6
+ # CLASS CONSTANTS
7
+ # ---
8
+ describe '::NMI_ALLOCATIONS' do
9
+ it "should be a hash" do
10
+ expect(AEMO::NMI::NMI_ALLOCATIONS.class).to eq(Hash)
11
+ end
12
+ end
13
+ describe '::TNI_CODES' do
14
+ it "should be a hash" do
15
+ expect(AEMO::NMI::TNI_CODES.class).to eq(Hash)
16
+ end
17
+ end
18
+ describe '::DLF_CODES' do
19
+ it "should be a hash" do
20
+ expect(AEMO::NMI::DLF_CODES.class).to eq(Hash)
21
+ end
22
+ end
23
+
24
+ # ---
25
+ # CLASS METHODS
26
+ # ---
27
+ describe '.valid_nmi?(nmi)' do
28
+ it 'should validate nmi' do
29
+ JSON.parse(File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures','nmi_checksum.json')))).each do |nmi|
30
+ expect(AEMO::NMI.valid_nmi?(nmi['nmi'])).to eq(true)
31
+ end
32
+ end
33
+ it "should invalidate" do
34
+ expect(AEMO::NMI.valid_nmi?("OOOOOOOOOO")).to eq(false)
35
+ end
36
+ it "should invalidate" do
37
+ expect(AEMO::NMI.valid_nmi?("NM100")).to eq(false)
38
+ end
39
+ it "should invalidate" do
40
+ expect{AEMO::NMI.valid_nmi?()}.to raise_error(ArgumentError)
41
+ end
42
+ end
43
+
44
+ describe '.self.valid_checksum?(nmi,checksum)' do
45
+ it 'should validate valid nmi and checksums' do
46
+ JSON.parse(File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures','nmi_checksum.json')))).each do |nmi|
47
+ expect(AEMO::NMI.valid_checksum?(nmi['nmi'],nmi['checksum'])).to eq(true)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '.self.network?(nmi)' do
53
+ it 'should return a network for an allocated NMI' do
54
+ network = AEMO::NMI.network('NCCCC00000')
55
+ expect(network.to_a[0].last[:title]).to eq('Ausgrid')
56
+ end
57
+ it 'should return NIL for an unallocated NMI' do
58
+ network = AEMO::NMI.network('ZZZZZZZZZZZZ')
59
+ expect(network).to eq(nil)
60
+ end
61
+ end
62
+
63
+ # ---
64
+ # INSTANCE METHODS
65
+ # ---
66
+ describe '#initialize' do
67
+ it "should raise an ArgumentError error" do
68
+ expect{ AEMO::NMI.new("OOOOOOOOOO") }.to raise_error(ArgumentError)
69
+ end
70
+ it "should raise an ArgumentError error" do
71
+ expect{ AEMO::NMI.new("NM100") }.to raise_error(ArgumentError)
72
+ end
73
+ it "should raise an ArgumentError error" do
74
+ expect{ AEMO::NMI.new() }.to raise_error(ArgumentError)
75
+ end
76
+ end
77
+ describe '#valid_nmi?' do
78
+ it 'should validate nmi' do
79
+ JSON.parse(File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures','nmi_checksum.json')))).each do |nmi|
80
+ _nmi = AEMO::NMI.new(nmi['nmi'])
81
+ expect(_nmi.valid_nmi?).to eq(true)
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#checksum' do
87
+ it 'should return NMI\'s checksum' do
88
+ JSON.parse(File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures','nmi_checksum.json')))).each do |nmi|
89
+ _nmi = AEMO::NMI.new(nmi['nmi'])
90
+ expect(_nmi.checksum).to eq(nmi['checksum'])
91
+ end
92
+ end
93
+ end
94
+
95
+ describe '#valid_checksum?(checksum)' do
96
+ it 'should validate valid checksums' do
97
+ JSON.parse(File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures','nmi_checksum.json')))).each do |nmi|
98
+ _nmi = AEMO::NMI.new(nmi['nmi'])
99
+ expect(_nmi.valid_checksum?(nmi['checksum'])).to eq(true)
100
+ end
101
+ end
102
+ it 'should not validate invalid checksums' do
103
+ JSON.parse(File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures','nmi_checksum.json')))).each do |nmi|
104
+ _nmi = AEMO::NMI.new(nmi['nmi'])
105
+ expect(_nmi.valid_checksum?((1+nmi['checksum'])%10)).to eq(false)
106
+ end
107
+ end
108
+ end
109
+
110
+ describe '#network' do
111
+ # Positive test cases
112
+ it 'should return a network for a valid NMI' do
113
+ JSON.parse(File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures','nmi_checksum.json')))).each do |nmi|
114
+ _nmi = AEMO::NMI.new(nmi['nmi'])
115
+ unless _nmi.network.nil?
116
+ expect(_nmi.network.class).to eq(Hash)
117
+ end
118
+ end
119
+ end
120
+ # Negative test cases
121
+ it 'should not return a network for a NMI not allocated to a network' do
122
+ JSON.parse(File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures','nmi_checksum.json')))).each do |nmi|
123
+ _nmi = AEMO::NMI.new(nmi['nmi'])
124
+ if _nmi.network.nil?
125
+ expect(_nmi.network.class).to eq(NilClass)
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  require 'aemo'
4
- require 'aemo/nem12'
4
+ require 'aemo/nem12'
5
+ # require 'aemo/nmi'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aemo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Courtney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-05 00:00:00.000000000 Z
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -72,6 +72,7 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
+ - ".gitignore"
75
76
  - Gemfile
76
77
  - Gemfile.lock
77
78
  - README.md
@@ -80,12 +81,21 @@ files:
80
81
  - lib/aemo/dispatchable.rb
81
82
  - lib/aemo/market.rb
82
83
  - lib/aemo/market/interval.rb
84
+ - lib/aemo/msats.rb
83
85
  - lib/aemo/nem12.rb
84
86
  - lib/aemo/nem13.rb
85
87
  - lib/aemo/nmi.rb
86
88
  - lib/aemo/region.rb
89
+ - lib/data/TNI-MLF-Codes.csv
90
+ - lib/data/aemo-dlf-dnsp.csv
91
+ - lib/data/aemo-dlf.json
92
+ - lib/data/aemo-dlf.xml
93
+ - lib/data/aemo-tni.json
94
+ - lib/data/aemo-tni.xml
95
+ - lib/data/xml-to-json.rb
87
96
  - spec/aemo/market_spec.rb
88
97
  - spec/aemo/nem12_spec.rb
98
+ - spec/aemo/nmi_spec.rb
89
99
  - spec/aemo/region_spec.rb
90
100
  - spec/aemo_spec.rb
91
101
  - spec/fixtures/GRAPH_30NSW1.csv
@@ -192,7 +202,7 @@ files:
192
202
  - spec/fixtures/nmi_checksum.json
193
203
  - spec/spec.opts
194
204
  - spec/spec_helper.rb
195
- homepage: https://bitbucket.org/jufemaiz/aemo-gem
205
+ homepage: https://github.com/jufemaiz/aemo
196
206
  licenses:
197
207
  - MIT
198
208
  metadata: {}
@@ -219,6 +229,7 @@ summary: AEMO Gem
219
229
  test_files:
220
230
  - spec/aemo/market_spec.rb
221
231
  - spec/aemo/nem12_spec.rb
232
+ - spec/aemo/nmi_spec.rb
222
233
  - spec/aemo/region_spec.rb
223
234
  - spec/aemo_spec.rb
224
235
  - spec/fixtures/GRAPH_30NSW1.csv
@@ -325,3 +336,4 @@ test_files:
325
336
  - spec/fixtures/nmi_checksum.json
326
337
  - spec/spec.opts
327
338
  - spec/spec_helper.rb
339
+ has_rdoc: