Class: WorkflowRunner
- Inherits:
-
OpenStudio::Ruleset::OSRunner
- Object
- OpenStudio::Ruleset::OSRunner
- WorkflowRunner
- Defined in:
- lib/openstudio/workflow_runner.rb
Overview
Extend OS Runner to persist measure information throughout the workflow Provide shims to support OpenStudio 2.X functionality in OpenStudio 1.X
Instance Attribute Summary collapse
-
#analysis ⇒ Object
readonly
Returns the value of attribute analysis.
-
#datapoint ⇒ Object
readonly
Returns the value of attribute datapoint.
Instance Method Summary collapse
-
#halted ⇒ Object
Overload halted.
-
#haltWorkflow(completed_status) ⇒ Object
Overload haltSimulation.
-
#incrementStep ⇒ Object
incrementing step copies result to previous results void incrementStep();.
-
#initialize(multi_logger, workflow_json, openstudio_2) ⇒ WorkflowRunner
constructor
A new instance of WorkflowRunner.
-
#languagePreference ⇒ Object
Returns preferred language, e.g.
-
#prepareForUserScriptRun(userScript) ⇒ Object
called right when each measure is run only called in OpenStudio 1.X virtual void prepareForUserScriptRun(const UserScript& userScript);.
-
#registerError(message) ⇒ Object
Overload registerError.
-
#registerFinalCondition(message) ⇒ Object
Overload registerFinalCondition.
-
#registerInfo(message) ⇒ Object
Overload registerInfo.
-
#registerInitialCondition(message) ⇒ Object
Overload registerInitialCondition.
-
#registerWarning(message) ⇒ Object
Overload registerInfo.
- #result ⇒ Object
- #setAnalysis(analysis) ⇒ Object
- #setDatapoint(datapoint) ⇒ Object
- #timeString ⇒ Object
-
#unitsPreference ⇒ Object
Returns preferred unit system, either ‘IP’ or ‘SI’.
-
#workflow ⇒ Object
Returns the workflow currently being run.
Constructor Details
#initialize(multi_logger, workflow_json, openstudio_2) ⇒ WorkflowRunner
Returns a new instance of WorkflowRunner.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/openstudio/workflow_runner.rb', line 13 def initialize(multi_logger, workflow_json, openstudio_2) @multi_logger = multi_logger @workflow_json = workflow_json @openstudio_2 = openstudio_2 @datapoint = nil @analysis = nil @halted = false @use_os_halted = OpenStudio::Ruleset::OSRunner.method_defined?(:halted) begin # OpenStudio 2.X super(@workflow_json) rescue Exception => e # OpenStudio 1.X @workflow = workflow_json @units_preference = 'SI' @language_preference = 'EN' super() end end |
Instance Attribute Details
#analysis ⇒ Object (readonly)
Returns the value of attribute analysis.
38 39 40 |
# File 'lib/openstudio/workflow_runner.rb', line 38 def analysis @analysis end |
#datapoint ⇒ Object (readonly)
Returns the value of attribute datapoint.
38 39 40 |
# File 'lib/openstudio/workflow_runner.rb', line 38 def datapoint @datapoint end |
Instance Method Details
#halted ⇒ Object
Overload halted
230 231 232 233 234 |
# File 'lib/openstudio/workflow_runner.rb', line 230 def halted return @halted unless @use_os_halted super end |
#haltWorkflow(completed_status) ⇒ Object
Overload haltSimulation
220 221 222 223 224 225 226 227 |
# File 'lib/openstudio/workflow_runner.rb', line 220 def haltWorkflow(completed_status) if @use_os_halted super else @halted = true @workflow_json.setCompletedStatus(completed_status) end end |
#incrementStep ⇒ Object
incrementing step copies result to previous results void incrementStep();
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/openstudio/workflow_runner.rb', line 178 def incrementStep if @openstudio_2 super else # compute result current_result = result @workflow.incrementStep end end |
#languagePreference ⇒ Object
Returns preferred language, e.g. ‘en’ or ‘fr’. New in OS 2.0. */ std::string languagePreference() const;
70 71 72 73 74 75 76 |
# File 'lib/openstudio/workflow_runner.rb', line 70 def languagePreference if @openstudio_2 super else @language_preference end end |
#prepareForUserScriptRun(userScript) ⇒ Object
called right when each measure is run only called in OpenStudio 1.X virtual void prepareForUserScriptRun(const UserScript& userScript);
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/openstudio/workflow_runner.rb', line 81 def prepareForUserScriptRun(userScript) if @openstudio_2 prepareForMeasureRun(userScript) else current_step = @workflow.currentStep unless current_step.empty? current_step.get.step[:result] = {} current_step.get.step[:result][:started_at] = timeString end # TODO: capture std out and err # TODO: get initial list of files super end end |
#registerError(message) ⇒ Object
Overload registerError
202 203 204 205 |
# File 'lib/openstudio/workflow_runner.rb', line 202 def registerError() super @multi_logger.error end |
#registerFinalCondition(message) ⇒ Object
Overload registerFinalCondition
214 215 216 217 |
# File 'lib/openstudio/workflow_runner.rb', line 214 def registerFinalCondition() super @multi_logger.info end |
#registerInfo(message) ⇒ Object
Overload registerInfo
190 191 192 193 |
# File 'lib/openstudio/workflow_runner.rb', line 190 def registerInfo() super @multi_logger.info end |
#registerInitialCondition(message) ⇒ Object
Overload registerInitialCondition
208 209 210 211 |
# File 'lib/openstudio/workflow_runner.rb', line 208 def registerInitialCondition() super @multi_logger.info end |
#registerWarning(message) ⇒ Object
Overload registerInfo
196 197 198 199 |
# File 'lib/openstudio/workflow_runner.rb', line 196 def registerWarning() super @multi_logger.warn end |
#result ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/openstudio/workflow_runner.rb', line 100 def result if @openstudio_2 super else os_result = super current_step = @workflow.currentStep if current_step.empty? raise 'Cannot find current_step' end current_step = current_step.get if current_step.step[:result].nil? # skipped, prepareForUserScriptRun was not called current_step.step[:result] = {} current_step.step[:result][:started_at] = timeString current_step.step[:result][:step_result] = 'Skip' else current_step.step[:result][:step_result] = os_result.value.valueName end current_step.step[:result][:completed_at] = timeString # TODO: restore stdout and stderr # TODO: check for created files current_step.step[:result][:step_errors] = [] os_result.errors.each do |error| current_step.step[:result][:step_errors] << error.logMessage end current_step.step[:result][:step_warnings] = [] os_result.warnings.each do |warning| current_step.step[:result][:step_warnings] << warning.logMessage end current_step.step[:result][:step_info] = [] os_result.info.each do |info| current_step.step[:result][:step_info] << info.logMessage end unless os_result.initialCondition.empty? current_step.step[:result][:initial_condition] = os_result.initialCondition.get.logMessage current_step.step[:result][:step_initial_condition] = os_result.initialCondition.get.logMessage end unless os_result.finalCondition.empty? current_step.step[:result][:final_condition] = os_result.finalCondition.get.logMessage current_step.step[:result][:step_final_condition] = os_result.finalCondition.get.logMessage end current_step.step[:result][:step_values] = [] os_result.attributes.each do |attribute| result = nil if attribute.valueType == 'Boolean'.to_AttributeValueType result = { name: attribute.name, value: attribute.valueAsBoolean, type: 'Boolean' } elsif attribute.valueType == 'Double'.to_AttributeValueType result = { name: attribute.name, value: attribute.valueAsDouble, type: 'Double' } elsif attribute.valueType == 'Integer'.to_AttributeValueType result = { name: attribute.name, value: attribute.valueAsInteger, type: 'Integer' } elsif attribute.valueType == 'Unsigned'.to_AttributeValueType result = { name: attribute.name, value: attribute.valueAsUnsigned, type: 'Integer' } elsif attribute.valueType == 'String'.to_AttributeValueType result = { name: attribute.name, value: attribute.valueAsString, type: 'String' } end current_step.step[:result][:step_values] << result unless result.nil? end return WorkflowStepResult_Shim.new(current_step.step[:result]) end end |
#setAnalysis(analysis) ⇒ Object
44 45 46 |
# File 'lib/openstudio/workflow_runner.rb', line 44 def setAnalysis(analysis) @analysis = analysis end |
#setDatapoint(datapoint) ⇒ Object
40 41 42 |
# File 'lib/openstudio/workflow_runner.rb', line 40 def setDatapoint(datapoint) @datapoint = datapoint end |
#timeString ⇒ Object
34 35 36 |
# File 'lib/openstudio/workflow_runner.rb', line 34 def timeString ::Time.now.utc.strftime('%Y%m%dT%H%M%SZ') end |
#unitsPreference ⇒ Object
Returns preferred unit system, either ‘IP’ or ‘SI’. New in OS 2.0. */ std::string unitsPreference() const;
60 61 62 63 64 65 66 |
# File 'lib/openstudio/workflow_runner.rb', line 60 def unitsPreference if @openstudio_2 super else @units_preference end end |
#workflow ⇒ Object
Returns the workflow currently being run. New in OS 2.0. WorkflowJSON workflow() const;
50 51 52 53 54 55 56 |
# File 'lib/openstudio/workflow_runner.rb', line 50 def workflow if @openstudio_2 super else @workflow end end |