Class: URBANopt::Scenario::DefaultReports::Program

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanopt/scenario/default_reports/program.rb

Overview

Program includes all building program related information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Program

Program class initialize building program attributes: :site_area , :floor_area , :conditioned_area , :unconditioned_area , :footprint_area , +:maximum_roof_height, :maximum_number_of_stories , :maximum_number_of_stories_above_ground , :parking_area , :number_of_parking_spaces , :number_of_parking_spaces_charging , :parking_footprint_area , :maximum_parking_height , :maximum_number_of_parking_stories , :maximum_number_of_parking_stories_above_ground , :number_of_residential_units , :building_types , :building_type , :maximum_occupancy , :area , :window_area , :north_window_area , :south_window_area , :east_window_area , :west_window_area , :wall_area , :roof_area , :equipment_roof_area , :photovoltaic_roof_area , :available_roof_area , :total_roof_area , :orientation , :aspect_ratio

parameters:

hash - Hash - A hash which may contain a deserialized program.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 58

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

  @site_area = hash[:site_area]
  @floor_area = hash[:floor_area]
  @conditioned_area = hash[:conditioned_area]
  @unconditioned_area = hash[:unconditioned_area]
  @footprint_area = hash[:footprint_area]
  @maximum_roof_height = hash[:maximum_roof_height]
  @maximum_number_of_stories = hash[:maximum_number_of_stories]
  @maximum_number_of_stories_above_ground = hash[:maximum_number_of_stories_above_ground]
  @parking_area = hash[:parking_area]
  @number_of_parking_spaces = hash[:number_of_parking_spaces]
  @number_of_parking_spaces_charging = hash[:number_of_parking_spaces_charging]
  @parking_footprint_area = hash[:parking_footprint_area]
  @maximum_parking_height = hash[:maximum_parking_height]
  @maximum_number_of_parking_stories = hash[:maximum_number_of_parking_stories]
  @maximum_number_of_parking_stories_above_ground = hash[:maximum_number_of_parking_stories_above_ground]
  @number_of_residential_units = hash[:number_of_residential_units]
  @building_types = hash[:building_types]
  @window_area = hash[:window_area]
  @wall_area = hash[:wall_area]
  @roof_area = hash[:roof_area]
  @orientation = hash[:orientation]
  @aspect_ratio = hash[:aspect_ratio]

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

Instance Attribute Details

#areaObject

Returns the value of attribute area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def area
  @area
end

#aspect_ratioObject

Returns the value of attribute aspect_ratio.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def aspect_ratio
  @aspect_ratio
end

#available_roof_areaObject

Returns the value of attribute available_roof_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def available_roof_area
  @available_roof_area
end

#building_typeObject

Returns the value of attribute building_type.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def building_type
  @building_type
end

#building_typesObject

Returns the value of attribute building_types.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def building_types
  @building_types
end

#conditioned_areaObject

Returns the value of attribute conditioned_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def conditioned_area
  @conditioned_area
end

#east_window_areaObject

Returns the value of attribute east_window_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def east_window_area
  @east_window_area
end

#equipment_roof_areaObject

Returns the value of attribute equipment_roof_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def equipment_roof_area
  @equipment_roof_area
end

#floor_areaObject

Returns the value of attribute floor_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def floor_area
  @floor_area
end

#footprint_areaObject

Returns the value of attribute footprint_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def footprint_area
  @footprint_area
end

#maximum_number_of_parking_storiesObject

Returns the value of attribute maximum_number_of_parking_stories.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def maximum_number_of_parking_stories
  @maximum_number_of_parking_stories
end

#maximum_number_of_parking_stories_above_groundObject

Returns the value of attribute maximum_number_of_parking_stories_above_ground.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def maximum_number_of_parking_stories_above_ground
  @maximum_number_of_parking_stories_above_ground
end

#maximum_number_of_storiesObject

Returns the value of attribute maximum_number_of_stories.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def maximum_number_of_stories
  @maximum_number_of_stories
end

#maximum_number_of_stories_above_groundObject

Returns the value of attribute maximum_number_of_stories_above_ground.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def maximum_number_of_stories_above_ground
  @maximum_number_of_stories_above_ground
end

#maximum_occupancyObject

Returns the value of attribute maximum_occupancy.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def maximum_occupancy
  @maximum_occupancy
end

#maximum_parking_heightObject

Returns the value of attribute maximum_parking_height.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def maximum_parking_height
  @maximum_parking_height
end

#maximum_roof_heightObject

Returns the value of attribute maximum_roof_height.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def maximum_roof_height
  @maximum_roof_height
end

#north_window_areaObject

Returns the value of attribute north_window_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def north_window_area
  @north_window_area
end

#number_of_parking_spacesObject

Returns the value of attribute number_of_parking_spaces.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def number_of_parking_spaces
  @number_of_parking_spaces
end

#number_of_parking_spaces_chargingObject

Returns the value of attribute number_of_parking_spaces_charging.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def number_of_parking_spaces_charging
  @number_of_parking_spaces_charging
end

#number_of_residential_unitsObject

Returns the value of attribute number_of_residential_units.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def number_of_residential_units
  @number_of_residential_units
