openstudio-workflow 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -77
  3. data/README.md +67 -93
  4. data/Rakefile +36 -36
  5. data/lib/openstudio-workflow.rb +65 -65
  6. data/lib/openstudio/workflow/adapters/input/local.rb +311 -324
  7. data/lib/openstudio/workflow/adapters/output/local.rb +158 -161
  8. data/lib/openstudio/workflow/adapters/output/socket.rb +106 -107
  9. data/lib/openstudio/workflow/adapters/output/web.rb +82 -82
  10. data/lib/openstudio/workflow/adapters/output_adapter.rb +163 -163
  11. data/lib/openstudio/workflow/job.rb +57 -57
  12. data/lib/openstudio/workflow/jobs/resources/monthly_report.idf +222 -222
  13. data/lib/openstudio/workflow/jobs/run_energyplus.rb +70 -70
  14. data/lib/openstudio/workflow/jobs/run_ep_measures.rb +73 -73
  15. data/lib/openstudio/workflow/jobs/run_initialization.rb +203 -203
  16. data/lib/openstudio/workflow/jobs/run_os_measures.rb +89 -89
  17. data/lib/openstudio/workflow/jobs/run_postprocess.rb +73 -73
  18. data/lib/openstudio/workflow/jobs/run_preprocess.rb +104 -104
  19. data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +118 -118
  20. data/lib/openstudio/workflow/jobs/run_translation.rb +84 -84
  21. data/lib/openstudio/workflow/multi_delegator.rb +62 -62
  22. data/lib/openstudio/workflow/registry.rb +172 -172
  23. data/lib/openstudio/workflow/run.rb +342 -328
  24. data/lib/openstudio/workflow/time_logger.rb +96 -96
  25. data/lib/openstudio/workflow/util.rb +49 -49
  26. data/lib/openstudio/workflow/util/energyplus.rb +575 -605
  27. data/lib/openstudio/workflow/util/io.rb +68 -68
  28. data/lib/openstudio/workflow/util/measure.rb +658 -650
  29. data/lib/openstudio/workflow/util/model.rb +151 -151
  30. data/lib/openstudio/workflow/util/post_process.rb +235 -238
  31. data/lib/openstudio/workflow/util/weather_file.rb +143 -143
  32. data/lib/openstudio/workflow/version.rb +40 -40
  33. data/lib/openstudio/workflow_json.rb +475 -476
  34. data/lib/openstudio/workflow_runner.rb +263 -268
  35. metadata +24 -24
