Skip to content

Commit

Permalink
Merge d798762 into feb47eb
Browse files Browse the repository at this point in the history
  • Loading branch information
sjauld committed May 1, 2018
2 parents feb47eb + d798762 commit 013f42c
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 31 deletions.
23 changes: 8 additions & 15 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-08-02 10:14:31 +1000 using RuboCop version 0.41.2.
# on 2018-05-01 11:12:22 +1000 using RuboCop version 0.50.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -10,6 +10,11 @@
Metrics/AbcSize:
Max: 165

# Offense count: 1
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 35

# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ClassLength:
Expand All @@ -19,8 +24,8 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 29

# Offense count: 193
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# Offense count: 191
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 192
Expand All @@ -33,15 +38,3 @@ Metrics/MethodLength:
# Offense count: 7
Metrics/PerceivedComplexity:
Max: 29

# Offense count: 43
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'lib/aemo/market/node.rb'
- 'lib/aemo/msats.rb'
- 'lib/aemo/nem12.rb'
- 'lib/aemo/region.rb'
- 'lib/data/xml_to_json.rb'
- 'spec/lib/aemo/nem12_spec.rb'
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ bundler_args: --retry=3 --jobs=3
cache: bundler
sudo: false
rvm:
- 2.6.0-preview1
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
Expand All @@ -26,7 +30,9 @@ rvm:
- ruby-head
matrix:
allow_failures:
- rvm: ruby-head
- rvm:
- ruby-head
- 2.6.0-preview1
fast_finish: true
install:
- bundle install
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# AEMO Gem Changelog

## 0.2.0

* Default NEM12 parsing to use strict validation
* Only enforce validation of NMIConfiguration in strict mode

## 0.1.45

* [Nokogiri vulnerability](https://rubysec.com/advisories/nokogiri-CVE-2017-15412) update
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
aemo (0.1.45)
aemo (0.2.0)
activesupport (>= 4.2.6, < 5.2)
httparty (~> 0.15, >= 0.15.6)
json (>= 1.7.5)
Expand All @@ -11,9 +11,9 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (5.1.4)
activesupport (5.1.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.4.0)
Expand Down Expand Up @@ -61,9 +61,9 @@ GEM
hashdiff (0.3.7)
hashie (3.5.6)
highline (1.7.8)
httparty (0.15.7)
httparty (0.16.2)
multi_xml (>= 0.5.2)
i18n (0.9.3)
i18n (1.0.1)
concurrent-ruby (~> 1.0)
jeweler (2.3.7)
builder
Expand Down
3 changes: 2 additions & 1 deletion lib/aemo/market/interval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Interval
dispatch: 'Dispatch'
}.freeze

attr_accessor :datetime, :region, :total_demand, :rrp, :period_type
attr_accessor :region, :total_demand, :rrp, :period_type
attr_writer :datetime

# Create a new instance of an Interval
#
Expand Down
10 changes: 5 additions & 5 deletions lib/aemo/nem12.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ def self.parse_nem12_100(line, options = {})
# Parses the NMI Data Details
# @param [String] line A single line in string format
# @return [Hash] the line parsed into a hash of information
def parse_nem12_200(line, _options = {})
def parse_nem12_200(line, options = {})
csv = line.parse_csv

raise ArgumentError, 'RecordIndicator is not 200' if csv[0] != '200'
raise ArgumentError, 'NMI is not valid' unless AEMO::NMI.valid_nmi?(csv[1])
if csv[2].nil? || csv[2].match(/.{1,240}/).nil?
if options[:strict] && (csv[2].nil? || csv[2].match(/.{1,240}/).nil?)
raise ArgumentError, 'NMIConfiguration is not valid'
end
if !csv[3].nil? && csv[3].match(/.{1,10}/).nil?
Expand Down Expand Up @@ -514,14 +514,14 @@ def to_csv

# @param [String] path_to_file the path to a file
# @return [Array<AEMO::NEM12>] NEM12 object
def self.parse_nem12_file(path_to_file, strict = false)
def self.parse_nem12_file(path_to_file, strict = true)
parse_nem12(File.read(path_to_file), strict)
end

# @param [String] contents the path to a file
# @param [Boolean] strict
# @return [Array<AEMO::NEM12>] An array of NEM12 objects
def self.parse_nem12(contents, strict = false)
def self.parse_nem12(contents, strict = true)
file_contents = contents.tr("\r", "\n").tr("\n\n", "\n").split("\n").delete_if(&:empty?)
raise ArgumentError, 'First row should be have a RecordIndicator of 100 and be of type Header Record' unless file_contents.first.parse_csv[0] == '100'

Expand All @@ -531,7 +531,7 @@ def self.parse_nem12(contents, strict = false)
case line[0..2].to_i
when 200
nem12s << AEMO::NEM12.new('')
nem12s.last.parse_nem12_200(line)
nem12s.last.parse_nem12_200(line, strict: strict)
when 300
nem12s.last.parse_nem12_300(line)
when 400
Expand Down
2 changes: 1 addition & 1 deletion lib/aemo/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# @author Joel Courtney <euphemize@gmail.com>
module AEMO
# aemo version
VERSION = '0.1.45'
VERSION = '0.2.0'.freeze