end

#orientationObject

Returns the value of attribute orientation.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def orientation
  @orientation
end

#parking_areaObject

Returns the value of attribute parking_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def parking_area
  @parking_area
end

#parking_footprint_areaObject

Returns the value of attribute parking_footprint_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def parking_footprint_area
  @parking_footprint_area
end

#photovoltaic_roof_areaObject

Returns the value of attribute photovoltaic_roof_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def photovoltaic_roof_area
  @photovoltaic_roof_area
end

#roof_areaObject

Returns the value of attribute roof_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def roof_area
  @roof_area
end

#site_areaObject

Returns the value of attribute site_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def site_area
  @site_area
end

#south_window_areaObject

Returns the value of attribute south_window_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def south_window_area
  @south_window_area
end

#total_roof_areaObject

Returns the value of attribute total_roof_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def total_roof_area
  @total_roof_area
end

#unconditioned_areaObject

Returns the value of attribute unconditioned_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def unconditioned_area
  @unconditioned_area
end

#wall_areaObject

Returns the value of attribute wall_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def wall_area
  @wall_area
end

#west_window_areaObject

Returns the value of attribute west_window_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def west_window_area
  @west_window_area
end

#window_areaObject

Returns the value of attribute window_area.



42
43
44
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 42

def window_area
  @window_area
end

Instance Method Details

#add_program(other) ⇒ Object

Merges program objects to each other by summing up values or taking the maximum value of the attributes.

parameters:

other - Program - An object of Program class.

rubocop:disable Metrics/AbcSize # :nodoc:



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 219

def add_program(other)
  @site_area = add_values(@site_area, other.site_area)

  @floor_area = add_values(@floor_area, other.floor_area)
  @conditioned_area = add_values(@conditioned_area, other.conditioned_area)
  @unconditioned_area = add_values(@unconditioned_area, other.unconditioned_area)
  @footprint_area = add_values(@footprint_area, other.footprint_area)
  @maximum_roof_height = max_value(@maximum_roof_height, other.maximum_roof_height)
  @maximum_number_of_stories = max_value(@maximum_number_of_stories, other.maximum_number_of_stories)
  @maximum_number_of_stories_above_ground = max_value(@maximum_number_of_stories_above_ground, other.maximum_number_of_stories_above_ground)
  @parking_area = add_values(@parking_area, other.parking_area)
  @number_of_parking_spaces = add_values(@number_of_parking_spaces, other.number_of_parking_spaces)
  @number_of_parking_spaces_charging = add_values(@number_of_parking_spaces_charging, other.number_of_parking_spaces_charging)
  @parking_footprint_area = add_values(@parkig_footprint_area, other.parking_footprint_area)
  @maximum_parking_height = max_value(@maximum_parking_height, other.maximum_parking_height)
  @maximum_number_of_parking_stories = max_value(@maximum_number_of_parking_stories, other.maximum_number_of_parking_stories)
  @maximum_number_of_parking_stories_above_ground = max_value(maximum_number_of_parking_stories_above_ground, other.maximum_number_of_parking_stories_above_ground)
  @number_of_residential_units = add_values(@number_of_residential_units, other.number_of_residential_units)

  @building_types = other.building_types

  @window_area[:north_window_area] = add_values(@window_area[:north_window_area], other.window_area[:north_window_area])
  @window_area[:south_window_area] = add_values(@window_area[:south_window_area], other.window_area[:south_window_area])
  @window_area[:east_window_area] = add_values(@window_area[:east_window_area], other.window_area[:east_window_area])
  @window_area[:west_window_area] = add_values(@window_area[:west_window_area], other.window_area[:west_window_area])
  @window_area[:total_window_area] =  add_values(@window_area[:total_window_area], other.window_area[:total_window_area])

  @wall_area[:north_wall_area] = add_values(@wall_area[:north_wall_area], other.wall_area[:north_wall_area])
  @wall_area[:south_wall_area] = add_values(@wall_area[:south_wall_area], other.wall_area[:south_wall_area])
  @wall_area[:east_wall_area] = add_values(@wall_area[:east_wall_area], other.wall_area[:east_wall_area])
  @wall_area[:west_wall_area] = add_values(@wall_area[:west_wall_area], other.wall_area[:west_wall_area])
  @wall_area[:total_wall_area] = add_values(@wall_area[:total_wall_area], other.wall_area[:total_wall_area])

  @roof_area[:equipment_roof_area] = add_values(@roof_area[:equipment_roof_area], other.roof_area[:equipment_roof_area])
  @roof_area[:photovoltaic_roof_area] = add_values(@roof_area[:photovoltaic_roof_area], other.roof_area[:photovoltaic_roof_area])
  @roof_area[:available_roof_area] = add_values(@roof_area[:available_roof_area], other.roof_area[:available_roof_area])
  @roof_area[:total_roof_area] = add_values(@roof_area[:total_roof_area], other.roof_area[:total_roof_area])
end

#add_values(existing_value, new_value) ⇒ Object

Adds up existing_value and new_values if not nill.

parameters:

existing_value - Float - A value corresponding to a Program attribute.

