Skip to content

Commit b0eaf8c

Browse files
committed
Remove system_mappings
1 parent da6a999 commit b0eaf8c

File tree

3 files changed

+45
-41
lines changed

3 files changed

+45
-41
lines changed

lib/buildingsync/model_articulation/facility.rb

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ def initialize(base_xml, ns)
7676

7777
@measures = []
7878
@contacts = []
79-
@systems_map = {}
8079

8180
# TODO: Go under Report
8281
@utility_name = nil
8382
@utility_meter_numbers = []
8483
@metering_configuration = nil
8584
@spaces_excluded_from_gross_floor_area = nil
8685

87-
@load_system = nil
8886
@hvac_systems = nil
87+
@lighting_systems = nil
88+
@load_systems = nil
8989

9090
# reading the xml
9191
read_xml
@@ -213,8 +213,7 @@ def read_and_create_initial_systems
213213

214214
init_hvac_systems(systems_xml.elements["#{@ns}:HVACSystems"])
215215
init_lighting_systems(systems_xml.elements["#{@ns}:LightingSystem"])
216-
# TODO: we aren't reading this from file... Which type of System is this? Plugloads? ProcessLoads?
217-
@load_system = LoadsSystem.new
216+
init_load_systems(systems_xml.elements["#{@ns}:PlugLoads"]) # PlugLoad, not ProcessLoad
218217

219218
end
220219

@@ -248,6 +247,21 @@ def init_lighting_systems(lighting_system_xmls)
248247
end
249248
end
250249

