Class: Pvwatts
- Inherits:
-
Object
- Object
- Pvwatts
- Defined in:
- lib/pvwatts.rb
Overview
Wrapper around the www.nrel.gov/rredc/pvwatts/ web service API. Calculates the Performance of a Grid-Connected PV System. Use of the Pvwatts web service is restricted to authorized users. For information on obtaining authorization, contact [email protected]
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#get_stats(opts = {}) ⇒ Hash
Get information based on passed options.
-
#initialize(api_key) ⇒ Pvwatts
constructor
Create an instance of the API wrapper.
-
#yearly_production(opts = {}) ⇒ Hash
Calculate the estimated yearly production based on passed options.
Constructor Details
#initialize(api_key) ⇒ Pvwatts
Create an instance of the API wrapper.
23 24 25 |
# File 'lib/pvwatts.rb', line 23 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/pvwatts.rb', line 17 def api_key @api_key end |
Instance Method Details
#get_stats(opts = {}) ⇒ Hash
Get information based on passed options.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pvwatts.rb', line 79 def get_stats(opts={}) Rails.logger.debug("pvwatts get_stats called") if Object.const_defined?(:Rails) keys = opts.keys client = Savon::Client.new("http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL") @latitude, @longitude = [opts[:latitude], opts[:longitude]] @dc_rating, @tilt, @azimuth, @derate, @cost, @array_type = opts[:dc_rating], opts[:tilt], opts[:azimuth], opts[:derate], opts[:cost], opts[:array_type] unless @latitude && @longitude && @dc_rating && @tilt && @azimuth && @derate && @cost && @array_type raise ArgumentError, "passed -> latitude: #{@latitude}, longitude: #{@longitude}, dc_rating: #{@dc_rating}, tilt: #{@tilt}, azimuth: #{@azimuth}, derate: #{@derate}, cost: #{@cost}, array_type: #{@array_type}" end req = prep_request(@latitude, @longitude, @dc_rating, @tilt, @azimuth, @derate, @array_type, @cost) response = client.get_pvwatts{|soap| soap.input = "GetPVWATTS"; soap.body = req } rdata = response.to_hash if rdata[:get_pvwatts_response] && rdata[:get_pvwatts_response][:get_pvwatts_result] && rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo] @production_data = [] @pvwatt_info = rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo].compact @production_data = @pvwatt_info else raise 'Problem with the pvwatts response' end @production_data end |
#yearly_production(opts = {}) ⇒ Hash
Calculate the estimated yearly production based on passed options.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pvwatts.rb', line 40 def yearly_production(opts={}) Rails.logger.debug("pvwatts yearly prod called") if Object.const_defined?(:Rails) keys = opts.keys client = Savon::Client.new("http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL") @latitude, @longitude = [opts[:latitude], opts[:longitude]] @dc_rating, @tilt, @azimuth, @derate, @cost, @array_type = opts[:dc_rating], opts[:tilt], opts[:azimuth], opts[:derate], opts[:cost], opts[:array_type] unless @latitude && @longitude && @dc_rating && @tilt && @azimuth && @derate && @cost && @array_type raise ArgumentError, "passed -> latitude: #{@latitude}, longitude: #{@longitude}, dc_rating: #{@dc_rating}, tilt: #{@tilt}, azimuth: #{@azimuth}, derate: #{@derate}, cost: #{@cost}, array_type: #{@array_type}" end req = prep_request(@latitude, @longitude, @dc_rating, @tilt, @azimuth, @derate, @array_type, @cost) response = client.get_pvwatts{|soap| soap.input = "GetPVWATTS"; soap.body = req } rdata = response.to_hash if rdata[:get_pvwatts_response] && rdata[:get_pvwatts_response][:get_pvwatts_result] && rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo] @production_data = {} @pvwatt_info = rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo].compact @pvwatt_info.each do |el| if el.respond_to?(:has_key?) && el.has_key?(:month) @production_data[el[:month].downcase] = el[:a_cenergy].to_i end end else raise 'Problem with the pvwatts response' end @production_data end |