pvwatts 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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)
@@ -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.
@@ -0,0 +1,19 @@
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
+ == Contributing to pvwatts
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * 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.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Solar Universe, LLC. See LICENSE.txt for
18
+ further details.
19
+
@@ -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/mattetti/pvwatts"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Wrapper around the http://www.nrel.gov/rredc/pvwatts/ web service API.}
19
+ gem.description = %Q{Calculates the Performance of a Grid-Connected PV System.}
20
+ gem.email = "mattaimonetti@gmail.com"
21
+ gem.authors = ["Matt Aimonetti"]
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
@@ -0,0 +1,90 @@
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
+ DEFAULT_DERATE = 0.82
17
+
18
+ attr_reader :api_key
19
+
20
+ # Create an instance of the API wrapper.
21
+ #
22
+ # @param [String] api_key The Pvwatts API key provided by bill_marion@nrel.gov
23
+ #
24
+ def initialize(api_key)
25
+ @api_key = api_key
26
+ end
27
+
28
+ # Calculate the estimated yearly production based on passed options.
29
+ #
30
+ # @param [Hash] opts
31
+ # @option opts [String, Float] :latitude Latitude coordinate of the location.
32
+ # @option opts [String, Float] :longitude Longitude coordinate of the location.
33
+ # @option opts [String, Float] :dc_rating
34
+ # @option opts [String, Integer] :tilt
35
+ # @option opts [String, Integer] :orientation Orientation or azimuth value.
36
+ # @option opts [String, Integer] :shading A percentage value between 0 and 100.
37
+ #
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, @orientation = opts[:dc_rating], opts[:tilt], opts[:orientation]
46
+ @shading = opts[:shading]
47
+ if @latitude.nil? || @longitude.nil? || @dc_rating.nil? || @tilt.nil? || @orientation.nil? || @shading.nil?
48
+ raise ArgumentError, "passed -> latitude: #{@latitude}, longitude: #{@longitude}, dc_rating: #{@dc_rating}\
49
+ tilt: #{@tilt} orientation: #{@orientation} shading: #{@shading}"
50
+ end
51
+ req = prep_request(@latitude, @longitude, @dc_rating, @tilt, @orientation, @shading)
52
+
53
+ response = client.get_pvwatts{|soap| soap.input = "GetPVWATTS"; soap.body = req }
54
+ rdata = response.to_hash
55
+ if rdata[:get_pvwatts_response] && rdata[:get_pvwatts_response][:get_pvwatts_result] && rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo]
56
+ @production_data = {}
57
+ @pvwatt_info = rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo].compact
58
+ @pvwatt_info.each do |el|
59
+ if el.respond_to?(:has_key?) && el.has_key?(:month)
60
+ @production_data[el[:month].downcase] = el[:a_cenergy].to_i
61
+ end
62
+ end
63
+ else
64
+ raise 'Problem with the pvwatts response'
65
+ end
66
+ @production_data
67
+ end
68
+
69
+ private
70
+
71
+ def prep_request(latitude, longitude, dc_rating, tilt, orientation, shading)
72
+ Rails.logger.debug "calling pvwatts with: latitude: #{latitude}, longitude: #{longitude}, dc_rating: #{dc_rating}, tilt: #{tilt}, orientation: #{orientation}, shading: #{shading}" if Object.const_defined?(:Rails)
73
+ shading = (shading == 0 ? 1 : shading / 100)
74
+ { 'wsdl:key' => api_key,
75
+ 'wsdl:latitude' => latitude,
76
+ 'wsdl:longitude' => longitude,
77
+ 'wsdl:locationID' => '',
78
+ 'wsdl:DCrating' => dc_rating,
79
+ # I will have to give this some thought, but .8 is a better number for now– it has todo with the shading and efficiency of inverters – we may need to pass efficiency data to get an accurate number along with the shading data (ie. how shaded the location is))
80
+ 'wsdl:derate' => (DEFAULT_DERATE * shading),
81
+ 'wsdl:cost' => 0.0,
82
+ 'wsdl:mode' => 0,
83
+ 'wsdl:tilt' => tilt,
84
+ 'wsdl:azimuth' => orientation,
85
+ 'wsdl:inoct' => 45.0,
86
+ 'wsdl:pwrdgr' => -0.005
87
+ }
88
+ end
89
+
90
+ end
@@ -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}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matt Aimonetti"]
12
+ s.date = %q{2011-03-06}
13
+ s.description = %q{Calculates the Performance of a Grid-Connected PV System.}
14
+ s.email = %q{mattaimonetti@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,30 @@
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
+ :orientation => 180,
11
+ :shading => 0)
12
+ end
13
+
14
+ it "should fetch the yearly production data" do
15
+ @pdata['jan'].should == 496
16
+ @pdata['feb'].should == 469
17
+ @pdata['mar'].should == 539
18
+ @pdata['apr'].should == 525
19
+ @pdata['may'].should == 539
20
+ @pdata['jun'].should == 498
21
+ @pdata['jul'].should == 526
22
+ @pdata['aug'].should == 554
23
+ @pdata['sep'].should == 540
24
+ @pdata['oct'].should == 536
25
+ @pdata['nov'].should == 508
26
+ @pdata['dec'].should == 471
27
+ @pdata['year'].should == 6203
28
+ end
29
+
30
+ 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,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pvwatts
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Matt Aimonetti
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-06 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 0
31
+ version: 2.3.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 2
61
+ version: 1.5.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: savon
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ - 7
75
+ - 6
76
+ version: 0.7.6
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: yard
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ - 6
90
+ - 4
91
+ version: 0.6.4
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: savon
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ - 7
105
+ - 6
106
+ version: 0.7.6
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: *id006
110
+ description: Calculates the Performance of a Grid-Connected PV System.
111
+ email: mattaimonetti@gmail.com
112
+ executables: []
113
+
114
+ extensions: []
115
+
116
+ extra_rdoc_files:
117
+ - LICENSE.txt
118
+ - README.rdoc
119
+ files:
120
+ - .document
121
+ - .rspec
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.rdoc
126
+ - Rakefile
127
+ - VERSION
128
+ - lib/pvwatts.rb
129
+ - pvwatts.gemspec
130
+ - spec/pvwatts_spec.rb
131
+ - spec/spec_helper.rb
132
+ has_rdoc: true
133
+ homepage: http://github.com/mattetti/pvwatts
134
+ licenses:
135
+ - MIT
136
+ post_install_message:
137
+ rdoc_options: []
138
+
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: -4335976862583453684
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ requirements: []
159
+
160
+ rubyforge_project:
161
+ rubygems_version: 1.3.7
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Wrapper around the http://www.nrel.gov/rredc/pvwatts/ web service API.
165
+ test_files:
166
+ - spec/pvwatts_spec.rb
167
+ - spec/spec_helper.rb