Class: HoneybeeAdapter
- Inherits:
-
OpenStudio::Workflow::OutputAdapters
- Object
- OpenStudio::Workflow::OutputAdapters
- HoneybeeAdapter
- Defined in:
- lib/files/honeybee_adapter.rb
Overview
Local file based workflow
Instance Method Summary collapse
-
#communicate_complete ⇒ Object
Write to the filesystem that the process has completed.
-
#communicate_energyplus_stdout(line, options = {}) ⇒ Object
Do nothing on EnergyPlus stdout.
-
#communicate_failure ⇒ Object
Write to the filesystem that the process has failed.
-
#communicate_measure_attributes(measure_attributes, _ = nil) ⇒ Object
Write the measure attributes to the filesystem.
-
#communicate_measure_result(result, options = {}) ⇒ Object
Do nothing on Measure result.
-
#communicate_objective_function(objectives, _ = nil) ⇒ Object
Write the objective function results to the filesystem.
-
#communicate_results(directory, results) ⇒ Object
Write the results of the workflow to the filesystem.
-
#communicate_started ⇒ Object
Write to the filesystem that the process has started.
-
#communicate_transition(_ = nil, _ = nil, _ = nil) ⇒ Object
Do nothing on a state transition.
-
#initialize(options = {}) ⇒ HoneybeeAdapter
constructor
A new instance of HoneybeeAdapter.
Constructor Details
#initialize(options = {}) ⇒ HoneybeeAdapter
Returns a new instance of HoneybeeAdapter.
36 37 38 39 40 |
# File 'lib/files/honeybee_adapter.rb', line 36 def initialize( = {}) STDOUT.flush super end |
Instance Method Details
#communicate_complete ⇒ Object
Write to the filesystem that the process has completed
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/files/honeybee_adapter.rb', line 58 def communicate_complete File.open("#{@options[:output_directory]}/finished.job", 'w') do |f| f << "Finished Workflow #{::Time.now}" # make sure data is written to the disk one way or the other begin f.fsync rescue f.flush end end end |
#communicate_energyplus_stdout(line, options = {}) ⇒ Object
Do nothing on EnergyPlus stdout
91 92 93 |
# File 'lib/files/honeybee_adapter.rb', line 91 def communicate_energyplus_stdout(line, = {}) puts "EnergyPlus: #{line}" end |
#communicate_failure ⇒ Object
Write to the filesystem that the process has failed
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/files/honeybee_adapter.rb', line 72 def communicate_failure File.open("#{@options[:output_directory]}/failed.job", 'w') do |f| f << "Failed Workflow #{::Time.now}" # make sure data is written to the disk one way or the other begin f.fsync rescue f.flush end end end |
#communicate_measure_attributes(measure_attributes, _ = nil) ⇒ Object
Write the measure attributes to the filesystem
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/files/honeybee_adapter.rb', line 117 def communicate_measure_attributes(measure_attributes, _ = nil) attributes_file = "#{@options[:output_directory]}/measure_attributes.json" FileUtils.rm_f(attributes_file) if File.exist?(attributes_file) File.open(attributes_file, 'w') do |f| f << JSON.pretty_generate(measure_attributes) # make sure data is written to the disk one way or the other begin f.fsync rescue f.flush end end end |
#communicate_measure_result(result, options = {}) ⇒ Object
Do nothing on Measure result
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/files/honeybee_adapter.rb', line 97 def communicate_measure_result(result, = {}) step_result = result.stepResult initial_condition = result.stepInitialCondition final_condition = result.stepFinalCondition errors = result.stepErrors warnings = result.stepWarnings infos = result.stepInfo # Mirrors WorkflowStepResult::string tab = 'Honeybee ' puts "#{tab}Result: #{step_result.get.valueName}" if !step_result.empty? puts "#{tab}Initial Condition: #{initial_condition.get}" if !initial_condition.empty? puts "#{tab}Final Condition: #{final_condition.get}" if !final_condition.empty? errors.each { |error| puts "#{tab}Error: #{error}" } warnings.each { |warning| puts "#{tab}Warn: #{warning}" } infos.each { |info| puts "#{tab}Info: #{info}" } end |
#communicate_objective_function(objectives, _ = nil) ⇒ Object
Write the objective function results to the filesystem
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/files/honeybee_adapter.rb', line 133 def communicate_objective_function(objectives, _ = nil) obj_fun_file = "#{@options[:output_directory]}/objectives.json" FileUtils.rm_f(obj_fun_file) if File.exist?(obj_fun_file) File.open(obj_fun_file, 'w') do |f| f << JSON.pretty_generate(objectives) # make sure data is written to the disk one way or the other begin f.fsync rescue f.flush end end end |
#communicate_results(directory, results) ⇒ Object
Write the results of the workflow to the filesystem
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/files/honeybee_adapter.rb', line 149 def communicate_results(directory, results) zip_results(directory) if results.is_a? Hash # DLM: don't we want this in the results zip? # DLM: deprecate in favor of out.osw File.open("#{@options[:output_directory]}/data_point_out.json", 'w') do |f| f << JSON.pretty_generate(results) # make sure data is written to the disk one way or the other begin f.fsync rescue f.flush end end else #puts "Unknown datapoint result type. Please handle #{results.class}" end end |
#communicate_started ⇒ Object
Write to the filesystem that the process has started
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/files/honeybee_adapter.rb', line 44 def communicate_started File.open("#{@options[:output_directory]}/started.job", 'w') do |f| f << "Started Workflow #{::Time.now}" # make sure data is written to the disk one way or the other begin f.fsync rescue f.flush end end end |
#communicate_transition(_ = nil, _ = nil, _ = nil) ⇒ Object
Do nothing on a state transition
86 87 |
# File 'lib/files/honeybee_adapter.rb', line 86 def communicate_transition(_ = nil, _ = nil, _ = nil) end |