pvwatts-ee 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pvwatts.rb +35 -1
- data/pvwatts.gemspec +1 -1
- data/spec/pvwatts_spec.rb +53 -27
- metadata +1 -1
data/lib/pvwatts.rb
CHANGED
@@ -63,7 +63,41 @@ class Pvwatts
|
|
63
63
|
end
|
64
64
|
@production_data
|
65
65
|
end
|
66
|
-
|
66
|
+
# Get information based on passed options.
|
67
|
+
#
|
68
|
+
# @param [Hash] opts
|
69
|
+
# @option opts [String, Float] :latitude Latitude coordinate of the location.
|
70
|
+
# @option opts [String, Float] :longitude Longitude coordinate of the location.
|
71
|
+
# @option opts [String, Float] :dc_rating kW rating values 0.5 to 10000.0
|
72
|
+
# @option opts [String, Float] :tilt PV Array Lattitude tilt value 0 - 90
|
73
|
+
# @option opts [String, Integer] :azimuth azimuth value 0 - 360 (180 for Northern Hemisphere).
|
74
|
+
# @option opts [String, Float] :derate overall DC to AC derate factor values 0.10 - 0.96
|
75
|
+
# @option opts [String, Float] :cost electricity cost per kWh (US ¢/kWh)
|
76
|
+
# @options opts [String, Integer] :array_type 0=fixed tilt, 1=1-axis tracking, 2=2-axis tracking
|
77
|
+
# @return [Hash] A hash with the yearly production with a key for each month and a 'year' key to represent the yearly value.
|
78
|
+
#
|
79
|
+
def get_stats(opts={})
|
80
|
+
Rails.logger.debug("pvwatts get_stats called") if Object.const_defined?(:Rails)
|
81
|
+
keys = opts.keys
|
82
|
+
client = Savon::Client.new("http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL")
|
83
|
+
@latitude, @longitude = [opts[:latitude], opts[:longitude]]
|
84
|
+
@dc_rating, @tilt, @azimuth, @derate, @cost, @array_type = opts[:dc_rating], opts[:tilt], opts[:azimuth], opts[:derate], opts[:cost], opts[:array_type]
|
85
|
+
unless @latitude && @longitude && @dc_rating && @tilt && @azimuth && @derate && @cost && @array_type
|
86
|
+
raise ArgumentError, "passed -> latitude: #{@latitude}, longitude: #{@longitude}, dc_rating: #{@dc_rating}, tilt: #{@tilt}, azimuth: #{@azimuth}, derate: #{@derate}, cost: #{@cost}, array_type: #{@array_type}"
|
87
|
+
end
|
88
|
+
req = prep_request(@latitude, @longitude, @dc_rating, @tilt, @azimuth, @derate, @array_type, @cost)
|
89
|
+
|
90
|
+
response = client.get_pvwatts{|soap| soap.input = "GetPVWATTS"; soap.body = req }
|
91
|
+
rdata = response.to_hash
|
92
|
+
if rdata[:get_pvwatts_response] && rdata[:get_pvwatts_response][:get_pvwatts_result] && rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo]
|
93
|
+
@production_data = []
|
94
|
+
@pvwatt_info = rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo].compact
|
95
|
+
@production_data = @pvwatt_info
|
96
|
+
else
|
97
|
+
raise 'Problem with the pvwatts response'
|
98
|
+
end
|
99
|
+
@production_data
|
100
|
+
end
|
67
101
|
private
|
68
102
|
|
69
103
|
def prep_request(latitude, longitude, dc_rating, tilt, azimuth, derate, array_type, cost)
|
data/pvwatts.gemspec
CHANGED
data/spec/pvwatts_spec.rb
CHANGED
@@ -1,32 +1,58 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
2
|
describe Pvwatts do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
describe "#yearly_production" do
|
4
|
+
it "should fetch the yearly production data" do
|
5
|
+
@pdata = Pvwatts.new(PVWATTS_SPEC_KEY).yearly_production(:latitude => 32.95850,
|
6
|
+
:longitude => -117.12206,
|
7
|
+
:dc_rating => 4.0,
|
8
|
+
:tilt => 45,
|
9
|
+
:azimuth => 180,
|
10
|
+
:derate => 0.82,
|
11
|
+
:array_type=>0,
|
12
|
+
:cost=>0.1)
|
13
|
+
@pdata['jan'].should == 496
|
14
|
+
@pdata['feb'].should == 469
|
15
|
+
@pdata['mar'].should == 539
|
16
|
+
@pdata['apr'].should == 525
|
17
|
+
@pdata['may'].should == 539
|
18
|
+
@pdata['jun'].should == 498
|
19
|
+
@pdata['jul'].should == 526
|
20
|
+
@pdata['aug'].should == 554
|
21
|
+
@pdata['sep'].should == 540
|
22
|
+
@pdata['oct'].should == 536
|
23
|
+
@pdata['nov'].should == 508
|
24
|
+
@pdata['dec'].should == 471
|
25
|
+
@pdata['year'].should == 6203
|
26
|
+
end
|
14
27
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
describe "#get_stats" do
|
29
|
+
it "should fetch the stats data" do
|
30
|
+
@pdata = Pvwatts.new(PVWATTS_SPEC_KEY).get_stats(:latitude => 32.95850,
|
31
|
+
:longitude => -117.12206,
|
32
|
+
:dc_rating => 4.0,
|
33
|
+
:tilt => 45,
|
34
|
+
:azimuth => 180,
|
35
|
+
:derate => 0.82,
|
36
|
+
:array_type=>0,
|
37
|
+
:cost=>0.1)
|
38
|
+
@pdata.is_a?(Array).should be_true
|
39
|
+
@pdata.size.should == 13
|
40
|
+
@pdata.each_with_index do |data, i|
|
41
|
+
@pdata.is_a?(Hash).should be_true
|
42
|
+
if i == 0
|
43
|
+
["array_type","array_tilt","location_id","a_crating","power_degredataion","inoct","latitude","d_crating","longitude","currency","electric_cost","array_azimuth","message","a_ctod_cderate"].each do |key|
|
44
|
+
@pdata.has_key?(key).should be_true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
@pdata["month"].should == month_to_string(i+1)
|
48
|
+
(@pdata["a_cenergy"] > 0).should be_true
|
49
|
+
(@pdata["cost_saved"] > 0).should be_true
|
50
|
+
(@pdata["solar"] > 0).should be_true
|
51
|
+
end
|
52
|
+
end
|
30
53
|
end
|
31
|
-
|
54
|
+
def month_to_string(integer)
|
55
|
+
month_keys={1=>"Jan", 2=>"Feb", 3=>"Mar", 4=>"Apr", 5=>"May", 6=>"Jun", 7=>"Jul", 8=>"Aug", 9=>"Sep", 10=>"Oct", 11=>"Nov", 12=>"Dec", 13=>"Year"}
|
56
|
+
month_keys[integer]
|
57
|
+
end
|
32
58
|
end
|