openstudio-workflow 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -72
  3. data/README.md +93 -93
  4. data/Rakefile +36 -36
  5. data/lib/openstudio-workflow.rb +65 -49
  6. data/lib/openstudio/workflow/adapters/input/local.rb +324 -301
  7. data/lib/openstudio/workflow/adapters/output/local.rb +161 -97
  8. data/lib/openstudio/workflow/adapters/output/socket.rb +107 -91
  9. data/lib/openstudio/workflow/adapters/output/web.rb +82 -66
  10. data/lib/openstudio/workflow/adapters/output_adapter.rb +163 -147
  11. data/lib/openstudio/workflow/job.rb +57 -22
  12. data/lib/openstudio/workflow/jobs/resources/monthly_report.idf +222 -222
  13. data/lib/openstudio/workflow/jobs/run_energyplus.rb +70 -54
  14. data/lib/openstudio/workflow/jobs/run_ep_measures.rb +73 -57
  15. data/lib/openstudio/workflow/jobs/run_initialization.rb +203 -171
  16. data/lib/openstudio/workflow/jobs/run_os_measures.rb +89 -73
  17. data/lib/openstudio/workflow/jobs/run_postprocess.rb +73 -57
  18. data/lib/openstudio/workflow/jobs/run_preprocess.rb +104 -80
  19. data/lib/openstudio/workflow/jobs/run_reporting_measures.rb +118 -102
  20. data/lib/openstudio/workflow/jobs/run_translation.rb +84 -68
  21. data/lib/openstudio/workflow/multi_delegator.rb +62 -46
  22. data/lib/openstudio/workflow/registry.rb +172 -137
  23. data/lib/openstudio/workflow/run.rb +328 -312
  24. data/lib/openstudio/workflow/time_logger.rb +96 -53
  25. data/lib/openstudio/workflow/util.rb +49 -14
  26. data/lib/openstudio/workflow/util/energyplus.rb +605 -570
  27. data/lib/openstudio/workflow/util/io.rb +68 -33
  28. data/lib/openstudio/workflow/util/measure.rb +650 -615
  29. data/lib/openstudio/workflow/util/model.rb +151 -100
  30. data/lib/openstudio/workflow/util/post_process.rb +238 -187
  31. data/lib/openstudio/workflow/util/weather_file.rb +143 -108
  32. data/lib/openstudio/workflow/version.rb +40 -24
  33. data/lib/openstudio/workflow_json.rb +476 -443
  34. data/lib/openstudio/workflow_runner.rb +268 -252
  35. metadata +23 -23
