pvwatts-ee 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ # gem "rcov", ">= 0"
13
+ gem 'savon', '~> 0.7.6'
14
+ gem 'yard', '>= 0.6.4'
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.0.0)
5
+ crack (0.1.8)
6
+ diff-lcs (1.1.2)
7
+ git (1.2.5)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rake (0.8.7)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+ savon (0.7.9)
22
+ builder (>= 2.1.2)
23
+ crack (>= 0.1.4)
24
+ yard (0.6.4)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.0.0)
31
+ jeweler (~> 1.5.2)
32
+ rspec (~> 2.3.0)
33
+ savon (~> 0.7.6)
34
+ yard (>= 0.6.4)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Solar Universe, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,21 @@
1
+ = pvwatts
2
+
3
+ Wrapper around the http://www.nrel.gov/rredc/pvwatts/ web service API which calculates the Performance of a Grid-Connected PV System.
4
+
5
+ For more information see http://rubydoc.info/gems/pvwatts/
6
+
7
+ == Contributing to pvwatts
8
+
9
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
10
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
11
+ * Fork the project
12
+ * Start a feature/bugfix branch
13
+ * Commit and push until you are happy with your contribution
14
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
16
+
17
+ == Copyright
18
+
19
+ Copyright (c) 2011 Solar Universe, LLC. See LICENSE.txt for
20
+ further details.
21
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "pvwatts"
16
+ gem.homepage = "http://github.com/bstrech/pvwatts"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Wrapper around the http://www.nrel.gov/rredc/pvwatts/ web service API. Forked from Matt Aimonetti.}
19
+ gem.description = %Q{Calculates the Performance of a Grid-Connected PV System.}
20
+ gem.email = "bstrech@gmail.com"
21
+ gem.authors = ["Brenda Strech"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'savon', '~> 0.7.6'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ task :default => :spec
36
+
37
+ require 'yard'
38
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/pvwatts.rb ADDED
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require 'savon'
3
+
4
+ # Wrapper around the http://www.nrel.gov/rredc/pvwatts/ web service API.
5
+ # Calculates the Performance of a Grid-Connected PV System.
6
+ # Use of the Pvwatts web service is restricted to authorized users.
7
+ # For information on obtaining authorization, contact bill_marion@nrel.gov
8
+ #
9
+ # @see http://www.nrel.gov/rredc/pvwatts/
10
+ #
11
+ # @author Matt Aimonetti for http://solaruniverse.com
12
+ #
13
+ class Pvwatts
14
+
15
+ Savon::Request.log = false
16
+
17
+ attr_reader :api_key
18
+
19
+ # Create an instance of the API wrapper.
20
+ #
21
+ # @param [String] api_key The Pvwatts API key provided by bill_marion@nrel.gov
22
+ #
23
+ def initialize(api_key)
24
+ @api_key = api_key
25
+ end
26
+
27
+ # Calculate the estimated yearly production based on passed options.
28
+ #
29
+ # @param [Hash] opts
30
+ # @option opts [String, Float] :latitude Latitude coordinate of the location.
31
+ # @option opts [String, Float] :longitude Longitude coordinate of the location.
32
+ # @option opts [String, Float] :dc_rating kW rating values 0.5 to 10000.0
33
+ # @option opts [String, Float] :tilt PV Array Lattitude tilt value 0 - 90
34
+ # @option opts [String, Integer] :azimuth azimuth value 0 - 360 (180 for Northern Hemisphere).
35
+ # @option opts [String, Float] :derate overall DC to AC derate factor values 0.10 - 0.96
36
+ # @option opts [String, Float] :cost electricity cost per kWh (US ¢/kWh)
37
+ # @options opts [String, Integer] :array_type 0=fixed tilt, 1=1-axis tracking, 2=2-axis tracking
38
+ # @return [Hash] A hash with the yearly production with a key for each month and a 'year' key to represent the yearly value.
39
+ #
40
+ def yearly_production(opts={})
41
+ Rails.logger.debug("pvwatts yearly prod called") if Object.const_defined?(:Rails)
42
+ keys = opts.keys
43
+ client = Savon::Client.new("http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL")
44
+ @latitude, @longitude = [opts[:latitude], opts[:longitude]]
45
+ @dc_rating, @tilt, @azimuth, @derate = opts[:dc_rating], opts[:tilt], opts[:azimuth], opts[:derate]
46
+ if @latitude.nil? || @longitude.nil? || @dc_rating.nil? || @tilt.nil? || @azimuth.nil? || @derate.nil?
47
+ raise ArgumentError, "passed -> latitude: #{@latitude}, longitude: #{@longitude}, dc_rating: #{@dc_rating}\
48
+ tilt: #{@tilt} azimuth: #{@azimuth} derate: #{@derate}"
49
+ end
50
+ req = prep_request(@latitude, @longitude, @dc_rating, @tilt, @azimuth, @derate, @array_type, @cost)
51
+
52
+ response = client.get_pvwatts{|soap| soap.input = "GetPVWATTS"; soap.body = req }
53
+ rdata = response.to_hash
54
+ if rdata[:get_pvwatts_response] && rdata[:get_pvwatts_response][:get_pvwatts_result] && rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo]
55
+ @production_data = {}
56
+ @pvwatt_info = rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo].compact
57
+ @pvwatt_info.each do |el|
58
+ if el.respond_to?(:has_key?) && el.has_key?(:month)
59
+ @production_data[el[:month].downcase] = el[:a_cenergy].to_i
60
+ end
61
+ end
62
+ else
63
+ raise 'Problem with the pvwatts response'
64
+ end
65
+ @production_data
66
+ end
67
+
68
+ private
69
+
70
+ def prep_request(latitude, longitude, dc_rating, tilt, azimuth, derate, array_type, cost=0.0)
71
+ Rails.logger.debug "calling pvwatts with: latitude: #{latitude}, longitude: #{longitude}, dc_rating: #{dc_rating}, tilt: #{tilt}, azimuth: #{azimuth}, dc_derate: #{derate}, cost: #{cost}, array_type: #{array_type}" if Object.const_defined?(:Rails)
72
+ shading = (shading == 0 ? 1 : shading / 100)
73
+ { 'wsdl:key' => api_key,
74
+ 'wsdl:latitude' => latitude,
75
+ 'wsdl:longitude' => longitude,
76
+ 'wsdl:locationID' => '',
77
+ 'wsdl:DCrating' => dc_rating,
78
+ 'wsdl:derate' => derate,
79
+ 'wsdl:cost' => cost,
80
+ 'wsdl:mode' => array_type,
81
+ 'wsdl:tilt' => tilt,
82
+ 'wsdl:azimuth' => azimuth,
83
+ 'wsdl:inoct' => 45.0,
84
+ 'wsdl:pwrdgr' => -0.005
85
+ }
86
+ end
87
+
88
+ end
data/pvwatts.gemspec ADDED
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pvwatts-ee}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matt Aimonetti", "Brenda Strech"]
12
+ s.date = %q{2011-06-17}
13
+ s.description = %q{Calculates the Performance of a Grid-Connected PV System.}
14
+ s.email = %q{bstrech@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/pvwatts.rb",
29
+ "pvwatts.gemspec",
30
+ "spec/pvwatts_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/mattetti/pvwatts}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{Wrapper around the http://www.nrel.gov/rredc/pvwatts/ web service API.}
38
+ s.test_files = [
39
+ "spec/pvwatts_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_development_dependency(%q<savon>, ["~> 0.7.6"])
52
+ s.add_development_dependency(%q<yard>, [">= 0.6.4"])
53
+ s.add_runtime_dependency(%q<savon>, ["~> 0.7.6"])
54
+ else
55
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
58
+ s.add_dependency(%q<savon>, ["~> 0.7.6"])
59
+ s.add_dependency(%q<yard>, [">= 0.6.4"])
60
+ s.add_dependency(%q<savon>, ["~> 0.7.6"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
+ s.add_dependency(%q<savon>, ["~> 0.7.6"])
67
+ s.add_dependency(%q<yard>, [">= 0.6.4"])
68
+ s.add_dependency(%q<savon>, ["~> 0.7.6"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Pvwatts do
4
+
5
+ before(:all) do
6
+ @pdata = Pvwatts.new(PVWATTS_SPEC_KEY).yearly_production(:latitude => 32.95850,
7
+ :longitude => -117.12206,
8
+ :dc_rating => 4.0,
9
+ :tilt => 45,
10
+ :azimuth => 180,
11
+ :derate => 0.82,
12
+ :array_type=>0,
13
+ :cost=>0.1)
14
+ end
15
+
16
+ it "should fetch the yearly production data" do
17
+ @pdata['jan'].should == 496
18
+ @pdata['feb'].should == 469
19
+ @pdata['mar'].should == 539
20
+ @pdata['apr'].should == 525
21
+ @pdata['may'].should == 539
22
+ @pdata['jun'].should == 498
23
+ @pdata['jul'].should == 526
24
+ @pdata['aug'].should == 554
25
+ @pdata['sep'].should == 540
26
+ @pdata['oct'].should == 536
27
+ @pdata['nov'].should == 508
28
+ @pdata['dec'].should == 471
29
+ @pdata['year'].should == 6203
30
+ end
31
+
32
+ end
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'pvwatts'
5
+ require 'savon'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ # Set this constant to run the tests
12
+ PVWATTS_SPEC_KEY = nil
13
+ raise "You first need to set the PVWATTS_SPEC_KEY constant in spec_helper.rb" if PVWATTS_SPEC_KEY.nil?
14
+
15
+ RSpec.configure do |config|
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pvwatts-ee
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Matt Aimonetti
14
+ - Brenda Strech
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-06-17 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 2
33
+ - 3
34
+ - 0
35
+ version: 2.3.0
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 23
47
+ segments:
48
+ - 1
49
+ - 0
50
+ - 0
51
+ version: 1.0.0
52
+ type: :development
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: jeweler
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ hash: 7
63
+ segments:
64
+ - 1
65
+ - 5
66
+ - 2
67
+ version: 1.5.2
68
+ type: :development
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: savon
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ hash: 15
79
+ segments:
80
+ - 0
81
+ - 7
82
+ - 6
83
+ version: 0.7.6
84
+ type: :development
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: yard
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 15
95
+ segments:
96
+ - 0
97
+ - 6
98
+ - 4
99
+ version: 0.6.4
100
+ type: :development
101
+ version_requirements: *id005
102
+ - !ruby/object:Gem::Dependency
103
+ name: savon
104
+ prerelease: false
105
+ requirement: &id006 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ hash: 15
111
+ segments:
112
+ - 0
113
+ - 7
114
+ - 6
115
+ version: 0.7.6
116
+ type: :runtime
117
+ version_requirements: *id006
118
+ description: Calculates the Performance of a Grid-Connected PV System.
119
+ email: bstrech@gmail.com
120
+ executables: []
121
+
122
+ extensions: []
123
+
124
+ extra_rdoc_files:
125
+ - LICENSE.txt
126
+ - README.rdoc
127
+ files:
128
+ - .document
129
+ - .rspec
130
+ - Gemfile
131
+ - Gemfile.lock
132
+ - LICENSE.txt
133
+ - README.rdoc
134
+ - Rakefile
135
+ - VERSION
136
+ - lib/pvwatts.rb
137
+ - pvwatts.gemspec
138
+ - spec/pvwatts_spec.rb
139
+ - spec/spec_helper.rb
140
+ has_rdoc: true
141
+ homepage: http://github.com/mattetti/pvwatts
142
+ licenses:
143
+ - MIT
144
+ post_install_message:
145
+ rdoc_options: []
146
+
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ requirements: []
168
+
169
+ rubyforge_project:
170
+ rubygems_version: 1.3.7
171
+ signing_key:
172
+ specification_version: 3
173
+ summary: Wrapper around the http://www.nrel.gov/rredc/pvwatts/ web service API.
174
+ test_files:
175
+ - spec/pvwatts_spec.rb
176
+ - spec/spec_helper.rb