Class: URBANopt::Reporting::DefaultReports::SolarPV

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanopt/reporting/default_reports/solar_pv.rb

Overview

Onsite solar PV system attributes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ SolarPV

Initialize SolarPV attributes from a hash. Solar PV attributes currently are limited to power capacity.

parameters:
  • hash - Hash - A hash containing a :size_kw key/value pair which represents the nameplate capacity in kilowatts (kW)



29
30
31
32
33
34
35
36
37
38
39
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
66
67
68
69
70
71
72
73
74
75
# File 'lib/urbanopt/reporting/default_reports/solar_pv.rb', line 29

def initialize(hash = {})
  hash.delete_if { |k, v| v.nil? }

  @size_kw = hash[:size_kw]
  @id = hash[:id]
  @location = hash[:location]
  @approx_area_m2 = 0

  if hash[:azimuth]
    @azimuth = hash[:azimuth]
  end
  if hash[:tilt]
    @tilt = hash[:tilt]
  end
  if hash[:module_type]
    @module_type = hash[:module_type]

    # calculate area with PVWatts formulas
    # Size (kW) = Array Area (m²) × 1 kW/m² × Module Efficiency (%)
    # also grab module efficiency: 0 (standard) = 15%, 1 (premium) = 19%, 2 (thin film) = 10%
    eff = 0
    case @module_type
    when 0
      eff = 0.15
    when 1
      eff = 0.19
    when 2
      eff = 0.10
    end
    if @size_kw != 0
      @approx_area_m2 = (@size_kw / eff).round(3)
    end
  end
  if hash[:gcr]
    @gcr = hash[:gcr]
  end
  if hash[:average_yearly_energy_produced_kwh]
    @annual_energy_produced = hash[:average_yearly_energy_produced_kwh]
  end

  # initialize class variables @@validator and @@schema
  @@validator ||= Validator.new
  @@schema ||= @@validator.schema

  # initialize @@logger
  @@logger ||= URBANopt::Reporting::DefaultReports.logger
end

Instance Attribute Details

#azimuthObject

Returns the value of attribute azimuth.



20
21
22
# File 'lib/urbanopt/reporting/default_reports/solar_pv.rb', line 20

def azimuth
  @azimuth
end

#locationObject

Returns the value of attribute location.



20
21
22
# File 'lib/urbanopt/reporting/default_reports/solar_pv.rb', line 20

def location
  @location
end

#module_typeObject

Returns the value of attribute module_type.



20
21
22
# File 'lib/urbanopt/reporting/default_reports/solar_pv.rb', line 20

def module_type
  @module_type
end

#size_kwObject

Float - power capacity in kilowatts



19
20
21
# File 'lib/urbanopt/reporting/default_reports/solar_pv.rb', line 19

def size_kw
  @size_kw
end

#tiltObject

Returns the value of attribute tilt.



20
21
22
# File 'lib/urbanopt/reporting/default_reports/solar_pv.rb', line 20

def tilt
  @tilt
end

Class Method Details

.add_pv(existing_pv, new_pv) ⇒ Object

Merge PV systems



98
99
100
101
102
103
104
105
106
# File 'lib/urbanopt/reporting/default_reports/solar_pv.rb', line 98

def self.add_pv(existing_pv, new_pv)
  if existing_pv.size_kw.nil? && new_pv.size_kw.nil?
    existing_pv.size_kw = nil
  else
    existing_pv.size_kw = (existing_pv.size_kw || 0) + (new_pv.size_kw || 0)
  end
  # KAF: todo, recalculate area?
  return existing_pv
end

Instance Method Details

#to_hashObject

Convert to a Hash equivalent for JSON serialization



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/urbanopt/reporting/default_reports/solar_pv.rb', line 80

def to_hash
  result = {}

  result[:size_kw] = @size_kw if @size_kw
  result[:location] = @location if @location
  result[:azimuth] = @azimuth if @azimuth
  result[:tilt] = @tilt if @tilt
  result[:module_type] = @module_type if @module_type
  result[:approximate_area_m2] = @approx_area_m2 if @approx_area_m2
  result[:gcr] = @gcr if @gcr
  result[:average_yearly_energy_produced_kwh] = @annual_energy_produced if @annual_energy_produced

  return result
end