@@ -1,143 +1,143 @@
1
- # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2018, 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 HOLDERS AND CONTRIBUTORS "AS IS"
24
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
- # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
- # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
- # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
- # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
- # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- # *******************************************************************************
35
-
36
- module OpenStudio
37
- module Workflow
38
- module Util
39
- # The current precedence rules for weather files are defined in this module. Best practice is to only use the
40
- # #get_weather_file method, as it will be forward compatible
41
- #
42
- module WeatherFile
43
- # Returns the weather file with precedence
44
- #
45
- # @param [String] directory The directory to append all relative directories to, see #get_weather_file_from_fs
46
- # @param [String] wf The weather file being searched for. If not the name of the file this parameter should be
47
- # the absolute path specifying it's location
48
- # @param [Array] wf_search_array The set of precedence ordered relative directories to search for the wf in. A
49
- # typical entry might look like `['files', '../../files', '../../weather']`
50
- # @param [Object] model The OpenStudio::Model object to parse, see #get_weather_file_from_osm
51
- # @return [String, nil] The weather file with precedence if defined, nil if not, and a failure if the wf is
52
- # defined but not in the filesystem
53
- #
54
- def get_weather_file(directory, wf, wf_search_array, model, logger = nil)
55
- # TODO: this logic needs some updating, weather file should come from current model, found using search paths
56
- logger ||= ::Logger.new(STDOUT) unless logger
57
- if wf
58
- weather_file = get_weather_file_from_fs(directory, wf, wf_search_array, logger)
59
- raise 'Could not locate the weather file in the filesystem. Please see the log' if weather_file == false
60
- end
61
- weather_file = get_weather_file_from_osm(model, logger) if weather_file.nil?
62
- raise 'Could not locate the weather file in the filesystem. Please see the log' if weather_file == false
63
- logger.warn 'The weather file could not be determined. Please see the log for details' unless weather_file
64
- weather_file
65
- end
66
-
67
- private
68
-
69
- # Returns the weather file from the model. If the weather file is defined in the model, then
70
- # it checks the file paths to check if the model exists. This allows for a user to upload a
71
- # weather file in a measure and then have the measure's path be used for the weather file.
72
- #
73
- # @todo (rhorsey) verify the description of this method, as it seems suspect
74
- # @param [Object] model The OpenStudio::Model object to retrieve the weather file from
75
- # @return [nil,false, String] If the result is nil the weather file was not defined in the model, if the result
76
- # is false the weather file was set but could not be found on the filesystem, if a string the weather file was
77
- # defined and it's existence verified
78
- #
79
- def get_weather_file_from_osm(model, logger)
80
- wf = nil
81
- # grab the weather file out of the OSM if it exists
82
- if model.weatherFile.empty?
83
- logger.warn 'No weather file defined in the model'
84
- else
85
- p = model.weatherFile.get.path.get.to_s.gsub('file://', '')
86
- wf = if File.exist? p
87
- File.absolute_path(p)
88
- else
89
- # this is the weather file from the OSM model
90
- File.absolute_path(@model.weatherFile.get.path.get.to_s)
91
- end
92
- logger.info "The weather file path found in the model object: #{wf}"
93
- unless File.exist? wf
94
- logger.warn 'The weather file could not be found on the filesystem.'
95
- wf = false
96
- end
97
- end
98
- wf
99
- end
100
-
101
- # Returns the weather file defined in the OSW
102
- #
103
- # @param [String] directory The base directory to append all relative directories to
104
- # @param [String] wf The weather file being searched for. If not the name of the file this parameter should be
105
- # the absolute path specifying it's location
106
- # @param [Array] wf_search_array The set of precedence ordered relative directories to search for the wf in. A
107
- # typical entry might look like `['files', '../../files', '../../weather']`
108
- # @return [nil, false, String] If the result is nil the weather file was not defined in the workflow, if the
109
- # result is false the weather file was set but could not be found on the filesystem, if a string the weather
110
- # file was defined and it's existence verified. The order of precedence for paths is as follows: 1 - an
111
- # absolute path defined in wf, 2 - the wf_search_array, should it be defined, joined with the weather file and
112
- # appended to the directory, with each entry in the array searched until the wf is found
113
- #
114
- def get_weather_file_from_fs(directory, wf, wf_search_array, logger)
115
- raise "wf was defined as #{wf}. Please correct" unless wf
116
- weather_file = nil
117
- if Pathname.new(wf).absolute?
118
- weather_file = wf
119
- else
120
- wf_search_array.each do |wf_dir|
121
- logger.warn "The path #{wf_dir} does not exist" unless File.exist? File.join(directory, wf_dir)
122
- next unless File.exist? File.join(directory, wf_dir)
123
- if Dir.entries(File.join(directory, wf_dir)).include? File.basename(wf)
124
- weather_file = File.absolute_path(File.join(directory, wf_dir, wf))
125
- break
126
- end
127
- end
128
- end
129
- unless weather_file
130
- logger.warn 'The weather file was not found on the filesystem'
131
- return nil
132
- end
133
- logger.info "Weather file with precedence in the file system is #{weather_file}"
134
- unless File.exist? weather_file
135
- logger.warn 'The weather file could not be found on the filesystem'
136
- weather_file = false
137
- end
138
- weather_file
139
- end
140
- end
141
- end
142
- end
143
- end
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, 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 HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
36
+ module OpenStudio
37
+ module Workflow
38
+ module Util
39
+ # The current precedence rules for weather files are defined in this module. Best practice is to only use the
40
+ # #get_weather_file method, as it will be forward compatible
41
+ #
42
+ module WeatherFile
43
+ # Returns the weather file with precedence
44
+ #
45
+ # @param [String] directory The directory to append all relative directories to, see #get_weather_file_from_fs
46
+ # @param [String] wf The weather file being searched for. If not the name of the file this parameter should be
47
+ # the absolute path specifying it's location
48
+ # @param [Array] wf_search_array The set of precedence ordered relative directories to search for the wf in. A
49
+ # typical entry might look like `['files', '../../files', '../../weather']`
50
+ # @param [Object] model The OpenStudio::Model object to parse, see #get_weather_file_from_osm
51
+ # @return [String, nil] The weather file with precedence if defined, nil if not, and a failure if the wf is
52
+ # defined but not in the filesystem
53
+ #
54
+ def get_weather_file(directory, wf, wf_search_array, model, logger = nil)
55
+ # TODO: this logic needs some updating, weather file should come from current model, found using search paths
56
+ logger ||= ::Logger.new(STDOUT) unless logger
57
+ if wf
58
+ weather_file = get_weather_file_from_fs(directory, wf, wf_search_array, logger)
59
+ raise 'Could not locate the weather file in the filesystem. Please see the log' if weather_file == false
60
+ end
61
+ weather_file = get_weather_file_from_osm(model, logger) if weather_file.nil?
62
+ raise 'Could not locate the weather file in the filesystem. Please see the log' if weather_file == false
63
+ logger.warn 'The weather file could not be determined. Please see the log for details' unless weather_file
64
+ weather_file
65
+ end
66
+
67
+ private
68
+
69
+ # Returns the weather file from the model. If the weather file is defined in the model, then
70
+ # it checks the file paths to check if the model exists. This allows for a user to upload a
71
+ # weather file in a measure and then have the measure's path be used for the weather file.
72
+ #
73
+ # @todo (rhorsey) verify the description of this method, as it seems suspect
74
+ # @param [Object] model The OpenStudio::Model object to retrieve the weather file from
75
+ # @return [nil,false, String] If the result is nil the weather file was not defined in the model, if the result
76
+ # is false the weather file was set but could not be found on the filesystem, if a string the weather file was
77
+ # defined and it's existence verified
78
+ #
79
+ def get_weather_file_from_osm(model, logger)
80
+ wf = nil
81
+ # grab the weather file out of the OSM if it exists
82
+ if model.weatherFile.empty?
83
+ logger.warn 'No weather file defined in the model'
84
+ else
85
+ p = model.weatherFile.get.path.get.to_s.gsub('file://', '')
86
+ wf = if File.exist? p
87
+ File.absolute_path(p)
88
+ else
89
+ # this is the weather file from the OSM model
90
+ File.absolute_path(@model.weatherFile.get.path.get.to_s)
91
+ end
92
+ logger.info "The weather file path found in the model object: #{wf}"
93
+ unless File.exist? wf
94
+ logger.warn 'The weather file could not be found on the filesystem.'
95
+ wf = false
96
+ end
97
+ end
98
+ wf
99
+ end
100
+
101
+ # Returns the weather file defined in the OSW
102
+ #
103
+ # @param [String] directory The base directory to append all relative directories to
104
+ # @param [String] wf The weather file being searched for. If not the name of the file this parameter should be
105
+ # the absolute path specifying it's location
106
+ # @param [Array] wf_search_array The set of precedence ordered relative directories to search for the wf in. A
107
+ # typical entry might look like `['files', '../../files', '../../weather']`
108
+ # @return [nil, false, String] If the result is nil the weather file was not defined in the workflow, if the
109
+ # result is false the weather file was set but could not be found on the filesystem, if a string the weather
110
+ # file was defined and it's existence verified. The order of precedence for paths is as follows: 1 - an
111
+ # absolute path defined in wf, 2 - the wf_search_array, should it be defined, joined with the weather file and
112
+ # appended to the directory, with each entry in the array searched until the wf is found
113
+ #
114
+ def get_weather_file_from_fs(directory, wf, wf_search_array, logger)
115
+ raise "wf was defined as #{wf}. Please correct" unless wf
116
+ weather_file = nil
117
+ if Pathname.new(wf).absolute?
118
+ weather_file = wf
119
+ else
120
+ wf_search_array.each do |wf_dir|
121
+ logger.warn "The path #{wf_dir} does not exist" unless File.exist? File.join(directory, wf_dir)
122
+ next unless File.exist? File.join(directory, wf_dir)
123
+ if Dir.entries(File.join(directory, wf_dir)).include? File.basename(wf)
124
+ weather_file = File.absolute_path(File.join(directory, wf_dir, wf))
125
+ break
126
+ end
127
+ end
128
+ end
129
+ unless weather_file
130
+ logger.warn 'The weather file was not found on the filesystem'
131
+ return nil
132
+ end
133
+ logger.info "Weather file with precedence in the file system is #{weather_file}"
134
+ unless File.exist? weather_file
135
+ logger.warn 'The weather file could not be found on the filesystem'
136
+ weather_file = false
137
+ end
138
+ weather_file
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -1,40 +1,40 @@
1
- # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2018, 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 HOLDERS AND CONTRIBUTORS "AS IS"
24
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
- # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
- # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
- # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
- # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
- # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- # *******************************************************************************
35
-
36
- module OpenStudio
37
- module Workflow
38
- VERSION = '1.3.4'.freeze # Suffixes must have periods (not dashes)
39
- end
40
- end
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, 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 HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
36
+ module OpenStudio
37
+ module Workflow
38
+ VERSION = '1.3.5'.freeze # Suffixes must have periods (not dashes)
39
+ end
40
+ end
@@ -1,476 +1,475 @@
1
- # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2018, 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 HOLDERS AND CONTRIBUTORS "AS IS"
24
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
- # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
- # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
- # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
- # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
- # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
- # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- # *******************************************************************************
35
-
36
- require 'pathname'
37
-
38
- # Optional_Shim provides a wrapper that looks like an OpenStudio Optional
39
- class Optional_Shim
40
- def initialize(obj)
41
- @obj = obj
42
- end
43
-
44
- def empty?
45
- @obj.nil?
46
- end
47
-
48
- def is_initialized
49
- !@obj.nil?
50
- end
51
-
52
- def get
53
- raise 'Uninitialized Optional_Shim' if @obj.nil?
54
- @obj
55
- end
56
- end
57
-
58
- s = ''
59
- unless s.respond_to?(:to_StepResult)
60
- class String
61
- def to_StepResult
62
- self
63
- end
64
- end
65
- end
66
- unless s.respond_to?(:to_VariantType)
67
- class String
68
- def to_VariantType
69
- self
70
- end
71
- end
72
- end
73
- unless s.respond_to?(:valueName)
74
- class String
75
- def valueName
76
- self
77
- end
78
- end
79
- end
80
-
81
- # WorkflowStepResultValue_Shim provides a shim interface to the WorkflowStepResultValue class in OpenStudio 2.X when running in OpenStudio 1.X
82
- class WorkflowStepResultValue_Shim
83
- def initialize(name, value, type)
84
- @name = name
85
- @value = value
86
- @type = type
87
- end
88
-
89
- attr_reader :name
90
-
91
- attr_reader :value
92
-
93
- def variantType
94
- @type
95
- end
96
-
97
- def valueAsString
98
- @value.to_s
99
- end
100
-
101
- def valueAsDouble
102
- @value.to_f
103
- end
104
-
105
- def valueAsInteger
106
- @value.to_i
107
- end
108
-
109
- def valueAsBoolean
110
- @value
111
- end
112
- end
113
-
114
- # WorkflowStepResult_Shim provides a shim interface to the WorkflowStepResult class in OpenStudio 2.X when running in OpenStudio 1.X
115
- class WorkflowStepResult_Shim
116
- def initialize(result)
117
- @result = result
118
- end
119
-
120
- def stepInitialCondition
121
- if @result[:initial_condition]
122
- return Optional_Shim.new(@result[:initial_condition])
123
- end
124
- return Optional_Shim.new(nil)
125
- end
126
-
127
- def stepFinalCondition
128
- if @result[:final_condition]
129
- return Optional_Shim.new(@result[:final_condition])
130
- end
131
- return Optional_Shim.new(nil)
132
- end
133
-
134
- def stepErrors
135
- return @result[:step_errors]
136
- end
137
-
138
- def stepWarnings
139
- return @result[:step_warnings]
140
- end
141
-
142
- def stepInfo
143
- return @result[:step_info]
144
- end
145
-
146
- def stepValues
147
- result = []
148
- @result[:step_values].each do |step_value|
149
- result << WorkflowStepResultValue_Shim.new(step_value[:name], step_value[:value], step_value[:type])
150
- end
151
- return result
152
- end
153
-
154
- def stepResult
155
- Optional_Shim.new(@result[:step_result])
156
- end
157
-
158
- def setStepResult(step_result)
159
- @result[:step_result] = step_result
160
- end
161
-
162
- end
163
-
164
- # WorkflowStep_Shim provides a shim interface to the WorkflowStep class in OpenStudio 2.X when running in OpenStudio 1.X
165
- class WorkflowStep_Shim
166
- def initialize(step)
167
- @step = step
168
- end
169
-
170
- attr_reader :step
171
-
172
- def name
173
- if @step[:name]
174
- Optional_Shim.new(@step[:name])
175
- else
176
- Optional_Shim.new(nil)
177
- end
178
- end
179
-
180
- def result
181
- if @step[:result]
182
- Optional_Shim.new(WorkflowStepResult_Shim.new(@step[:result]))
183
- else
184
- Optional_Shim.new(nil)
185
- end
186
- end
187
-
188
- # std::string measureDirName() const;
189
- def measureDirName
190
- @step[:measure_dir_name]
191
- end
192
-
193
- # std::map<std::string, Variant> arguments() const;
194
- def arguments
195
- # TODO: match C++
196
- @step[:arguments]
197
- end
198
- end
199
-
200
- # WorkflowJSON_Shim provides a shim interface to the WorkflowJSON class in OpenStudio 2.X when running in OpenStudio 1.X
201
- class WorkflowJSON_Shim
202
- def initialize(workflow, osw_dir)
203
- @workflow = workflow
204
- @osw_dir = osw_dir
205
- @current_step_index = 0
206
- end
207
-
208
- # std::string string(bool includeHash=true) const;
209
- def string
210
- JSON.fast_generate(@workflow)
211
- end
212
-
213
- def timeString
214
- ::Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
215
- end
216
-
217
- # Returns the absolute path to the directory this workflow was loaded from or saved to. Returns current working dir for new WorkflowJSON.
218
- # openstudio::path oswDir() const;
219
- def oswDir
220
- OpenStudio.toPath(@osw_dir)
221
- end
222
-
223
- def saveAs(path)
224
- File.open(path.to_s, 'w') do |f|
225
- f << JSON.pretty_generate(@workflow)
226
- # make sure data is written to the disk one way or the other
227
- begin
228
- f.fsync
229
- rescue
230
- f.flush
231
- end
232
- end
233
- end
234
-
235
- # Sets the started at time.
236
- def start
237
- @workflow[:started_at] = timeString
238
- end
239
-
240
- # Get the current step index.
241
- def currentStepIndex
242
- @current_step_index
243
- end
244
-
245
- # Get the current step.
246
- # boost::optional<WorkflowStep> currentStep() const;
247
- def currentStep
248
- steps = @workflow[:steps]
249
-
250
- step = nil
251
- if @current_step_index < steps.size
252
- step = WorkflowStep_Shim.new(steps[@current_step_index])
253
- end
254
- return Optional_Shim.new(step)
255
- end
256
-
257
- # Increments current step, returns true if there is another step.
258
- # bool incrementStep();
259
- def incrementStep
260
- @current_step_index += 1
261
- @workflow[:current_step] = @current_step_index
262
-
263
- if @current_step_index < @workflow[:steps].size
264
- return true
265
- end
266
-
267
- return false
268
- end
269
-
270
- # Returns the root directory, default value is '.'. Evaluated relative to oswDir if not absolute.
271
- # openstudio::path rootDir() const;
272
- # openstudio::path absoluteRootDir() const;
273
- def rootDir
274
- if @workflow[:root_dir]
275
- OpenStudio.toPath(@workflow[:root_dir])
276
- else
277
- OpenStudio.toPath(@osw_dir)
278
- end
279
- end
280
-
281
- def absoluteRootDir
282
- OpenStudio.toPath(File.absolute_path(rootDir.to_s, @osw_dir.to_s))
283
- end
284
-
285
- # Returns the run directory, default value is './run'. Evaluated relative to rootDir if not absolute.
286
- # openstudio::path runDir() const;
287
- # openstudio::path absoluteRunDir() const;
288
- def runDir
289
- if @workflow[:run_directory]
290
- OpenStudio.toPath(@workflow[:run_directory])
291
- else
292
- OpenStudio.toPath('./run')
293
- end
294
- end
295
-
296
- def absoluteRunDir
297
- OpenStudio.toPath(File.absolute_path(runDir.to_s, rootDir.to_s))
298
- end
299
-
300
- def outPath
301
- if @workflow[:out_name]
302
- OpenStudio.toPath(@workflow[:out_name])
303
- else
304
- OpenStudio.toPath('./out.osw')
305
- end
306
- end
307
-
308
- def absoluteOutPath
309
- OpenStudio.toPath(File.absolute_path(outPath.to_s, oswDir.to_s))
310
- end
311
-
312
- # Returns the paths that will be searched in order for files, default value is './files/'. Evaluated relative to rootDir if not absolute.
313
- # std::vector<openstudio::path> filePaths() const;
314
- # std::vector<openstudio::path> absoluteFilePaths() const;
315
- def filePaths
316
- result = OpenStudio::PathVector.new
317
- if @workflow[:file_paths]
318
- @workflow[:file_paths].each do |file_path|
319
- result << OpenStudio.toPath(file_path)
320
- end
321
- else
322
- result << OpenStudio.toPath('./files')
323
- result << OpenStudio.toPath('./weather')
324
- result << OpenStudio.toPath('../../files')
325
- result << OpenStudio.toPath('../../weather')
326
- result << OpenStudio.toPath('./')
327
- end
328
- result
329
- end
330
-
331
- def absoluteFilePaths
332
- result = OpenStudio::PathVector.new
333
- filePaths.each do |file_path|
334
- result << OpenStudio.toPath(File.absolute_path(file_path.to_s, rootDir.to_s))
335
- end
336
- result
337
- end
338
-
339
- def addFilePath(path)
340
- if !@workflow[:file_paths]
341
- @workflow[:file_paths] = []
342
- end
343
- @workflow[:file_paths] << path
344
- end
345
-
346
- def resetFilePaths()
347
- @workflow[:file_paths] = []
348
- end
349
-
350
- # Attempts to find a file by name, searches through filePaths in order and returns first match.
351
- # boost::optional<openstudio::path> findFile(const openstudio::path& file);
352
- # boost::optional<openstudio::path> findFile(const std::string& fileName);
353
- def findFile(file)
354
- file = file.to_s
355
-
356
- # check if absolute and exists
357
- if Pathname.new(file).absolute?
358
- if File.exist?(file)
359
- return OpenStudio::OptionalPath.new(OpenStudio.toPath(file))
360
- end
361
-
362
- # absolute path does not exist
363
- return OpenStudio::OptionalPath.new
364
- end
365
-
366
- absoluteFilePaths.each do |file_path|
367
- result = File.join(file_path.to_s, file)
368
- if File.exist?(result)
369
- return OpenStudio::OptionalPath.new(OpenStudio.toPath(result))
370
- end
371
- end
372
- OpenStudio::OptionalPath.new
373
- end
374
-
375
- # Returns the paths that will be searched in order for measures, default value is './measures/'. Evaluated relative to rootDir if not absolute.
376
- # std::vector<openstudio::path> measurePaths() const;
377
- # std::vector<openstudio::path> absoluteMeasurePaths() const;
378
- def measurePaths
379
- result = OpenStudio::PathVector.new
380
- if @workflow[:measure_paths]
381
- @workflow[:measure_paths].each do |measure_path|
382
- result << OpenStudio.toPath(measure_path)
383
- end
384
- else
385
- result << OpenStudio.toPath('./measures')
386
- result << OpenStudio.toPath('../../measures')
387
- result << OpenStudio.toPath('./')
388
- end
389
- result
390
- end
391
-
392
- def absoluteMeasurePaths
393
- result = OpenStudio::PathVector.new
394
- measurePaths.each do |measure_path|
395
- result << OpenStudio.toPath(File.absolute_path(measure_path.to_s, rootDir.to_s))
396
- end
397
- result
398
- end
399
-
400
- # Attempts to find a measure by name, searches through measurePaths in order and returns first match. */
401
- # boost::optional<openstudio::path> findMeasure(const openstudio::path& measureDir);
402
- # boost::optional<openstudio::path> findMeasure(const std::string& measureDirName);
403
- def findMeasure(measureDir)
404
- measureDir = measureDir.to_s
405
-
406
- # check if absolute and exists
407
- if Pathname.new(measureDir).absolute?
408
- if File.exist?(measureDir)
409
- return OpenStudio::OptionalPath.new(OpenStudio.toPath(measureDir))
410
- end
411
-
412
- # absolute path does not exist
413
- return OpenStudio::OptionalPath.new
414
- end
415
-
416
- absoluteMeasurePaths.each do |measure_path|
417
- result = File.join(measure_path.to_s, measureDir)
418
- if File.exist?(result)
419
- return OpenStudio::OptionalPath.new(OpenStudio.toPath(result))
420
- end
421
- end
422
- OpenStudio::OptionalPath.new
423
- end
424
-
425
- # Returns the seed file path. Evaluated relative to filePaths if not absolute.
426
- # boost::optional<openstudio::path> seedFile() const;
427
- def seedFile
428
- result = OpenStudio::OptionalPath.new
429
- if @workflow[:seed_file]
430
- result = OpenStudio::OptionalPath.new(OpenStudio.toPath(@workflow[:seed_file]))
431
- end
432
- result
433
- end
434
-
435
- # Returns the weather file path. Evaluated relative to filePaths if not absolute.
436
- # boost::optional<openstudio::path> weatherFile() const;
437
- def weatherFile
438
- result = OpenStudio::OptionalPath.new
439
- if @workflow[:weather_file]
440
- result = OpenStudio::OptionalPath.new(OpenStudio.toPath(@workflow[:weather_file]))
441
- end
442
- result
443
- end
444
-
445
- # Returns the workflow steps. */
446
- # std::vector<WorkflowStep> workflowSteps() const;
447
- def workflowSteps
448
- result = []
449
- @workflow[:steps].each do |step|
450
- result << WorkflowStep_Shim.new(step)
451
- end
452
- result
453
- end
454
-
455
- def completedStatus
456
- if @workflow[:completed_status]
457
- Optional_Shim.new(@workflow[:completed_status])
458
- else
459
- Optional_Shim.new(nil)
460
- end
461
- end
462
-
463
- def setCompletedStatus(status)
464
- @workflow[:completed_status] = status
465
- @workflow[:completed_at] = timeString
466
- end
467
-
468
- def setEplusoutErr(eplusout_err)
469
- @workflow[:eplusout_err] = eplusout_err
470
- end
471
-
472
- # return empty optional
473
- def runOptions
474
- return Optional_Shim.new(nil)
475
- end
476
- end
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2020, 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 HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
36
+ require 'pathname'
37
+
38
+ # Optional_Shim provides a wrapper that looks like an OpenStudio Optional
39
+ class Optional_Shim
40
+ def initialize(obj)
41
+ @obj = obj
42
+ end
43
+
44
+ def empty?
45
+ @obj.nil?
46
+ end
47
+
48
+ def is_initialized
49
+ !@obj.nil?
50
+ end
51
+
52
+ def get
53
+ raise 'Uninitialized Optional_Shim' if @obj.nil?
54
+ @obj
55
+ end
56
+ end
57
+
58
+ s = ''
59
+ unless s.respond_to?(:to_StepResult)
60
+ class String
61
+ def to_StepResult
62
+ self
63
+ end
64
+ end
65
+ end
66
+ unless s.respond_to?(:to_VariantType)
67
+ class String
68
+ def to_VariantType
69
+ self
70
+ end
71
+ end
72
+ end
73
+ unless s.respond_to?(:valueName)
74
+ class String
75
+ def valueName
76
+ self
77
+ end
78
+ end
79
+ end
80
+
81
+ # WorkflowStepResultValue_Shim provides a shim interface to the WorkflowStepResultValue class in OpenStudio 2.X when running in OpenStudio 1.X
82
+ class WorkflowStepResultValue_Shim
83
+ def initialize(name, value, type)
84
+ @name = name
85
+ @value = value
86
+ @type = type
87
+ end
88
+
89
+ attr_reader :name
90
+
91
+ attr_reader :value
92
+
93
+ def variantType
94
+ @type
95
+ end
96
+
97
+ def valueAsString
98
+ @value.to_s
99
+ end
100
+
101
+ def valueAsDouble
102
+ @value.to_f
103
+ end
104
+
105
+ def valueAsInteger
106
+ @value.to_i
107
+ end
108
+
109
+ def valueAsBoolean
110
+ @value
111
+ end
112
+ end
113
+
114
+ # WorkflowStepResult_Shim provides a shim interface to the WorkflowStepResult class in OpenStudio 2.X when running in OpenStudio 1.X
115
+ class WorkflowStepResult_Shim
116
+ def initialize(result)
117
+ @result = result
118
+ end
119
+
120
+ def stepInitialCondition
121
+ if @result[:initial_condition]
122
+ return Optional_Shim.new(@result[:initial_condition])
123
+ end
124
+ return Optional_Shim.new(nil)
125
+ end
126
+
127
+ def stepFinalCondition
128
+ if @result[:final_condition]
129
+ return Optional_Shim.new(@result[:final_condition])
130
+ end
131
+ return Optional_Shim.new(nil)
132
+ end
133
+
134
+ def stepErrors
135
+ return @result[:step_errors]
136
+ end
137
+
138
+ def stepWarnings
139
+ return @result[:step_warnings]
140
+ end
141
+
142
+ def stepInfo
143
+ return @result[:step_info]
144
+ end
145
+
146
+ def stepValues
147
+ result = []
148
+ @result[:step_values].each do |step_value|
149
+ result << WorkflowStepResultValue_Shim.new(step_value[:name], step_value[:value], step_value[:type])
150
+ end
151
+ return result
152
+ end
153
+
154
+ def stepResult
155
+ Optional_Shim.new(@result[:step_result])
156
+ end
157
+
158
+ def setStepResult(step_result)
159
+ @result[:step_result] = step_result
160
+ end
161
+ end
162
+
163
+ # WorkflowStep_Shim provides a shim interface to the WorkflowStep class in OpenStudio 2.X when running in OpenStudio 1.X
164
+ class WorkflowStep_Shim
165
+ def initialize(step)
166
+ @step = step
167
+ end
168
+
169
+ attr_reader :step
170
+
171
+ def name
172
+ if @step[:name]
173
+ Optional_Shim.new(@step[:name])
174
+ else
175
+ Optional_Shim.new(nil)
176
+ end
177
+ end
178
+
179
+ def result
180
+ if @step[:result]
181
+ Optional_Shim.new(WorkflowStepResult_Shim.new(@step[:result]))
182
+ else
183
+ Optional_Shim.new(nil)
184
+ end
185
+ end
186
+
187
+ # std::string measureDirName() const;
188
+ def measureDirName
189
+ @step[:measure_dir_name]
190
+ end
191
+
192
+ # std::map<std::string, Variant> arguments() const;
193
+ def arguments
194
+ # TODO: match C++
195
+ @step[:arguments]
196
+ end
197
+ end
198
+
199
+ # WorkflowJSON_Shim provides a shim interface to the WorkflowJSON class in OpenStudio 2.X when running in OpenStudio 1.X
200
+ class WorkflowJSON_Shim
201
+ def initialize(workflow, osw_dir)
202
+ @workflow = workflow
203
+ @osw_dir = osw_dir
204
+ @current_step_index = 0
205
+ end
206
+
207
+ # std::string string(bool includeHash=true) const;
208
+ def string
209
+ JSON.fast_generate(@workflow)
210
+ end
211
+
212
+ def timeString
213
+ ::Time.now.utc.strftime('%Y%m%dT%H%M%SZ')
214
+ end
215
+
216
+ # Returns the absolute path to the directory this workflow was loaded from or saved to. Returns current working dir for new WorkflowJSON.
217
+ # openstudio::path oswDir() const;
218
+ def oswDir
219
+ OpenStudio.toPath(@osw_dir)
220
+ end
221
+
222
+ def saveAs(path)
223
+ File.open(path.to_s, 'w') do |f|
224
+ f << JSON.pretty_generate(@workflow)
225
+ # make sure data is written to the disk one way or the other
226
+ begin
227
+ f.fsync
228
+ rescue StandardError
229
+ f.flush
230
+ end
231
+ end
232
+ end
233
+
234
+ # Sets the started at time.
235
+ def start
236
+ @workflow[:started_at] = timeString
237
+ end
238
+
239
+ # Get the current step index.
240
+ def currentStepIndex
241
+ @current_step_index
242
+ end
243
+
244
+ # Get the current step.
245
+ # boost::optional<WorkflowStep> currentStep() const;
246
+ def currentStep
247
+ steps = @workflow[:steps]
248
+
249
+ step = nil
250
+ if @current_step_index < steps.size
251
+ step = WorkflowStep_Shim.new(steps[@current_step_index])
252
+ end
253
+ return Optional_Shim.new(step)
254
+ end
255
+
256
+ # Increments current step, returns true if there is another step.
257
+ # bool incrementStep();
258
+ def incrementStep
259
+ @current_step_index += 1
260
+ @workflow[:current_step] = @current_step_index
261
+
262
+ if @current_step_index < @workflow[:steps].size
263
+ return true
264
+ end
265
+
266
+ return false
267
+ end
268
+
269
+ # Returns the root directory, default value is '.'. Evaluated relative to oswDir if not absolute.
270
+ # openstudio::path rootDir() const;
271
+ # openstudio::path absoluteRootDir() const;
272
+ def rootDir
273
+ if @workflow[:root_dir]
274
+ OpenStudio.toPath(@workflow[:root_dir])
275
+ else
276
+ OpenStudio.toPath(@osw_dir)
277
+ end
278
+ end
279
+
280
+ def absoluteRootDir
281
+ OpenStudio.toPath(File.absolute_path(rootDir.to_s, @osw_dir.to_s))
282
+ end
283
+
284
+ # Returns the run directory, default value is './run'. Evaluated relative to rootDir if not absolute.
285
+ # openstudio::path runDir() const;
286
+ # openstudio::path absoluteRunDir() const;
287
+ def runDir
288
+ if @workflow[:run_directory]
289
+ OpenStudio.toPath(@workflow[:run_directory])
290
+ else
291
+ OpenStudio.toPath('./run')
292
+ end
293
+ end
294
+
295
+ def absoluteRunDir
296
+ OpenStudio.toPath(File.absolute_path(runDir.to_s, rootDir.to_s))
297
+ end
298
+
299
+ def outPath
300
+ if @workflow[:out_name]
301
+ OpenStudio.toPath(@workflow[:out_name])
302
+ else
303
+ OpenStudio.toPath('./out.osw')
304
+ end
305
+ end
306
+
307
+ def absoluteOutPath
308
+ OpenStudio.toPath(File.absolute_path(outPath.to_s, oswDir.to_s))
309
+ end
310
+
311
+ # Returns the paths that will be searched in order for files, default value is './files/'. Evaluated relative to rootDir if not absolute.
312
+ # std::vector<openstudio::path> filePaths() const;
313
+ # std::vector<openstudio::path> absoluteFilePaths() const;
314
+ def filePaths
315
+ result = OpenStudio::PathVector.new
316
+ if @workflow[:file_paths]
317
+ @workflow[:file_paths].each do |file_path|
318
+ result << OpenStudio.toPath(file_path)
319
+ end
320
+ else
321
+ result << OpenStudio.toPath('./files')
322
+ result << OpenStudio.toPath('./weather')
323
+ result << OpenStudio.toPath('../../files')
324
+ result << OpenStudio.toPath('../../weather')
325
+ result << OpenStudio.toPath('./')
326
+ end
327
+ result
328
+ end
329
+
330
+ def absoluteFilePaths
331
+ result = OpenStudio::PathVector.new
332
+ filePaths.each do |file_path|
333
+ result << OpenStudio.toPath(File.absolute_path(file_path.to_s, rootDir.to_s))
334
+ end
335
+ result
336
+ end
337
+
338
+ def addFilePath(path)
339
+ if !@workflow[:file_paths]
340
+ @workflow[:file_paths] = []
341
+ end
342
+ @workflow[:file_paths] << path
343
+ end
344
+
345
+ def resetFilePaths
346
+ @workflow[:file_paths] = []
347
+ end
348
+
349
+ # Attempts to find a file by name, searches through filePaths in order and returns first match.
350
+ # boost::optional<openstudio::path> findFile(const openstudio::path& file);
351
+ # boost::optional<openstudio::path> findFile(const std::string& fileName);
352
+ def findFile(file)
353
+ file = file.to_s
354
+
355
+ # check if absolute and exists
356
+ if Pathname.new(file).absolute?
357
+ if File.exist?(file)
358
+ return OpenStudio::OptionalPath.new(OpenStudio.toPath(file))
359
+ end
360
+
361
+ # absolute path does not exist
362
+ return OpenStudio::OptionalPath.new
363
+ end
364
+
365
+ absoluteFilePaths.each do |file_path|
366
+ result = File.join(file_path.to_s, file)
367
+ if File.exist?(result)
368
+ return OpenStudio::OptionalPath.new(OpenStudio.toPath(result))
369
+ end
370
+ end
371
+ OpenStudio::OptionalPath.new
372
+ end
373
+
374
+ # Returns the paths that will be searched in order for measures, default value is './measures/'. Evaluated relative to rootDir if not absolute.
375
+ # std::vector<openstudio::path> measurePaths() const;
376
+ # std::vector<openstudio::path> absoluteMeasurePaths() const;
377
+ def measurePaths
378
+ result = OpenStudio::PathVector.new
379
+ if @workflow[:measure_paths]
380
+ @workflow[:measure_paths].each do |measure_path|
381
+ result << OpenStudio.toPath(measure_path)
382
+ end
383
+ else
384
+ result << OpenStudio.toPath('./measures')
385
+ result << OpenStudio.toPath('../../measures')
386
+ result << OpenStudio.toPath('./')
387
+ end
388
+ result
389
+ end
390
+
391
+ def absoluteMeasurePaths
392
+ result = OpenStudio::PathVector.new
393
+ measurePaths.each do |measure_path|
394
+ result << OpenStudio.toPath(File.absolute_path(measure_path.to_s, rootDir.to_s))
395
+ end
396
+ result
397
+ end
398
+
399
+ # Attempts to find a measure by name, searches through measurePaths in order and returns first match. */
400
+ # boost::optional<openstudio::path> findMeasure(const openstudio::path& measureDir);
401
+ # boost::optional<openstudio::path> findMeasure(const std::string& measureDirName);
402
+ def findMeasure(measureDir)
403
+ measureDir = measureDir.to_s
404
+
405
+ # check if absolute and exists
406
+ if Pathname.new(measureDir).absolute?
407
+ if File.exist?(measureDir)
408
+ return OpenStudio::OptionalPath.new(OpenStudio.toPath(measureDir))
409
+ end
410
+
411
+ # absolute path does not exist
412
+ return OpenStudio::OptionalPath.new
413
+ end
414
+
415
+ absoluteMeasurePaths.each do |measure_path|
416
+ result = File.join(measure_path.to_s, measureDir)
417
+ if File.exist?(result)
418
+ return OpenStudio::OptionalPath.new(OpenStudio.toPath(result))
419
+ end
420
+ end
421
+ OpenStudio::OptionalPath.new
422
+ end
423
+
424
+ # Returns the seed file path. Evaluated relative to filePaths if not absolute.
425
+ # boost::optional<openstudio::path> seedFile() const;
426
+ def seedFile
427
+ result = OpenStudio::OptionalPath.new
428
+ if @workflow[:seed_file]
429
+ result = OpenStudio::OptionalPath.new(OpenStudio.toPath(@workflow[:seed_file]))
430
+ end
431
+ result
432
+ end
433
+
434
+ # Returns the weather file path. Evaluated relative to filePaths if not absolute.
435
+ # boost::optional<openstudio::path> weatherFile() const;
436
+ def weatherFile
437
+ result = OpenStudio::OptionalPath.new
438
+ if @workflow[:weather_file]
439
+ result = OpenStudio::OptionalPath.new(OpenStudio.toPath(@workflow[:weather_file]))
440
+ end
441
+ result
442
+ end
443
+
444
+ # Returns the workflow steps. */
445
+ # std::vector<WorkflowStep> workflowSteps() const;
446
+ def workflowSteps
447
+ result = []
448
+ @workflow[:steps].each do |step|
449
+ result << WorkflowStep_Shim.new(step)
450
+ end
451
+ result
452
+ end
453
+
454
+ def completedStatus
455
+ if @workflow[:completed_status]
456
+ Optional_Shim.new(@workflow[:completed_status])
457
+ else
458
+ Optional_Shim.new(nil)
459
+ end
460
+ end
461
+
462
+ def setCompletedStatus(status)
463
+ @workflow[:completed_status] = status
464
+ @workflow[:completed_at] = timeString
465
+ end
466
+
467
+ def setEplusoutErr(eplusout_err)
468
+ @workflow[:eplusout_err] = eplusout_err
469
+ end
470
+
471
+ # return empty optional
472
+ def runOptions
473
+ return Optional_Shim.new(nil)
474
+ end
475
+ end