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,268 +1,263 @@
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
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_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
+ attr_reader :datapoint
67
+
68
+ def setDatapoint(datapoint)
69
+ @datapoint = datapoint
70
+ end
71
+
72
+ attr_reader :analysis
73
+
74
+ def setAnalysis(analysis)
75
+ @analysis = analysis
76
+ end
77
+
78
+ # Returns the workflow currently being run. New in OS 2.0.
79
+ # WorkflowJSON workflow() const;
80
+ def workflow
81
+ if @openstudio_2
82
+ super
83
+ else
84
+ @workflow
85
+ end
86
+ end
87
+
88
+ # Returns preferred unit system, either 'IP' or 'SI'. New in OS 2.0. */
89
+ # std::string unitsPreference() const;
90
+ def unitsPreference
91
+ if @openstudio_2
92
+ super
93
+ else
94
+ @units_preference
95
+ end
96
+ end
97
+
98
+ # Returns preferred language, e.g. 'en' or 'fr'. New in OS 2.0. */
99
+ # std::string languagePreference() const;
100
+ def languagePreference
101
+ if @openstudio_2
102
+ super
103
+ else
104
+ @language_preference
105
+ end
106
+ end
107
+
108
+ # called right when each measure is run
109
+ # only called in OpenStudio 1.X
110
+ # virtual void prepareForUserScriptRun(const UserScript& userScript);
111
+ def prepareForUserScriptRun(userScript)
112
+ if @openstudio_2
113
+ prepareForMeasureRun(userScript)
114
+ else
115
+ current_step = @workflow.currentStep
116
+
117
+ unless current_step.empty?
118
+ current_step.get.step[:result] = {}
119
+ current_step.get.step[:result][:started_at] = timeString
120
+ end
121
+
122
+ # TODO: capture std out and err
123
+
124
+ # TODO: get initial list of files
125
+
126
+ super
127
+ end
128
+ end
129
+
130
+ def result
131
+ if @openstudio_2
132
+ super
133
+ else
134
+ os_result = super
135
+
136
+ current_step = @workflow.currentStep
137
+
138
+ if current_step.empty?
139
+ raise 'Cannot find current_step'
140
+ end
141
+ current_step = current_step.get
142
+
143
+ if current_step.step[:result].nil?
144
+ # skipped, prepareForUserScriptRun was not called
145
+ current_step.step[:result] = {}
146
+ current_step.step[:result][:started_at] = timeString
147
+ current_step.step[:result][:step_result] = 'Skip'
148
+ else
149
+ current_step.step[:result][:step_result] = os_result.value.valueName
150
+ end
151
+
152
+ current_step.step[:result][:completed_at] = timeString
153
+
154
+ # TODO: restore stdout and stderr
155
+
156
+ # TODO: check for created files
157
+
158
+ current_step.step[:result][:step_errors] = []
159
+ os_result.errors.each do |error|
160
+ current_step.step[:result][:step_errors] << error.logMessage
161
+ end
162
+
163
+ current_step.step[:result][:step_warnings] = []
164
+ os_result.warnings.each do |warning|
165
+ current_step.step[:result][:step_warnings] << warning.logMessage
166
+ end
167
+
168
+ current_step.step[:result][:step_info] = []
169
+ os_result.info.each do |info|
170
+ current_step.step[:result][:step_info] << info.logMessage
171
+ end
172
+
173
+ unless os_result.initialCondition.empty?
174
+ current_step.step[:result][:initial_condition] = os_result.initialCondition.get.logMessage
175
+ current_step.step[:result][:step_initial_condition] = os_result.initialCondition.get.logMessage
176
+ end
177
+
178
+ unless os_result.finalCondition.empty?
179
+ current_step.step[:result][:final_condition] = os_result.finalCondition.get.logMessage
180
+ current_step.step[:result][:step_final_condition] = os_result.finalCondition.get.logMessage
181
+ end
182
+
183
+ current_step.step[:result][:step_values] = []
184
+ os_result.attributes.each do |attribute|
185
+ result = nil
186
+ if attribute.valueType == 'Boolean'.to_AttributeValueType
187
+ result = { name: attribute.name, value: attribute.valueAsBoolean, type: 'Boolean' }
188
+ elsif attribute.valueType == 'Double'.to_AttributeValueType
189
+ result = { name: attribute.name, value: attribute.valueAsDouble, type: 'Double' }
190
+ elsif attribute.valueType == 'Integer'.to_AttributeValueType
191
+ result = { name: attribute.name, value: attribute.valueAsInteger, type: 'Integer' }
192
+ elsif attribute.valueType == 'Unsigned'.to_AttributeValueType
193
+ result = { name: attribute.name, value: attribute.valueAsUnsigned, type: 'Integer' }
194
+ elsif attribute.valueType == 'String'.to_AttributeValueType
195
+ result = { name: attribute.name, value: attribute.valueAsString, type: 'String' }
196
+ end
197
+
198
+ current_step.step[:result][:step_values] << result unless result.nil?
199
+ end
200
+
201
+ return WorkflowStepResult_Shim.new(current_step.step[:result])
202
+ end
203
+ end
204
+
205
+ # incrementing step copies result to previous results
206
+ # void incrementStep();
207
+ def incrementStep
208
+ if @openstudio_2
209
+ super
210
+ else
211
+ # compute result
212
+ current_result = result
213
+
214
+ @workflow.incrementStep
215
+ end
216
+ end
217
+
218
+ # Overload registerInfo
219
+ def registerInfo(message)
220
+ super
221
+ @multi_logger.info message
222
+ end
223
+
224
+ # Overload registerInfo
225
+ def registerWarning(message)
226
+ super
227
+ @multi_logger.warn message
228
+ end
229
+
230
+ # Overload registerError
231
+ def registerError(message)
232
+ super
233
+ @multi_logger.error message
234
+ end
235
+
236
+ # Overload registerInitialCondition
237
+ def registerInitialCondition(message)
238
+ super
239
+ @multi_logger.info message
240
+ end
241
+
242
+ # Overload registerFinalCondition
243
+ def registerFinalCondition(message)
244
+ super
245
+ @multi_logger.info message
246
+ end
247
+
248
+ # Overload haltSimulation
249
+ def haltWorkflow(completed_status)
250
+ if @use_os_halted
251
+ super
252
+ else
253
+ @halted = true
254
+ @workflow_json.setCompletedStatus(completed_status)
255
+ end
256
+ end
257
+
258
+ # Overload halted
259
+ def halted
260
+ return @halted unless @use_os_halted
261
+ super
262
+ end
263
+ end