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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +29 -26
  3. data/.rspec +3 -3
  4. data/.rubocop.yml +10 -9
  5. data/CHANGELOG.md +16 -0
  6. data/Gemfile +6 -6
  7. data/Jenkinsfile +10 -10
  8. data/README.md +251 -250
  9. data/Rakefile +119 -119
  10. data/bin/console +14 -14
  11. data/bin/setup +8 -8
  12. data/doc_templates/LICENSE.md +26 -26
  13. data/doc_templates/README.md.erb +41 -41
  14. data/doc_templates/copyright_erb.txt +35 -35
  15. data/doc_templates/copyright_js.txt +3 -3
  16. data/doc_templates/copyright_ruby.txt +33 -33
  17. data/init_templates/README.md +37 -37
  18. data/init_templates/gemspec.txt +32 -32
  19. data/init_templates/openstudio_module.rb +50 -50
  20. data/init_templates/spec.rb +47 -47
  21. data/init_templates/spec_helper.rb +49 -49
  22. data/init_templates/template_gemfile.txt +17 -17
  23. data/init_templates/template_rakefile.txt +15 -15
  24. data/init_templates/version.rb +40 -40
  25. data/lib/files/openstudio-extension-gem-test.ddy +536 -536
  26. data/lib/files/openstudio-extension-gem-test.epw +8768 -8768
  27. data/lib/files/openstudio-extension-gem-test.stat +554 -554
  28. data/lib/measures/openstudio_extension_test_measure/LICENSE.md +26 -26
  29. data/lib/measures/openstudio_extension_test_measure/README.md +26 -26
  30. data/lib/measures/openstudio_extension_test_measure/README.md.erb +41 -41
  31. data/lib/measures/openstudio_extension_test_measure/measure.rb +72 -72
  32. data/lib/measures/openstudio_extension_test_measure/measure.xml +83 -83
  33. data/lib/measures/openstudio_extension_test_measure/resources/os_lib_helper_methods.rb +399 -399
  34. data/lib/measures/openstudio_extension_test_measure/tests/{OpenStudioExtensionTestMeasure_Test.rb → openstudio_extension_test_measure_test.rb} +74 -75
  35. data/lib/openstudio-extension.rb +1 -1
  36. data/lib/openstudio/extension.rb +234 -229
  37. data/lib/openstudio/extension/core/CreateResults.rb +886 -886
  38. data/lib/openstudio/extension/core/check_air_sys_temps.rb +190 -190
  39. data/lib/openstudio/extension/core/check_calibration.rb +155 -155
  40. data/lib/openstudio/extension/core/check_cond_zns.rb +84 -84
  41. data/lib/openstudio/extension/core/check_domestic_hot_water.rb +334 -334
  42. data/lib/openstudio/extension/core/check_envelope_conductance.rb +453 -453
  43. data/lib/openstudio/extension/core/check_eui_by_end_use.rb +162 -162
  44. data/lib/openstudio/extension/core/check_eui_reasonableness.rb +135 -135
  45. data/lib/openstudio/extension/core/check_fan_pwr.rb +98 -98
  46. data/lib/openstudio/extension/core/check_internal_loads.rb +393 -393
  47. data/lib/openstudio/extension/core/check_mech_sys_capacity.rb +226 -226
  48. data/lib/openstudio/extension/core/check_mech_sys_efficiency.rb +326 -326
  49. data/lib/openstudio/extension/core/check_mech_sys_part_load_eff.rb +464 -464
  50. data/lib/openstudio/extension/core/check_mech_sys_type.rb +139 -139
  51. data/lib/openstudio/extension/core/check_part_loads.rb +451 -451
  52. data/lib/openstudio/extension/core/check_placeholder.rb +75 -75
  53. data/lib/openstudio/extension/core/check_plant_cap.rb +123 -123
  54. data/lib/openstudio/extension/core/check_plant_temps.rb +159 -159
  55. data/lib/openstudio/extension/core/check_plenum_loads.rb +87 -87
  56. data/lib/openstudio/extension/core/check_pump_pwr.rb +108 -108
  57. data/lib/openstudio/extension/core/check_sch_coord.rb +241 -241
  58. data/lib/openstudio/extension/core/check_schedules.rb +311 -311
  59. data/lib/openstudio/extension/core/check_simultaneous_heating_and_cooling.rb +158 -158
  60. data/lib/openstudio/extension/core/check_supply_air_and_thermostat_temp_difference.rb +148 -148
  61. data/lib/openstudio/extension/core/check_weather_files.rb +132 -132
  62. data/lib/openstudio/extension/core/deer_vintages.rb +311 -311
  63. data/lib/openstudio/extension/core/os_lib_aedg_measures.rb +491 -491
  64. data/lib/openstudio/extension/core/os_lib_cofee.rb +258 -258
  65. data/lib/openstudio/extension/core/os_lib_constructions.rb +378 -378
  66. data/lib/openstudio/extension/core/os_lib_geometry.rb +1022 -1022
  67. data/lib/openstudio/extension/core/os_lib_helper_methods.rb +399 -399
  68. data/lib/openstudio/extension/core/os_lib_hvac.rb +2171 -2171
  69. data/lib/openstudio/extension/core/os_lib_lighting_and_equipment.rb +214 -214
  70. data/lib/openstudio/extension/core/os_lib_model_generation.rb +817 -817
  71. data/lib/openstudio/extension/core/os_lib_model_simplification.rb +1049 -1049
  72. data/lib/openstudio/extension/core/os_lib_outdoorair_and_infiltration.rb +165 -165
  73. data/lib/openstudio/extension/core/os_lib_reporting.rb +4651 -4651
  74. data/lib/openstudio/extension/core/os_lib_reporting_qaqc.rb +200 -200
  75. data/lib/openstudio/extension/core/os_lib_schedules.rb +963 -963
  76. data/lib/openstudio/extension/rake_task.rb +159 -149
  77. data/lib/openstudio/extension/runner.rb +667 -644
  78. data/lib/openstudio/extension/runner_config.rb +114 -0
  79. data/lib/openstudio/extension/version.rb +40 -40
  80. data/openstudio-extension.gemspec +34 -33
  81. 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 OpenStudioExtensionTestMeasure_Test < 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.size == 0)