# aemo version split amongst different revisions
MAJOR_VERSION, MINOR_VERSION, REVISION = VERSION.split('.').map(&:to_i)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
100,NEM12,200505181432,CNRGYMDP,NEMMCO
200,NEM1201002,,E1,E1,N1,01002,KWH,30,
300,20050315,300.000,266.100,191.550,247.800,288.600,280.800,282.450,206.100,204.750,289.500,390.600,360.150,407.700,432.600,435.000,491.850,600.900,541.950,474.600,565.350,548.550,491.850,593.250,602.400,571.350,450.150,509.400,559.950,522.000,520.950,541.200,538.050,484.800,330.900,329.250,331.650,330.750,333.750,335.250,294.150,185.250,184.800,186.450,256.800,329.700,320.100,316.500,321.150,A,,,20050316014209,
200,NEM1201002,E1E2,E2,E2,N2,01002,KWH,30,
300,20050315,113.100,87.600,33.750,60.600,81.900,79.500,81.150,39.750,25.650,58.800,174.300,197.100,390.600,392.550,394.200,418.500,484.950,407.700,407.700,466.500,455.700,386.850,486.900,489.450,465.150,360.000,387.450,458.700,381.900,424.800,446.250,444.450,383.550,172.650,154.050,164.400,164.250,174.450,170.100,110.100,44.550,44.250,39.900,72.300,109.050,102.450,103.950,103.050,A,,,20050316014209,
200,NEM1201002,E1E2,E1,E1,N1,01002,KWH,30,
300,20050316,321.900,326.400,302.700,298.650,304.500,295.350,309.750,312.300,312.000,338.100,376.950,411.900,546.450,548.250,497.850,528.450,580.800,525.000,435.600,569.400,587.400,577.050,487.350,492.150,588.450,455.550,553.650,515.400,539.700,561.600,540.300,555.600,493.800,349.500,323.700,321.300,322.200,317.550,318.450,324.450,324.600,324.600,321.900,318.750,318.600,317.850,317.100,321.300,A,,,20050317032944,
200,NEM1201002,E1E2,E2,E2,N2,01002,KWH,30,
300,20050316,104.850,103.500,82.950,64.800,72.300,71.400,72.900,80.100,94.500,121.050,185.100,282.900,427.800,427.950,322.800,381.450,464.400,413.400,332.250,442.950,472.800,466.350,401.550,400.200,470.700,352.800,426.300,381.300,435.450,453.750,433.200,453.000,388.350,226.050,148.050,149.550,142.650,115.650,105.750,107.100,109.350,111.450,107.100,104.250,103.050,101.850,103.200,107.550,A,,,20050317032944,
200,NEM1201002,E1E2,E1,E1,N1,01002,KWH,30,
300,20050317,322.350,318.000,302.400,294.450,298.650,296.400,315.150,315.600,326.550,358.200,389.700,397.200,513.150,511.200,520.650,510.300,543.450,549.900,419.850,529.200,527.850,506.100,535.050,538.050,369.600,380.850,555.150,558.600,477.900,334.500,337.200,335.250,339.150,335.550,316.200,312.750,312.600,320.250,320.250,315.750,317.250,315.600,314.700,315.300,315.000,315.750,314.400,315.900,A,,,20050318014032,
200,NEM1201002,E1E2,E2,E2,N2,01002,KWH,30,
300,20050317,104.100,100.800,85.800,70.500,70.950,69.450,53.250,55.650,66.600,106.800,182.100,266.550,408.900,402.150,410.700,414.450,436.200,427.800,325.350,442.200,439.200,432.150,435.300,418.800,283.500,294.000,450.450,455.400,368.400,156.000,160.500,137.550,138.000,134.400,112.350,105.600,103.350,111.750,111.150,107.550,106.500,103.950,102.300,105.750,103.800,97.500,99.750,102.000,A,,,20050318014032,
200,NEM1201002,E1E2,E1,E1,N1,01002,KWH,30,
300,20050318,315.150,313.800,296.550,298.500,295.200,298.950,300.750,322.950,330.450,350.700,345.750,346.950,345.900,348.600,300.150,337.500,336.750,345.900,330.450,327.150,334.800,345.750,335.850,320.100,325.500,325.200,326.400,330.600,332.700,332.250,321.000,316.500,299.850,302.400,301.050,263.850,255.450,142.050,138.300,138.300,136.800,138.300,136.050,135.750,135.750,136.650,136.050,130.800,A,,,20050319014041,
200,NEM1201002,E1E2,E2,E2,N2,01002,KWH,30,
300,20050318,103.050,98.850,81.150,75.600,72.150,73.950,74.550,81.150,89.250,124.200,125.700,128.700,136.800,151.050,177.900,174.450,204.000,210.150,180.150,164.400,187.950,211.950,193.800,122.850,124.800,121.200,129.300,131.250,130.950,130.050,118.050,105.750,77.100,75.900,75.000,51.150,44.400,12.300,12.750,12.150,12.450,11.550,14.400,14.550,15.000,14.700,15.750,21.900,A,,,20050319014041,
900
16 changes: 13 additions & 3 deletions spec/lib/aemo/nem12_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@
end

describe '#parse_nem12_200' do
# before(:each) do
# @nem12 = AEMO::NEM12.parse_nem12_100('100,NEM12,201603010000,CNRGYMDP,NEMMCO', strict: true)
# end
context 'non-strict mode' do
it 'should not raise validation warning with bad NMI configuration' do
expect(AEMO::NEM12.parse_nem12_file(fixture(File.join('NEM12-Errors', 'NEM12#DerpyNMIConfig#CNRGYMDP#NEMMCO.csv')), false))
.to be_truthy
end
end

context 'strict mode (default)' do
it 'should raise validation warning with bad NMI configuration' do
expect { AEMO::NEM12.parse_nem12_file(fixture(File.join('NEM12-Errors', 'NEM12#DerpyNMIConfig#CNRGYMDP#NEMMCO.csv'))) }
.to raise_error(ArgumentError, 'NMIConfiguration is not valid')
end
end
end

describe '#parse_nem12_300' do
Expand Down

0 comments on commit 013f42c

Please sign in to comment.