Class: OpenStudio::Workflow::Adapters::Local

Inherits:
OpenStudio::Workflow::Adapter show all
Defined in:
lib/openstudio/workflow/adapters/local.rb

Instance Attribute Summary

Attributes inherited from OpenStudio::Workflow::Adapter

#options

Instance Method Summary collapse

Methods inherited from OpenStudio::Workflow::Adapter

#add_directory_to_zip, #load

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(options = {})
  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, _options = {})
  # 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, options = {})
  defaults = { datapoint_filename: 'datapoint.json', format: 'json' }
  options = defaults.merge(options)

  # how do we log within this file?
  if File.exist? "#{directory}/#{options[:datapoint_filename]}"
    ::MultiJson.load(File.read("#{directory}/#{options[:datapoint_filename]}"), symbolize_names: true)
  else
    fail "Data point file does not exist for #{directory}/#{options[: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, _options = {})
  @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, options = {})
  defaults = { problem_filename: 'problem.json', format: 'json' }
  options = defaults.merge(options)

  if File.exist? "#{directory}/#{options[:problem_filename]}"
    ::MultiJson.load(File.read("#{directory}/#{options[:problem_filename]}"), symbolize_names: true)
  else
    fail "Problem file does not exist for #{directory}/#{options[:problem_filename]}"
  end
end