250+
def init_load_systems(loads_system_xmls)
251+
# if theres no loads_system_xmls, use a default
252+
if loads_system_xmls.nil? || !loads_system_xmls.has_elements?
253+
loads_system_xml = @g.add_plug_load_to_facility(@base_xml)
254+
@load_systems = [BuildingSync::LoadsSystem.new(loads_system_xml, @ns)]
255+
256+
# else, use the lighting_system_xmls
257+
else
258+
@load_systems = []
259+
loads_system_xmls.elements.each do |lighting_system_xml|
260+
@load_systems << BuildingSync::LoadsSystem.new(lighting_system_xml, @ns)
261+
end
262+
end
263+
end
264+
251265
# @see BuildingSync::Report.add_cb_modeled
252266
def add_cb_modeled(id = 'Scenario-Baseline')
253267
@report.add_cb_modeled(id)
@@ -264,13 +278,13 @@ def add_blank_lighting_system(premise_id, premise_type, lighting_system_id = 'Li
264278
@g.add_linked_premise(lighting_system_xml, premise_id, premise_type)
265279

266280
# Create a new array if doesn't yet exist
267-
if !@systems_map.key?('LightingSystems')
268-
@systems_map['LightingSystems'] = []
281+
if @lighting_systems.nil?
282+
@lighting_systems = []
269283
end
270284

271285
# Create new lighting system and add to array
272286
new_system = BuildingSync::LightingSystemType.new(lighting_system_xml, @ns)
273-
@systems_map['LightingSystems'] << new_system
287+
@lighting_systems << new_system
274288
return new_system
275289
end
276290

@@ -324,13 +338,17 @@ def create_building_systems(main_output_dir:, zone_hash: nil, hvac_delivery_type
324338

325339
# add internal loads to space types
326340
if add_space_type_loads
327-
@load_system.add_internal_loads(model, open_studio_system_standard, template, @site.get_building_sections, remove_objects)
341+
@load_systems.each do |load_system|
342+
load_system.add_internal_loads(model, open_studio_system_standard, template, @site.get_building_sections, remove_objects)
343+
end
328344
new_occupancy_peak = @site.get_peak_occupancy
329345
new_occupancy_peak.each do |id, occupancy_peak|
330346
floor_area = @site.get_floor_area[id]
331347
if occupancy_peak && floor_area && floor_area > 0.0
332348
puts "new peak occupancy value found: absolute occupancy: #{occupancy_peak} occupancy per area: #{occupancy_peak.to_f / floor_area.to_f} and area: #{floor_area} m2"
333-
@load_system.adjust_occupancy_peak(model, occupancy_peak, floor_area, @site.get_space_types_from_hash(id))
349+
@load_systems.each do |load_system|
350+
load_system.adjust_occupancy_peak(model, occupancy_peak, floor_area, @site.get_space_types_from_hash(id))
351+
end
334352
end
335353
end
336354
end
@@ -363,13 +381,15 @@ def create_building_systems(main_output_dir:, zone_hash: nil, hvac_delivery_type
363381

364382
# add elevators (returns ElectricEquipment object)
365383
if add_elevators
366-
@load_system.add_elevator(model, open_studio_system_standard)
384+
@load_systems.each do |load_system|
385+
load_system.add_elevator(model, open_studio_system_standard)
386+
end
367387
end
368388

369389
# add exterior lights (returns a hash where key is lighting type and value is exteriorLights object)
370390
if add_exterior_lights
371-
if !@systems_map['LightingSystems'].nil?
372-
@systems_map['LightingSystems'].each do |lighting_system|
391+
if !@lighting_systems.nil?
392+
@lighting_systems.each do |lighting_system|
373393
lighting_system.add_exterior_lights(model, open_studio_system_standard, onsite_parking_fraction, exterior_lighting_zone, remove_objects)
374394
end
375395
else
@@ -460,6 +480,6 @@ def prepare_final_xml
460480
@site.prepare_final_xml
461481
end
462482

463-
attr_reader :systems_map, :site, :report, :measures, :contacts
483+
attr_reader :site, :report, :measures, :contacts, :hvac_systems, :lighting_systems, :load_systems
464484
end
465485
end

spec/tests/model_articulation_test/facility_spec.rb

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
end
167167
end
168168

169-
RSpec.describe 'Facility Systems Mapping' do
169+
RSpec.describe 'Facility Systems' do
170170
before(:all) do
171171
# -- Setup
172172
@ns = 'auc'
@@ -184,33 +184,20 @@
184184
@facility = BuildingSync::Facility.new(facility_xml, @ns)
185185
end
186186
describe 'with systems defined' do
187-
it 'should be of the correct data structure' do
188-
# -- Assert
189-
expect(@facility.systems_map).to be_an_instance_of(Hash)
190-
end
191-
it 'should have the correct keys' do
192-
# -- Assert correct keys get created
193-
expected_keys = ['HVACSystems', 'LightingSystems', 'PlugLoads']
194-
expected_keys.each do |k|
195-
expect(@facility.systems_map.key?(k)).to be true
196-
end
197-
end
198-
199187
it 'values should be of the correct type and size' do
200188
# -- Assert values of keys are correct type and size
201-
expect(@facility.systems_map['HVACSystems']).to be_an_instance_of(Array)
202-
expect(@facility.systems_map['LightingSystems']).to be_an_instance_of(Array)
203-
expect(@facility.systems_map['PlugLoads']).to be_an_instance_of(Array)
204-
expect(@facility.systems_map['HVACSystems'].size).to eq(2)
205-
expect(@facility.systems_map['LightingSystems'].size).to eq(1)
206-
expect(@facility.systems_map['PlugLoads'].size).to eq(1)
189+
expect(@facility.hvac_systems).to be_an_instance_of(Array)
190+
expect(@facility.lighting_systems).to be_an_instance_of(Array)
191+
expect(@facility.load_systems).to be_an_instance_of(Array)
192+
expect(@facility.hvac_systems.size).to eq(2)
193+
expect(@facility.lighting_systems.size).to eq(1)
194+
expect(@facility.load_systems.size).to eq(1)
207195
end
208196

209197
it 'values in array should be of the correct type' do
210-
# Only HVACSystem and LightingSystem should be typed as BSync element types (for now)
211-
expect(@facility.systems_map['HVACSystems'][0]).to be_an_instance_of(BuildingSync::HVACSystem)
212-
expect(@facility.systems_map['LightingSystems'][0]).to be_an_instance_of(BuildingSync::LightingSystemType)
213-
expect(@facility.systems_map['PlugLoads'][0]).to be_an_instance_of(REXML::Element)
198+
expect(@facility.hvac_systems[0]).to be_an_instance_of(BuildingSync::HVACSystem)
199+
expect(@facility.lighting_systems[0]).to be_an_instance_of(BuildingSync::LightingSystemType)
200+
expect(@facility.load_systems[0]).to be_an_instance_of(BuildingSync::LoadsSystem)
214201
end
215202
end
216203
describe 'with no systems defined' do

spec/tests/model_articulation_test/lighting_system_type_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,15 @@
7373
@facility = BuildingSync::Facility.new(facility_xml, ns)
7474

7575
# -- Assert - No systems have been added
76-
expect(@facility.systems_map.empty?).to be true
7776
@facility.determine_open_studio_standard(@std)
7877

7978
# Add a blank lighting system to the facility and link it to the building
8079
building_id = @facility.site.get_building.xget_id
8180
@lighting_system = @facility.add_blank_lighting_system(building_id, 'Building')
8281

8382
# -- Assert Lighting System has been properly added
84-
expect(@facility.systems_map.key?('LightingSystems')).to be true
85-
expect(@facility.systems_map['LightingSystems'].size).to eq(1)
86-
expect(@facility.systems_map['LightingSystems'][0]).to be @lighting_system
87-
expect(@lighting_system.xget_linked_premises).to eq('Building' => ['Building1'])
83+
expect(@facility.lighting_systems.size).to eq(1)
84+
expect(@facility.lighting_systems[0].xget_linked_premises).to eq('Building' => ['Building1'])
8885

8986
# we need to create a site and call the generate_baseline_osm method in order to set the space types in the model, why are those really needed?
9087
@facility.generate_baseline_osm(@epw_file_path, @output_path, @std)

0 commit comments

Comments
 (0)