@@ -1,252 +1,268 @@
1
- ######################################################################
2
- # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
- # All rights reserved.
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License as published by the Free Software Foundation; either
8
- # version 2.1 of the License, or (at your option) any later version.
9
- #
10
- # This library is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- # Lesser General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU Lesser General Public
16
- # License along with this library; if not, write to the Free Software
17
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- ######################################################################
19
-
20
- require_relative 'workflow_json'
21
-
22
- # Extend OS Runner to persist measure information throughout the workflow
23
- # Provide shims to support OpenStudio 2.X functionality in OpenStudio 1.X
24
- class WorkflowRunner < OpenStudio::Ruleset::OSRunner
25
- def initialize(multi_logger, workflow_json, openstudio_2)
26
- @multi_logger = multi_logger
27
- @workflow_json = workflow_json
28
- @openstudio_2 = openstudio_2
29
- @datapoint = nil
30
- @analysis = nil
31
- @halted = false
32
- @use_os_halted = OpenStudio::Ruleset::OSRunner.method_defined?(:halted)
33
-
34
- begin
35
- # OpenStudio 2.X
36
- super(@workflow_json)
37
- rescue Exception => e
38
- # OpenStudio 1.X
39
- @workflow = workflow_json
40
- @units_preference = 'SI'
41
- @language_preference = 'EN'
42
- super()
43
- end
44
- end
45
-
46
- def timeString
47
- ::Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
48
- end
49
-
50
- def datapoint
51
- @datapoint
52
- end
53
-
54
- def setDatapoint(datapoint)
55
- @datapoint = datapoint
56
- end
57
-
58
- def analysis
59
- @analysis
60
- end
61
-
62
- def setAnalysis(analysis)
63
- @analysis = analysis
64
- end
65
-
66
- # Returns the workflow currently being run. New in OS 2.0.
67
- # WorkflowJSON workflow() const;
68
- def workflow
69
- if @openstudio_2
70
- super
71
- else
72
- @workflow
73
- end
74
- end
75
-
76
- # Returns preferred unit system, either 'IP' or 'SI'. New in OS 2.0. */
77
- # std::string unitsPreference() const;
78
- def unitsPreference
79
- if @openstudio_2
80
- super
81
- else
82
- @units_preference
83
- end
84
- end
85
-
86
- # Returns preferred language, e.g. 'en' or 'fr'. New in OS 2.0. */
87
- # std::string languagePreference() const;
88
- def languagePreference
89
- if @openstudio_2
90
- super
91
- else
92
- @language_preference
93
- end
94
- end
95
-
96
- # called right when each measure is run
97
- # only called in OpenStudio 1.X
98
- # virtual void prepareForUserScriptRun(const UserScript& userScript);
99
- def prepareForUserScriptRun(userScript)
100
-
101
- if @openstudio_2
102
- prepareForMeasureRun(userScript)
103
- else
104
- current_step = @workflow.currentStep
105
-
106
- unless current_step.empty?
107
- current_step.get.step[:result] = {}
108
- current_step.get.step[:result][:started_at] = timeString
109
- end
110
-
111
- # TODO: capture std out and err
112
-
113
- # TODO: get initial list of files
114
-
115
- super
116
- end
117
- end
118
-
119
- def result
120
- if @openstudio_2
121
- super
122
- else
123
- os_result = super
124
-
125
- current_step = @workflow.currentStep
126
-
127
- if current_step.empty?
128
- raise 'Cannot find current_step'
129
- end
130
- current_step = current_step.get
131
-
132
- if current_step.step[:result].nil?
133
- # skipped, prepareForUserScriptRun was not called
134
- current_step.step[:result] = {}
135
- current_step.step[:result][:started_at] = timeString
136
- current_step.step[:result][:step_result] = 'Skip'
137
- else
138
- current_step.step[:result][:step_result] = os_result.value.valueName
139
- end
140
-
141
- current_step.step[:result][:completed_at] = timeString
142
-
143
- # TODO: restore stdout and stderr
144
-
145
- # TODO: check for created files
146
-
147
- current_step.step[:result][:step_errors] = []
148
- os_result.errors.each do |error|
149
- current_step.step[:result][:step_errors] << error.logMessage
150
- end
151
-
152
- current_step.step[:result][:step_warnings] = []
153
- os_result.warnings.each do |warning|
154
- current_step.step[:result][:step_warnings] << warning.logMessage
155
- end
156
-
157
- current_step.step[:result][:step_info] = []
158
- os_result.info.each do |info|
159
- current_step.step[:result][:step_info] << info.logMessage
160
- end
161
-
162
- unless os_result.initialCondition.empty?
163
- current_step.step[:result][:initial_condition] = os_result.initialCondition.get.logMessage
164
- current_step.step[:result][:step_initial_condition] = os_result.initialCondition.get.logMessage
165
- end
166
-
167
- unless os_result.finalCondition.empty?
168
- current_step.step[:result][:final_condition] = os_result.finalCondition.get.logMessage
169
- current_step.step[:result][:step_final_condition] = os_result.finalCondition.get.logMessage
170
- end
171
-
172
- current_step.step[:result][:step_values] = []
173
- os_result.attributes.each do |attribute|
174
- result = nil
175
- if attribute.valueType == 'Boolean'.to_AttributeValueType
176
- result = { name: attribute.name, value: attribute.valueAsBoolean, type: 'Boolean' }
177
- elsif attribute.valueType == 'Double'.to_AttributeValueType
178
- result = { name: attribute.name, value: attribute.valueAsDouble, type: 'Double' }
179
- elsif attribute.valueType == 'Integer'.to_AttributeValueType
180
- result = { name: attribute.name, value: attribute.valueAsInteger, type: 'Integer' }
181
- elsif attribute.valueType == 'Unsigned'.to_AttributeValueType
182
- result = { name: attribute.name, value: attribute.valueAsUnsigned, type: 'Integer' }
183
- elsif attribute.valueType == 'String'.to_AttributeValueType
184
- result = { name: attribute.name, value: attribute.valueAsString, type: 'String' }
185
- end
186
-
187
- current_step.step[:result][:step_values] << result unless result.nil?
188
- end
189
-
190
- return WorkflowStepResult_Shim.new(current_step.step[:result])
191
- end
192
- end
193
-
194
- # incrementing step copies result to previous results
195
- # void incrementStep();
196
- def incrementStep
197
- if @openstudio_2
198
- super
199
- else
200
- # compute result
201
- current_result = result
202
-
203
- @workflow.incrementStep
204
- end
205
- end
206
-
207
- # Overload registerInfo
208
- def registerInfo(message)
209
- super
210
- @multi_logger.info message
211
- end
212
-
213
- # Overload registerInfo
214
- def registerWarning(message)
215
- super
216
- @multi_logger.warn message
217
- end
218
-
219
- # Overload registerError
220
- def registerError(message)
221
- super
222
- @multi_logger.error message
223
- end
224
-
225
- # Overload registerInitialCondition
226
- def registerInitialCondition(message)
227
- super
228
- @multi_logger.info message
229
- end
230
-
231
- # Overload registerFinalCondition
232
- def registerFinalCondition(message)
233
- super
234
- @multi_logger.info message
235
- end
236
-
237
- # Overload haltSimulation
238
- def haltWorkflow(completed_status)
239
- if @use_os_halted
240
- super
241
- else
242
- @halted = true
243
- @workflow_json.setCompletedStatus(completed_status)
244
- end
245
- end
246
-
247
- # Overload halted
248
- def halted
249
- return @halted unless @use_os_halted
250
- super
251
- end
252
- end
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_relative 'workflow_json'
37
+
38
+ # Extend OS Runner to persist measure information throughout the workflow
39
+ # Provide shims to support OpenStudio 2.X functionality in OpenStudio 1.X
40
+ class WorkflowRunner < OpenStudio::Ruleset::OSRunner
41
+ def initialize(multi_logger, workflow_json, openstudio_2)
42
+ @multi_logger = multi_logger
43
+ @workflow_json = workflow_json
44
+ @openstudio_2 = openstudio_2
45
+ @datapoint = nil
46
+ @analysis = nil
47
+ @halted = false
48
+ @use_os_halted = OpenStudio::Ruleset::OSRunner.method_defined?(:halted)
49
+
50
+ begin
51
+ # OpenStudio 2.X
52
+ super(@workflow_json)
53
+ rescue Exception => e
54
+ # OpenStudio 1.X
55
+ @workflow = workflow_json
56
+ @units_preference = 'SI'
57
+ @language_preference = 'EN'
58
+ super()
59
+ end
60
+ end
61
+
62
+ def timeString
63
+ ::Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
64
+ end
65
+
66
+ def datapoint
67
+ @datapoint
68
+ end
69
+
70
+ def setDatapoint(datapoint)
71
+ @datapoint = datapoint
72
+ end
73
+
74
+ def analysis
75
+ @analysis
76
+ end
77
+
78
+ def setAnalysis(analysis)
79
+ @analysis = analysis
80
+ end
81
+
82
+ # Returns the workflow currently being run. New in OS 2.0.
83
+ # WorkflowJSON workflow() const;
84
+ def workflow
85
+ if @openstudio_2
86
+ super
87
+ else
88
+ @workflow
89
+ end
90
+ end
91
+
92
+ # Returns preferred unit system, either 'IP' or 'SI'. New in OS 2.0. */
93
+ # std::string unitsPreference() const;
94
+ def unitsPreference
95
+ if @openstudio_2
96
+ super
97
+ else
98
+ @units_preference
99
+ end
100
+ end
101
+
102
+ # Returns preferred language, e.g. 'en' or 'fr'. New in OS 2.0. */
103
+ # std::string languagePreference() const;
104
+ def languagePreference
105
+ if @openstudio_2
106
+ super
107
+ else
108
+ @language_preference
109
+ end
110
+ end
111
+
112
+ # called right when each measure is run
113
+ # only called in OpenStudio 1.X
114
+ # virtual void prepareForUserScriptRun(const UserScript& userScript);
115
+ def prepareForUserScriptRun(userScript)
116
+
117
+ if @openstudio_2
118
+ prepareForMeasureRun(userScript)
119
+ else
120
+ current_step = @workflow.currentStep
121
+
122
+ unless current_step.empty?
123
+ current_step.get.step[:result] = {}
124
+ current_step.get.step[:result][:started_at] = timeString
125
+ end
126
+
127
+ # TODO: capture std out and err
128
+
129
+ # TODO: get initial list of files
130
+
131
+ super
132
+ end
133
+ end
134
+
135
+ def result
136
+ if @openstudio_2
137
+ super
138
+ else
139
+ os_result = super
140
+
141
+ current_step = @workflow.currentStep
142
+
143
+ if current_step.empty?
144
+ raise 'Cannot find current_step'
145
+ end
146
+ current_step = current_step.get
147
+
148
+ if current_step.step[:result].nil?
149
+ # skipped, prepareForUserScriptRun was not called
150
+ current_step.step[:result] = {}
151
+ current_step.step[:result][:started_at] = timeString
152
+ current_step.step[:result][:step_result] = 'Skip'
153
+ else
154
+ current_step.step[:result][:step_result] = os_result.value.valueName
155
+ end
156
+
157
+ current_step.step[:result][:completed_at] = timeString
158
+
159
+ # TODO: restore stdout and stderr
160
+
161
+ # TODO: check for created files
162
+
163
+ current_step.step[:result][:step_errors] = []
164
+ os_result.errors.each do |error|
165
+ current_step.step[:result][:step_errors] << error.logMessage
166
+ end
167
+
168
+ current_step.step[:result][:step_warnings] = []
169
+ os_result.warnings.each do |warning|
170
+ current_step.step[:result][:step_warnings] << warning.logMessage
171
+ end
172
+
173
+ current_step.step[:result][:step_info] = []
174
+ os_result.info.each do |info|
175
+ current_step.step[:result][:step_info] << info.logMessage
176
+ end
177
+
178
+ unless os_result.initialCondition.empty?
179
+ current_step.step[:result][:initial_condition] = os_result.initialCondition.get.logMessage
180
+ current_step.step[:result][:step_initial_condition] = os_result.initialCondition.get.logMessage
181
+ end
182
+
183
+ unless os_result.finalCondition.empty?
184
+ current_step.step[:result][:final_condition] = os_result.finalCondition.get.logMessage
185
+ current_step.step[:result][:step_final_condition] = os_result.finalCondition.get.logMessage
186
+ end
187
+
188
+ current_step.step[:result][:step_values] = []
189
+ os_result.attributes.each do |attribute|
190
+ result = nil
191
+ if attribute.valueType == 'Boolean'.to_AttributeValueType
192
+ result = { name: attribute.name, value: attribute.valueAsBoolean, type: 'Boolean' }
193
+ elsif attribute.valueType == 'Double'.to_AttributeValueType
194
+ result = { name: attribute.name, value: attribute.valueAsDouble, type: 'Double' }
195
+ elsif attribute.valueType == 'Integer'.to_AttributeValueType
196
+ result = { name: attribute.name, value: attribute.valueAsInteger, type: 'Integer' }
197
+ elsif attribute.valueType == 'Unsigned'.to_AttributeValueType
198
+ result = { name: attribute.name, value: attribute.valueAsUnsigned, type: 'Integer' }
199
+ elsif attribute.valueType == 'String'.to_AttributeValueType
200
+ result = { name: attribute.name, value: attribute.valueAsString, type: 'String' }
201
+ end
202
+
203
+ current_step.step[:result][:step_values] << result unless result.nil?
204
+ end
205
+
206
+ return WorkflowStepResult_Shim.new(current_step.step[:result])
207
+ end
208
+ end
209
+
210
+ # incrementing step copies result to previous results
211
+ # void incrementStep();
212
+ def incrementStep
213
+ if @openstudio_2
214
+ super
215
+ else
216
+ # compute result
217
+ current_result = result
218
+
219
+ @workflow.incrementStep
220
+ end
221
+ end
222
+
223
+ # Overload registerInfo
224
+ def registerInfo(message)
225
+ super
226
+ @multi_logger.info message
227
+ end
228
+
229
+ # Overload registerInfo
230
+ def registerWarning(message)
231
+ super
232
+ @multi_logger.warn message
233
+ end
234
+
235
+ # Overload registerError
236
+ def registerError(message)
237
+ super
238
+ @multi_logger.error message
239
+ end
240
+
241
+ # Overload registerInitialCondition
242
+ def registerInitialCondition(message)
243
+ super
244
+ @multi_logger.info message
245
+ end
246
+
247
+ # Overload registerFinalCondition
248
+ def registerFinalCondition(message)
249
+ super
250
+ @multi_logger.info message
251
+ end
252
+
253
+ # Overload haltSimulation
254
+ def haltWorkflow(completed_status)
255
+ if @use_os_halted
256
+ super
257
+ else
258
+ @halted = true
259
+ @workflow_json.setCompletedStatus(completed_status)
260
+ end
261
+ end
262
+
263
+ # Overload halted
264
+ def halted
265
+ return @halted unless @use_os_halted
266
+ super
267
+ end
268
+ end