72
- assert(result.info.size == 0)
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
@@ -1 +1 @@
1
- require_relative 'openstudio/extension'
1
+ require_relative 'openstudio/extension'
@@ -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
- module OpenStudio
40
- module Extension
41
- class Extension
42
- attr_accessor :root_dir
43
-
44
- def initialize
45
- @root_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
46
- end
47
-
48
- # Return the absolute path of the measures or nil if there is none, used when configuring OSWs
49
- def measures_dir
50
- return File.absolute_path(File.join(@root_dir, 'lib', 'measures'))
51
- end
52
-
53
- # Relevant files such as weather data, design days, etc.
54
- # Return the absolute path of the files or nil if there is none, used when configuring OSWs
55
- def files_dir
56
- return File.absolute_path(File.join(@root_dir, 'lib', 'files'))
57
- end
58
-
59
- # Doc templates are common files like copyright files which are used to update measures and other code
60
- # Doc templates will only be applied to measures in the current repository
61
- # Return the absolute path of the doc templates dir or nil if there is none
62
- def doc_templates_dir
63
- return File.absolute_path(File.join(@root_dir, 'doc_templates'))
64
- end
65
-
66
- # Do not override
67
- # Files in the core directory are copied into measure resource folders to build standalone measures
68
- # Files will be copied into the resources folder of measures which have files of the same name
69
- # Return the absolute path of the core dir or nil if there is none
70
- def core_dir
71
- return File.absolute_path(File.join(@root_dir, 'lib', 'openstudio', 'extension', 'core'))
72
- end
73
- end
74
-
75
- ##
76
- # Module method to return all classes derived from OpenStudio::Extension::Extension
77
- # Note all extension classes must be loaded before calling this method
78
- ##
79
- # @return [Array]: Array of classes
80
- def self.all_extensions
81
- # DLM: consider calling Bundler.require in this method
82
- # do not call Bundler.require when requiring this file, only when calling this method
83
- result = []
84
- ObjectSpace.each_object(::Class) do |obj|
85
- next if !obj.ancestors.include?(OpenStudio::Extension::Extension)
86
- result << obj
87
- end
88
- return result.uniq
89
- end
90
-
91
- ##
92
- # Module method to return measure directories from all extensions
93
- ##
94
- # @return [Array]: Array of measure directories
95
- def self.all_measure_dirs
96
- result = []
97
- all_extensions.each do |obj|
98
- begin
99
- dir = obj.new.measures_dir
100
- result << dir if dir
101
- rescue StandardError
102
- end
103
- end
104
- return result.uniq
105
- end
106
-
107
- ##
108
- # Module method to return file directories from all extensions
109
- ##
110
- # @return [Array] Array of measure resource directories
111
- def self.all_file_dirs
112
- result = []
113
- all_extensions.each do |obj|
114
- begin
115
- dir = obj.new.files_dir
116
- result << dir if dir
117
- rescue StandardError
118
- end
119
- end
120
- return result.uniq
121
- end
122
-
123
- ##
124
- # Module method to check for duplicate file, measure, or measure resource names across all extensions
125
- #
126
- # Will raise an error if conflicting file names are found.
127
- # Note that file names in measure_files_dir names (e.g. License.md) are expected to be the same across all extensions.
128
- ##
129
- def self.check_for_name_conflicts
130
- measure_dirs = all_measure_dirs
131
- file_dirs = all_file_dirs
132
- conflicts = []
133
-
134
- measure_dir_names = {}
135
- measure_dirs.each do |dir|
136
- Dir.glob(File.join(dir, '*')).each do |file|
137
- next if !File.directory?(file)
138
- next if !File.exist?(File.join(file, 'measure.rb'))
139
-
140
- # puts file
141
- file_name = File.basename(file).downcase
142
- if measure_dir_names[file_name]
143
- conflicts << "Measure '#{file}' conflicts with '#{measure_dir_names[file_name]}'"
144
- else
145
- measure_dir_names[file_name] = file
146
- end
147
- end
148
- end
149
-
150
- file_names = {}
151
- file_dirs.each do |dir|
152
- Dir.glob(File.join(dir, '*')).each do |file|
153
- next if !File.file?(file)
154
-
155
- # puts file
156
- file_name = File.basename(file).downcase
157
- if file_names[file_name]
158
- conflicts << "File '#{file}' conflicts with '#{file_names[file_name]}'"
159
- else
160
- file_names[file_name] = file
161
- end
162
- end
163
- end
164
-
165
- if !conflicts.empty?
166
- raise "Conflicting file names found: #{conflicts.join(', ')}"
167
- end
168
-
169
- return false
170
- end
171
-
172
- ##
173
- # Module method used to configure an input OSW with paths to all OpenStudio::Extension measure and file directories
174
- ##
175
- # @param [Hash] in_osw Initial OSW object as a Hash, keys should be symbolized
176
- #
177
- # @return [Hash] Output OSW with measure and file paths configured
178
- def self.configure_osw(in_osw)
179
- check_for_name_conflicts
180
-
181
- measure_dirs = all_measure_dirs
182
- file_dirs = all_file_dirs
183
-
184
- in_osw[:measure_paths] = [] if in_osw[:measure_paths].nil?
185
- in_osw[:file_paths] = [] if in_osw[:file_paths].nil?
186
-
187
- in_osw[:measure_paths] = in_osw[:measure_paths].concat(measure_dirs).uniq
188
- in_osw[:file_paths] = in_osw[:file_paths].concat(file_dirs).uniq
189
-
190
- return in_osw
191
- end
192
-
193
- ##
194
- # Module method used to set the measure argument for measure_dir_name to argument_value,
195
- # argument_name must appear in the OSW or exception will be raised. If step_name is nil
196
- # then all workflow steps matching measure_dir_name will be affected. If step_name is
197
- # not nil, then only workflow steps matching measure_dir_name and step_name will be affected.
198
- ##
199
- # @param [Hash] in_osw Initial OSW object as a Hash, keys should be symbolized
200
- # @param [String] measure_dir_name Directory name of measure to set argument on
201
- # @param [String] argument_name Name of the argument to set
202
- # @param [String] argument_value Value to set the argument name to
203
- # @param [String] step_name Optional argument, if present used to select workflow step to modify
204
- #
205
- # @return [Hash] Output OSW with measure argument set to argument value
206
- #
207
- def self.set_measure_argument(osw, measure_dir_name, argument_name, argument_value, step_name = nil)
208
- result = false
209
- osw[:steps].each do |step|
210
- if step[:measure_dir_name] == measure_dir_name
211
- if step_name.nil? || step[:name] == step_name
212
- step[:arguments][argument_name.to_sym] = argument_value
213
- result = true
214
- end
215
- end
216
- end
217
-
218
- if !result
219
- if step_name
220
- raise "Could not set '#{argument_name}' to '#{argument_value}' for measure '#{measure_dir_name}' in step '#{step_name}'"
221
- else
222
- raise "Could not set '#{argument_name}' to '#{argument_value}' for measure '#{measure_dir_name}'"
223
- end
224
- end
225
-
226
- return osw
227
- end
228
- end
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