Class: OpenStudio::Workflow::Adapters::Local
- Inherits:
-
OpenStudio::Workflow::Adapter
- Object
- OpenStudio::Workflow::Adapter
- OpenStudio::Workflow::Adapters::Local
- Defined in:
- lib/openstudio/workflow/adapters/local.rb
Instance Attribute Summary
Attributes inherited from OpenStudio::Workflow::Adapter
Instance Method Summary collapse
- #communicate_complete(directory) ⇒ Object
-
#communicate_failure(directory) ⇒ Object
Final state of the simulation.
- #communicate_intermediate_result(_directory) ⇒ Object
- #communicate_results(directory, results) ⇒ Object
-
#communicate_started(directory, _options = {}) ⇒ Object
Tell the system that the process has started.
-
#get_datapoint(directory, options = {}) ⇒ Object
Get the data point from the path.
-
#get_logger(directory, _options = {}) ⇒ Object
For the local adapter send back a handle to a file to append the data.
-
#get_problem(directory, options = {}) ⇒ Object
Get the Problem/Analysis definition from the local file TODO: rename this to get_analysis_definintion (or something like that).
-
#initialize(options = {}) ⇒ Local
constructor
A new instance of Local.
Methods inherited from OpenStudio::Workflow::Adapter
Constructor Details
#initialize(options = {}) ⇒ Local
Returns a new instance of Local.
27 28 29 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 27 def initialize( = {}) super end |
Instance Method Details
#communicate_complete(directory) ⇒ Object
67 68 69 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 67 def communicate_complete(directory) File.open("#{directory}/finished.job", 'w') { |f| f << "Finished Workflow #{::Time.now}" } end |
#communicate_failure(directory) ⇒ Object
Final state of the simulation. The os_directory is the run directory and may be needed to zip up the results of the simuation.
73 74 75 76 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 73 def communicate_failure(directory) File.open("#{directory}/failed.job", 'w') { |f| f << "Failed Workflow #{::Time.now}" } # @communicate_module.communicate_failure(@communicate_object, os_directory) end |
#communicate_intermediate_result(_directory) ⇒ Object
63 64 65 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 63 def communicate_intermediate_result(_directory) # noop end |
#communicate_results(directory, results) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 78 def communicate_results(directory, results) zip_results(directory) if results.is_a? Hash File.open("#{directory}/data_point_out.json", 'w') { |f| f << JSON.pretty_generate(results) } else pp "Unknown datapoint result type. Please handle #{results.class}" # data_point_json_path = OpenStudio::Path.new(run_dir) / OpenStudio::Path.new('data_point_out.json') # os_data_point.saveJSON(data_point_json_path, true) end # end end |
#communicate_started(directory, _options = {}) ⇒ Object
Tell the system that the process has started
32 33 34 35 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 32 def communicate_started(directory, = {}) # Watch out for namespace conflicts (::Time is okay but Time is OpenStudio::Time) File.open("#{directory}/started.job", 'w') { |f| f << "Started Workflow #{::Time.now}" } end |
#get_datapoint(directory, options = {}) ⇒ Object
Get the data point from the path
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 38 def get_datapoint(directory, = {}) defaults = { datapoint_filename: 'datapoint.json', format: 'json' } = defaults.merge() # how do we log within this file? if File.exist? "#{directory}/#{[:datapoint_filename]}" ::MultiJson.load(File.read("#{directory}/#{[:datapoint_filename]}"), symbolize_names: true) else fail "Data point file does not exist for #{directory}/#{[:datapoint_filename]}" end end |
#get_logger(directory, _options = {}) ⇒ Object
For the local adapter send back a handle to a file to append the data. For this adapter the log messages are likely to be the same as the run.log messages. ?: do we really want two local logs from the Local adapter? One is in the run dir and the other is in the root
94 95 96 97 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 94 def get_logger(directory, = {}) @log ||= File.open("#{directory}/local_adapter.log", 'w') @log end |
#get_problem(directory, options = {}) ⇒ Object
Get the Problem/Analysis definition from the local file TODO: rename this to get_analysis_definintion (or something like that)
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/openstudio/workflow/adapters/local.rb', line 52 def get_problem(directory, = {}) defaults = { problem_filename: 'problem.json', format: 'json' } = defaults.merge() if File.exist? "#{directory}/#{[:problem_filename]}" ::MultiJson.load(File.read("#{directory}/#{[:problem_filename]}"), symbolize_names: true) else fail "Problem file does not exist for #{directory}/#{[:problem_filename]}" end end |