openstudio-extension 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +29 -26
- data/.rspec +3 -3
- data/.rubocop.yml +10 -9
- data/CHANGELOG.md +16 -0
- data/Gemfile +6 -6
- data/Jenkinsfile +10 -10
- data/README.md +251 -250
- data/Rakefile +119 -119
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/doc_templates/LICENSE.md +26 -26
- data/doc_templates/README.md.erb +41 -41
- data/doc_templates/copyright_erb.txt +35 -35
- data/doc_templates/copyright_js.txt +3 -3
- data/doc_templates/copyright_ruby.txt +33 -33
- data/init_templates/README.md +37 -37
- data/init_templates/gemspec.txt +32 -32
- data/init_templates/openstudio_module.rb +50 -50
- data/init_templates/spec.rb +47 -47
- data/init_templates/spec_helper.rb +49 -49
- data/init_templates/template_gemfile.txt +17 -17
- data/init_templates/template_rakefile.txt +15 -15
- data/init_templates/version.rb +40 -40
- data/lib/files/openstudio-extension-gem-test.ddy +536 -536
- data/lib/files/openstudio-extension-gem-test.epw +8768 -8768
- data/lib/files/openstudio-extension-gem-test.stat +554 -554
- data/lib/measures/openstudio_extension_test_measure/LICENSE.md +26 -26
- data/lib/measures/openstudio_extension_test_measure/README.md +26 -26
- data/lib/measures/openstudio_extension_test_measure/README.md.erb +41 -41
- data/lib/measures/openstudio_extension_test_measure/measure.rb +72 -72
- data/lib/measures/openstudio_extension_test_measure/measure.xml +83 -83
- data/lib/measures/openstudio_extension_test_measure/resources/os_lib_helper_methods.rb +399 -399
- data/lib/measures/openstudio_extension_test_measure/tests/{OpenStudioExtensionTestMeasure_Test.rb → openstudio_extension_test_measure_test.rb} +74 -75
- data/lib/openstudio-extension.rb +1 -1
- data/lib/openstudio/extension.rb +234 -229
- data/lib/openstudio/extension/core/CreateResults.rb +886 -886
- data/lib/openstudio/extension/core/check_air_sys_temps.rb +190 -190
- data/lib/openstudio/extension/core/check_calibration.rb +155 -155
- data/lib/openstudio/extension/core/check_cond_zns.rb +84 -84
- data/lib/openstudio/extension/core/check_domestic_hot_water.rb +334 -334
- data/lib/openstudio/extension/core/check_envelope_conductance.rb +453 -453
- data/lib/openstudio/extension/core/check_eui_by_end_use.rb +162 -162
- data/lib/openstudio/extension/core/check_eui_reasonableness.rb +135 -135
- data/lib/openstudio/extension/core/check_fan_pwr.rb +98 -98
- data/lib/openstudio/extension/core/check_internal_loads.rb +393 -393
- data/lib/openstudio/extension/core/check_mech_sys_capacity.rb +226 -226
- data/lib/openstudio/extension/core/check_mech_sys_efficiency.rb +326 -326
- data/lib/openstudio/extension/core/check_mech_sys_part_load_eff.rb +464 -464
- data/lib/openstudio/extension/core/check_mech_sys_type.rb +139 -139
- data/lib/openstudio/extension/core/check_part_loads.rb +451 -451
- data/lib/openstudio/extension/core/check_placeholder.rb +75 -75
- data/lib/openstudio/extension/core/check_plant_cap.rb +123 -123
- data/lib/openstudio/extension/core/check_plant_temps.rb +159 -159
- data/lib/openstudio/extension/core/check_plenum_loads.rb +87 -87
- data/lib/openstudio/extension/core/check_pump_pwr.rb +108 -108
- data/lib/openstudio/extension/core/check_sch_coord.rb +241 -241
- data/lib/openstudio/extension/core/check_schedules.rb +311 -311
- data/lib/openstudio/extension/core/check_simultaneous_heating_and_cooling.rb +158 -158
- data/lib/openstudio/extension/core/check_supply_air_and_thermostat_temp_difference.rb +148 -148
- data/lib/openstudio/extension/core/check_weather_files.rb +132 -132
- data/lib/openstudio/extension/core/deer_vintages.rb +311 -311
- data/lib/openstudio/extension/core/os_lib_aedg_measures.rb +491 -491
- data/lib/openstudio/extension/core/os_lib_cofee.rb +258 -258
- data/lib/openstudio/extension/core/os_lib_constructions.rb +378 -378
- data/lib/openstudio/extension/core/os_lib_geometry.rb +1022 -1022
- data/lib/openstudio/extension/core/os_lib_helper_methods.rb +399 -399
- data/lib/openstudio/extension/core/os_lib_hvac.rb +2171 -2171
- data/lib/openstudio/extension/core/os_lib_lighting_and_equipment.rb +214 -214
- data/lib/openstudio/extension/core/os_lib_model_generation.rb +817 -817
- data/lib/openstudio/extension/core/os_lib_model_simplification.rb +1049 -1049
- data/lib/openstudio/extension/core/os_lib_outdoorair_and_infiltration.rb +165 -165
- data/lib/openstudio/extension/core/os_lib_reporting.rb +4651 -4651
- data/lib/openstudio/extension/core/os_lib_reporting_qaqc.rb +200 -200
- data/lib/openstudio/extension/core/os_lib_schedules.rb +963 -963
- data/lib/openstudio/extension/rake_task.rb +159 -149
- data/lib/openstudio/extension/runner.rb +667 -644
- data/lib/openstudio/extension/runner_config.rb +114 -0
- data/lib/openstudio/extension/version.rb +40 -40
- data/openstudio-extension.gemspec +34 -33
- metadata +39 -37
@@ -1,75 +1,74 @@
|
|
1
|
-
# *******************************************************************************
|
2
|
-
# OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
|
3
|
-
# All rights reserved.
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are met:
|
6
|
-
#
|
7
|
-
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
-
# this list of conditions and the following disclaimer.
|
9
|
-
#
|
10
|
-
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
-
# this list of conditions and the following disclaimer in the documentation
|
12
|
-
# and/or other materials provided with the distribution.
|
13
|
-
#
|
14
|
-
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
-
# may be used to endorse or promote products derived from this software without
|
16
|
-
# specific prior written permission from the respective party.
|
17
|
-
#
|
18
|
-
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
-
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
-
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
-
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
-
#
|
23
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
-
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
-
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
-
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
-
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
-
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
-
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
-
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
-
# *******************************************************************************
|
35
|
-
|
36
|
-
require 'openstudio'
|
37
|
-
require 'openstudio/measure/ShowRunnerOutput'
|
38
|
-
|
39
|
-
require_relative '../measure.rb'
|
40
|
-
require 'minitest/autorun'
|
41
|
-
|
42
|
-
class
|
43
|
-
# def setup
|
44
|
-
# end
|
45
|
-
|
46
|
-
# def teardown
|
47
|
-
# end
|
48
|
-
|
49
|
-
def test_OpenStudioExtensionTestMeasure
|
50
|
-
# create an instance of the measure
|
51
|
-
measure = OpenStudioExtensionTestMeasure.new
|
52
|
-
|
53
|
-
# create an instance of a runner
|
54
|
-
runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
|
55
|
-
|
56
|
-
# make an empty model
|
57
|
-
model = OpenStudio::Model::Model.new
|
58
|
-
|
59
|
-
# get arguments and test that they are what we are expecting
|
60
|
-
arguments = measure.arguments(model)
|
61
|
-
assert_equal(0, arguments.size)
|
62
|
-
|
63
|
-
# set argument values to good values and run the measure on model with spaces
|
64
|
-
arguments = measure.arguments(model)
|
65
|
-
argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
|
66
|
-
|
67
|
-
measure.run(model, runner, argument_map)
|
68
|
-
result = runner.result
|
69
|
-
# show_output(result)
|
70
|
-
assert(result.value.valueName == 'Success')
|
71
|
-
assert(result.warnings.
|
72
|
-
assert(result.info.
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
+
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
+
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
+
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
|
36
|
+
require 'openstudio'
|
37
|
+
require 'openstudio/measure/ShowRunnerOutput'
|
38
|
+
|
39
|
+
require_relative '../measure.rb'
|
40
|
+
require 'minitest/autorun'
|
41
|
+
|
42
|
+
class OpenStudioExtensionTestMeasureTest < Minitest::Test
|
43
|
+
# def setup
|
44
|
+
# end
|
45
|
+
|
46
|
+
# def teardown
|
47
|
+
# end
|
48
|
+
|
49
|
+
def test_OpenStudioExtensionTestMeasure
|
50
|
+
# create an instance of the measure
|
51
|
+
measure = OpenStudioExtensionTestMeasure.new
|
52
|
+
|
53
|
+
# create an instance of a runner
|
54
|
+
runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
|
55
|
+
|
56
|
+
# make an empty model
|
57
|
+
model = OpenStudio::Model::Model.new
|
58
|
+
|
59
|
+
# get arguments and test that they are what we are expecting
|
60
|
+
arguments = measure.arguments(model)
|
61
|
+
assert_equal(0, arguments.size)
|
62
|
+
|
63
|
+
# set argument values to good values and run the measure on model with spaces
|
64
|
+
arguments = measure.arguments(model)
|
65
|
+
argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
|
66
|
+
|
67
|
+
measure.run(model, runner, argument_map)
|
68
|
+
result = runner.result
|
69
|
+
# show_output(result)
|
70
|
+
assert(result.value.valueName == 'Success')
|
71
|
+
assert(result.warnings.empty?)
|
72
|
+
assert(result.info.empty?)
|
73
|
+
end
|
74
|
+
end
|
data/lib/openstudio-extension.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative 'openstudio/extension'
|
1
|
+
require_relative 'openstudio/extension'
|
data/lib/openstudio/extension.rb
CHANGED
@@ -1,229 +1,234 @@
|
|
1
|
-
# *******************************************************************************
|
2
|
-
# OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
|
3
|
-
# All rights reserved.
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are met:
|
6
|
-
#
|
7
|
-
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
-
# this list of conditions and the following disclaimer.
|
9
|
-
#
|
10
|
-
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
-
# this list of conditions and the following disclaimer in the documentation
|
12
|
-
# and/or other materials provided with the distribution.
|
13
|
-
#
|
14
|
-
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
-
# may be used to endorse or promote products derived from this software without
|
16
|
-
# specific prior written permission from the respective party.
|
17
|
-
#
|
18
|
-
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
-
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
-
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
-
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
-
#
|
23
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
-
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
-
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
-
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
-
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
-
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
-
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
-
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
-
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
-
# *******************************************************************************
|
35
|
-
|
36
|
-
require 'openstudio/extension/version'
|
37
|
-
require 'openstudio/extension/runner'
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
def
|
50
|
-
|
51
|
-
end
|
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
|
-
end
|
1
|
+
# *******************************************************************************
|
2
|
+
# OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
|
3
|
+
# All rights reserved.
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# (1) Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# (2) Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# (3) Neither the name of the copyright holder nor the names of any contributors
|
15
|
+
# may be used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission from the respective party.
|
17
|
+
#
|
18
|
+
# (4) Other than as required in clauses (1) and (2), distributions in any form
|
19
|
+
# of modifications or other derivative works may not use the "OpenStudio"
|
20
|
+
# trademark, "OS", "os", or any other confusingly similar designation without
|
21
|
+
# specific prior written permission from Alliance for Sustainable Energy, LLC.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
|
24
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
25
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
|
27
|
+
# UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
|
28
|
+
# THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
29
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
30
|
+
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
32
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33
|
+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
# *******************************************************************************
|
35
|
+
|
36
|
+
require 'openstudio/extension/version'
|
37
|
+
require 'openstudio/extension/runner'
|
38
|
+
require 'openstudio/extension/runner_config'
|
39
|
+
|
40
|
+
module OpenStudio
|
41
|
+
module Extension
|
42
|
+
class Extension
|
43
|
+
attr_accessor :root_dir
|
44
|
+
|
45
|
+
# Typically one does not pass in the root path and it is defaulted as the root path of the project
|
46
|
+
# that is inheriting the extension. The root path can be overriden as needed on initialization only. This
|
47
|
+
# is mainly used for testing purposes.
|
48
|
+
# @param root_dir: string, fully qualified path of the root directory of the extension gem.
|
49
|
+
def initialize(root_dir = nil)
|
50
|
+
@root_dir = root_dir || File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return the absolute path of the measures or nil if there is none, used when configuring OSWs
|
54
|
+
def measures_dir
|
55
|
+
return File.absolute_path(File.join(@root_dir, 'lib', 'measures'))
|
56
|
+
end
|
57
|
+
|
58
|
+
# Relevant files such as weather data, design days, etc.
|
59
|
+
# Return the absolute path of the files or nil if there is none, used when configuring OSWs
|
60
|
+
def files_dir
|
61
|
+
return File.absolute_path(File.join(@root_dir, 'lib', 'files'))
|
62
|
+
end
|
63
|
+
|
64
|
+
# Doc templates are common files like copyright files which are used to update measures and other code
|
65
|
+
# Doc templates will only be applied to measures in the current repository
|
66
|
+
# Return the absolute path of the doc templates dir or nil if there is none
|
67
|
+
def doc_templates_dir
|
68
|
+
return File.absolute_path(File.join(@root_dir, 'doc_templates'))
|
69
|
+
end
|
70
|
+
|
71
|
+
# Do not override
|
72
|
+
# Files in the core directory are copied into measure resource folders to build standalone measures
|
73
|
+
# Files will be copied into the resources folder of measures which have files of the same name
|
74
|
+
# Return the absolute path of the core dir or nil if there is none
|
75
|
+
def core_dir
|
76
|
+
return File.absolute_path(File.join(@root_dir, 'lib', 'openstudio', 'extension', 'core'))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Module method to return all classes derived from OpenStudio::Extension::Extension
|
82
|
+
# Note all extension classes must be loaded before calling this method
|
83
|
+
##
|
84
|
+
# @return [Array]: Array of classes
|
85
|
+
def self.all_extensions
|
86
|
+
# DLM: consider calling Bundler.require in this method
|
87
|
+
# do not call Bundler.require when requiring this file, only when calling this method
|
88
|
+
result = []
|
89
|
+
ObjectSpace.each_object(::Class) do |obj|
|
90
|
+
next if !obj.ancestors.include?(OpenStudio::Extension::Extension)
|
91
|
+
|
92
|
+
result << obj
|
93
|
+
end
|
94
|
+
return result.uniq
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Module method to return measure directories from all extensions
|
99
|
+
##
|
100
|
+
# @return [Array]: Array of measure directories
|
101
|
+
def self.all_measure_dirs
|
102
|
+
result = []
|
103
|
+
all_extensions.each do |obj|
|
104
|
+
begin
|
105
|
+
dir = obj.new.measures_dir
|
106
|
+
result << dir if dir
|
107
|
+
rescue StandardError
|
108
|
+
end
|
109
|
+
end
|
110
|
+
return result.uniq
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# Module method to return file directories from all extensions
|
115
|
+
##
|
116
|
+
# @return [Array] Array of measure resource directories
|
117
|
+
def self.all_file_dirs
|
118
|
+
result = []
|
119
|
+
all_extensions.each do |obj|
|
120
|
+
begin
|
121
|
+
dir = obj.new.files_dir
|
122
|
+
result << dir if dir
|
123
|
+
rescue StandardError
|
124
|
+
end
|
125
|
+
end
|
126
|
+
return result.uniq
|
127
|
+
end
|
128
|
+
|
129
|
+
##
|
130
|
+
# Module method to check for duplicate file, measure, or measure resource names across all extensions
|
131
|
+
#
|
132
|
+
# Will raise an error if conflicting file names are found.
|
133
|
+
# Note that file names in measure_files_dir names (e.g. License.md) are expected to be the same across all extensions.
|
134
|
+
##
|
135
|
+
def self.check_for_name_conflicts
|
136
|
+
measure_dirs = all_measure_dirs
|
137
|
+
file_dirs = all_file_dirs
|
138
|
+
conflicts = []
|
139
|
+
|
140
|
+
measure_dir_names = {}
|
141
|
+
measure_dirs.each do |dir|
|
142
|
+
Dir.glob(File.join(dir, '*')).each do |file|
|
143
|
+
next if !File.directory?(file)
|
144
|
+
next if !File.exist?(File.join(file, 'measure.rb'))
|
145
|
+
|
146
|
+
# puts file
|
147
|
+
file_name = File.basename(file).downcase
|
148
|
+
if measure_dir_names[file_name]
|
149
|
+
conflicts << "Measure '#{file}' conflicts with '#{measure_dir_names[file_name]}'"
|
150
|
+
else
|
151
|
+
measure_dir_names[file_name] = file
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
file_names = {}
|
157
|
+
file_dirs.each do |dir|
|
158
|
+
Dir.glob(File.join(dir, '*')).each do |file|
|
159
|
+
next if !File.file?(file)
|
160
|
+
|
161
|
+
# puts file
|
162
|
+
file_name = File.basename(file).downcase
|
163
|
+
if file_names[file_name]
|
164
|
+
conflicts << "File '#{file}' conflicts with '#{file_names[file_name]}'"
|
165
|
+
else
|
166
|
+
file_names[file_name] = file
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
if !conflicts.empty?
|
172
|
+
raise "Conflicting file names found: [#{conflicts.join(', ')}]"
|
173
|
+
end
|
174
|
+
|
175
|
+
return false
|
176
|
+
end
|
177
|
+
|
178
|
+
##
|
179
|
+
# Module method used to configure an input OSW with paths to all OpenStudio::Extension measure and file directories
|
180
|
+
##
|
181
|
+
# @param [Hash] in_osw Initial OSW object as a Hash, keys should be symbolized
|
182
|
+
#
|
183
|
+
# @return [Hash] Output OSW with measure and file paths configured
|
184
|
+
def self.configure_osw(in_osw)
|
185
|
+
check_for_name_conflicts
|
186
|
+
|
187
|
+
measure_dirs = all_measure_dirs
|
188
|
+
file_dirs = all_file_dirs
|
189
|
+
|
190
|
+
in_osw[:measure_paths] = [] if in_osw[:measure_paths].nil?
|
191
|
+
in_osw[:file_paths] = [] if in_osw[:file_paths].nil?
|
192
|
+
|
193
|
+
in_osw[:measure_paths] = in_osw[:measure_paths].concat(measure_dirs).uniq
|
194
|
+
in_osw[:file_paths] = in_osw[:file_paths].concat(file_dirs).uniq
|
195
|
+
|
196
|
+
return in_osw
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# Module method used to set the measure argument for measure_dir_name to argument_value,
|
201
|
+
# argument_name must appear in the OSW or exception will be raised. If step_name is nil
|
202
|
+
# then all workflow steps matching measure_dir_name will be affected. If step_name is
|
203
|
+
# not nil, then only workflow steps matching measure_dir_name and step_name will be affected.
|
204
|
+
##
|
205
|
+
# @param [Hash] in_osw Initial OSW object as a Hash, keys should be symbolized
|
206
|
+
# @param [String] measure_dir_name Directory name of measure to set argument on
|
207
|
+
# @param [String] argument_name Name of the argument to set
|
208
|
+
# @param [String] argument_value Value to set the argument name to
|
209
|
+
# @param [String] step_name Optional argument, if present used to select workflow step to modify
|
210
|
+
#
|
211
|
+
# @return [Hash] Output OSW with measure argument set to argument value
|
212
|
+
def self.set_measure_argument(osw, measure_dir_name, argument_name, argument_value, step_name = nil)
|
213
|
+
result = false
|
214
|
+
osw[:steps].each do |step|
|
215
|
+
if step[:measure_dir_name] == measure_dir_name
|
216
|
+
if step_name.nil? || step[:name] == step_name
|
217
|
+
step[:arguments][argument_name.to_sym] = argument_value
|
218
|
+
result = true
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
if !result
|
224
|
+
if step_name
|
225
|
+
raise "Could not set '#{argument_name}' to '#{argument_value}' for measure '#{measure_dir_name}' in step '#{step_name}'"
|
226
|
+
else
|
227
|
+
raise "Could not set '#{argument_name}' to '#{argument_value}' for measure '#{measure_dir_name}'"
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
return osw
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|