-
Notifications
You must be signed in to change notification settings - Fork 1
/
facility_spec.rb
289 lines (249 loc) · 11.5 KB
/
facility_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
119
120
121
122
123
124
125
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# frozen_string_literal: true
# *******************************************************************************
# OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
# BuildingSync(R), Copyright (c) 2015-2020, Alliance for Sustainable Energy, LLC.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# (3) Neither the name of the copyright holder nor the names of any contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission from the respective party.
#
# (4) Other than as required in clauses (1) and (2), distributions in any form
# of modifications or other derivative works may not use the "OpenStudio"
# trademark, "OS", "os", or any other confusingly similar designation without
# specific prior written permission from Alliance for Sustainable Energy, LLC.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *******************************************************************************
require 'builder'
require 'buildingsync/generator'
RSpec.describe 'FacilitySpec' do
describe 'Expected Errors' do
it 'should raise an StandardError given a non-Facility REXML Element' do
# -- Setup
ns = 'auc'
v = '2.2.0'
g = BuildingSync::Generator.new(ns, v)
doc_string = g.create_bsync_root_to_building
doc = REXML::Document.new(doc_string)
# -- Create Building object from Facility
begin
BuildingSync::Facility.new(doc.root, ns)
# Should not reach this
expect(false).to be true
rescue StandardError => e
puts e.message
expect(e.message).to eql 'Attempted to initialize Facility object with Element name of: BuildingSync'
end
end
end
# TODO: Add actual assertions
it 'Should create an instance of the facility class with minimal XML snippet' do
generator = BuildingSync::Generator.new
generator.create_minimum_facility('Retail', '1954', 'Gross', '69452')
end
it 'Should return the boolean value for creating osm file correctly or not.' do
# -- Setup
file_name = 'building_151.xml'
std = ASHRAE90_1
xml_path, output_path = create_xml_path_and_output_path(file_name, std, __FILE__, 'v2.2.0')
epw_path = File.join(SPEC_WEATHER_DIR, 'USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw')
expect(File.exist?(epw_path)).to be true
generator = BuildingSync::Generator.new
facility = generator.create_minimum_facility('Retail', '1954', 'Gross', '69452')
facility.determine_open_studio_standard(std)
# -- Assert
expect(facility.generate_baseline_osm(epw_path, output_path, std)).to be true
end
# TODO: Add actual assertions
it 'Should create a building system with parameters set to true' do
# -- Setup
file_name = 'building_151.xml'
std = ASHRAE90_1
xml_path, output_path = create_xml_path_and_output_path(file_name, std, __FILE__, 'v2.2.0')
doc = nil
File.open(xml_path, 'r') do |file|
doc = REXML::Document.new(file)
end
ns = 'auc'
# -- Act
facility = BuildingSync::Facility.new(doc.elements["/#{ns}:BuildingSync/#{ns}:Facilities/#{ns}:Facility"], ns)
facility.determine_open_studio_standard(ASHRAE90_1)
facility.generate_baseline_osm(nil, output_path, ASHRAE90_1)
facility.create_building_systems(output_path: output_path, htg_src: 'Electricity',
add_elevators: true, add_exterior_lights: true, remove_objects: true)
end
# TODO: Add actual assertions
it 'Should create a building system with parameters set to false' do
# -- Setup
file_name = 'building_151.xml'
std = ASHRAE90_1
xml_path, output_path = create_xml_path_and_output_path(file_name, std, __FILE__, 'v2.2.0')
doc = nil
File.open(xml_path, 'r') do |file|
doc = REXML::Document.new(file)
end
# -- Act
ns = 'auc'
facility = BuildingSync::Facility.new(doc.elements["/#{ns}:BuildingSync/#{ns}:Facilities/#{ns}:Facility"], ns)
facility.determine_open_studio_standard(ASHRAE90_1)
facility.generate_baseline_osm(nil, output_path, ASHRAE90_1)
facility.create_building_systems(output_path: output_path, zone_hash: nil, hvac_delivery_type: 'Forced Air',
htg_src: 'Electricity', clg_src: 'Electricity', add_space_type_loads: false,
add_constructions: false, add_elevators: false, add_exterior_lights: false,
add_exhaust: false, add_swh: false, add_hvac: false, add_thermostat: false,
remove_objects: false)
end
end
RSpec.describe 'Facility Scenario Parsing' do
before(:each) do
# -- Setup
@ns = 'auc'
g = BuildingSync::Generator.new
@doc = g.create_minimum_snippet('Retail')
@facility_xml = g.get_first_facility_element(@doc)
end
it 'building_151.xml get_scenarios should return an Array of length 30 with elements of type BuildingSync::Scenario' do
# -- Setup
file_name = 'building_151.xml'
std = ASHRAE90_1
xml_path, output_path = create_xml_path_and_output_path(file_name, std, __FILE__, 'v2.2.0')
facility = BuildingSync::Generator.new.get_facility_from_file(xml_path)
# -- Assert
expect(facility.report.scenarios.size).to eq 30
facility.report.scenarios.each do |scenario|
expect(scenario).to be_an_instance_of(BuildingSync::Scenario)
end
end
it 'scenarios should return an empty array if no scenario elements are found' do
scenarios = @doc.get_elements("//#{@ns}:Scenarios").first
scenarios.elements.delete("#{@ns}:Scenario")
scenario_elements = @doc.get_elements("//#{@ns}:Scenarios/#{@ns}:Scenario")
expect(scenario_elements.size).to eq(0)
facility = BuildingSync::Facility.new(@facility_xml, @ns)
# -- Assert
expect(facility.report.scenarios).to be_an_instance_of(Array)
expect(facility.report.scenarios.empty?).to be true
end
end
RSpec.describe 'Facility Systems Mapping' do
before(:all) do
# -- Setup
@ns = 'auc'
g = BuildingSync::Generator.new
doc = g.create_minimum_snippet('Retail')
doc_no_systems = g.create_minimum_snippet('Retail)')
@facility_no_systems_xml = g.get_first_facility_element(doc_no_systems)
g.add_hvac_system_to_first_facility(doc, 'HVACSystem-1', 'VAV with Hot Water Reheat')
g.add_hvac_system_to_first_facility(doc, 'HVACSystem-2', 'VAV with Hot Water Reheat')
g.add_lighting_system_to_first_facility(doc)
g.add_plug_load_to_first_facility(doc)
facility_xml = g.get_first_facility_element(doc)
@facility = BuildingSync::Facility.new(facility_xml, @ns)
end
describe 'with systems defined' do
it 'should be of the correct data structure' do
# -- Assert
expect(@facility.systems_map).to be_an_instance_of(Hash)
end
it 'should have the correct keys' do
# -- Assert correct keys get created
expected_keys = ['HVACSystems', 'LightingSystems', 'PlugLoads']
expected_keys.each do |k|
expect(@facility.systems_map.key?(k)).to be true
end
end
it 'values should be of the correct type and size' do
# -- Assert values of keys are correct type and size
expect(@facility.systems_map['HVACSystems']).to be_an_instance_of(Array)
expect(@facility.systems_map['LightingSystems']).to be_an_instance_of(Array)
expect(@facility.systems_map['PlugLoads']).to be_an_instance_of(Array)
expect(@facility.systems_map['HVACSystems'].size).to eq(2)
expect(@facility.systems_map['LightingSystems'].size).to eq(1)
expect(@facility.systems_map['PlugLoads'].size).to eq(1)
end
it 'values in array should be of the correct type' do
# Only HVACSystem and LightingSystem should be typed as BSync element types (for now)
expect(@facility.systems_map['HVACSystems'][0]).to be_an_instance_of(BuildingSync::HVACSystem)
expect(@facility.systems_map['LightingSystems'][0]).to be_an_instance_of(BuildingSync::LightingSystemType)
expect(@facility.systems_map['PlugLoads'][0]).to be_an_instance_of(REXML::Element)
end
end
describe 'with no systems defined' do
it 'should not error when Systems has no children' do
# -- Setup - add a blank Systems element
REXML::Element.new("#{@ns}:Systems", @facility_no_systems_xml)
expect(@facility_no_systems_xml.get_elements("#{@ns}:Systems").size).to eq(1)
facility_no_systems = BuildingSync::Facility.new(@facility_no_systems_xml, @ns)
end
it 'should not error when Systems does not exist' do
# -- Setup - remove the Systems element
@facility_no_systems_xml.elements.delete("#{@ns}:Systems")
expect(@facility_no_systems_xml.get_elements("#{@ns}:Systems").size).to eq(0)
facility_no_systems = BuildingSync::Facility.new(@facility_no_systems_xml, @ns)
end
end
end
RSpec.describe 'Facility Methods' do
before(:all) do
# -- Setup
file_name = 'building_151_level1.xml'
std = ASHRAE90_1
xml_path, output_path = create_xml_path_and_output_path(file_name, std, __FILE__, 'v2.2.0')
@facility = BuildingSync::Generator.new.get_facility_from_file(xml_path)
end
describe 'building_151_level1.xml' do
it 'Should return contact_name' do
# -- Setup
expected_value = 'a contact person'
# -- Assert
expect(@facility.get_auditor_contact_name).to eql(expected_value)
end
it 'Should return annual_fuel_use_native_units' do
# -- Setup
expected_value = '123'
# -- Assert
expect(@facility.annual_fuel_use_native_units == expected_value).to be true
end
it 'Should return energy_cost' do
# -- Setup
expected_value = '1000'
# -- Assert
expect(@facility.energy_cost == expected_value).to be true
end
it 'Should return metering_configuration ' do
# -- Setup
expected_value = 'Direct metering'
# -- Assert
expect(@facility.metering_configuration == expected_value).to be true
end
it 'Should return rate_schedules ' do
# -- Setup
expected_value = REXML::Element.new('auc:CriticalPeakPricing')
rate_schedule = @facility.rate_schedules_xml[0]
rate_structure_type = rate_schedule.get_elements('auc:TypeOfRateStructure/*')[0]
# -- Assert
expect(rate_structure_type.to_s == expected_value.to_s).to be true
end
end
end