new_value - Float - A value corresponding to a Program attribute.



203
204
205
206
207
208
209
210
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 203

def add_values(existing_value, new_value)
  if existing_value && new_value
    existing_value += new_value
  elsif new_value
    existing_value = new_value
  end
  return existing_value
end

#defaultsObject

Assigns default values if values do not exist.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 93

def defaults
  hash = {}
  hash[:site_area] = nil
  hash[:floor_area] = nil
  hash[:conditioned_area] = nil
  hash[:unconditioned_area] = nil
  hash[:footprint_area] = nil
  hash[:maximum_roof_height] = nil
  hash[:maximum_number_of_stories] = nil
  hash[:maximum_number_of_stories_above_ground] = nil
  hash[:parking_area] = nil
  hash[:number_of_parking_spaces] = nil
  hash[:number_of_parking_spaces_charging] = nil
  hash[:parking_footprint_area] = nil
  hash[:maximum_parking_height] = nil
  hash[:maximum_number_of_parking_stories] = nil
  hash[:maximum_number_of_parking_stories_above_ground] = nil
  hash[:number_of_residential_units] = nil
  hash[:building_types] = [{ building_type: nil, maximum_occupancy: nil, floor_area: nil }]
  hash[:window_area] = { north_window_area: nil, south_window_area: nil, east_window_area: nil, west_window_area: nil, total_window_area: nil }
  hash[:wall_area] = { north_wall_area: nil, south_wall_area: nil, east_wall_area: nil, west_wall_area: nil, total_wall_area: nil }
  hash[:roof_area] = { equipment_roof_area: nil, photovoltaic_roof_area: nil, available_roof_area: nil, total_roof_area: nil }
  hash[:orientation] = nil
  hash[:aspect_ratio] = nil
  return hash
end

#max_value(existing_value, new_value) ⇒ Object

Return the maximum value from existing_value and new_value.

parameters:

existing_value - Float - A value corresponding to a Program attribute.

new_value - Float - A value corresponding to a Program attribute.



186
187
188
189
190
191
192
193
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 186

def max_value(existing_value, new_value)
  if existing_value && new_value
    [existing_value, new_value].max
  elsif new_value
    existing_value = new_value
  end
  return existing_value
end

#to_hashObject

Convert to a Hash equivalent for JSON serialization.

  • Exclude attributes with nil values.

  • Validate program hash properties against schema.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/urbanopt/scenario/default_reports/program.rb', line 126

def to_hash
  result = {}
  result[:site_area] = @site_area if @site_area
  result[:floor_area] = @floor_area if @floor_area
  result[:conditioned_area] = @conditioned_area if @conditioned_area
  result[:unconditioned_area] = @unconditioned_area if @unconditioned_area
  result[:footprint_area] = @footprint_area if @footprint_area
  result[:maximum_roof_height] = @maximum_roof_height if @maximum_roof_height
  result[:maximum_number_of_stories] = @maximum_number_of_stories if @maximum_number_of_stories
  result[:maximum_number_of_stories_above_ground] = @maximum_number_of_stories_above_ground if @maximum_number_of_parking_stories_above_ground
  result[:parking_area] = @parking_area if @parking_area
  result[:number_of_parking_spaces] = @number_of_parking_spaces if @number_of_parking_spaces
  result[:number_of_parking_spaces_charging] = @number_of_parking_spaces_charging if @number_of_parking_spaces_charging
  result[:parking_footprint_area] = @parking_footprint_area if @parking_footprint_area
  result[:maximum_parking_height] = @maximum_parking_height if @maximum_parking_height
  result[:maximum_number_of_parking_stories] = @maximum_number_of_parking_stories if @maximum_number_of_parking_stories
  result[:maximum_number_of_parking_stories_above_ground] = @maximum_number_of_parking_stories_above_ground if @maximum_number_of_parking_stories_above_ground
  result[:number_of_residential_units] = @number_of_residential_units if @number_of_residential_units

  if @building_types.any?
    result[:building_types] = @building_types
    @building_types.each do |bt|
      bt.delete_if { |k, v| v.nil? } if bt
    end
  end

  # result[:window_area] = @window_area if @window_area
  window_area_hash = @window_area if @window_area
  window_area_hash.delete_if { |k, v| v.nil? }
  result[:window_area] = window_area_hash if @window_area

  # result[:wall_area] = @wall_area if @wall_area
  wall_area_hash = @wall_area if @wall_area
  wall_area_hash.delete_if { |k, v| v.nil? }
  result[:wall_area] = wall_area_hash if @wall_area

  # result[:roof_area] = @roof_area if @roof_area
  roof_area_hash = @roof_area if @roof_area
  roof_area_hash.delete_if { |k, v| v.nil? }
  result[:roof_area] = roof_area_hash if @roof_area

  result[:orientation] = @orientation if @orientation
  result[:aspect_ratio] = @aspect_ratio if @aspect_ratio

  # validate program properties against schema
  if @@validator.validate(@@schema[:definitions][:Program][:properties], result).any?
    raise "program properties does not match schema: #{@@validator.validate(@@schema[:definitions][:Program][:properties], result)}"
  end

  return result
end