Class: OpenStudio::Workflow::OutputAdapter::Local

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

Direct Known Subclasses

Socket, Web

Instance Attribute Summary

Attributes inherited from OpenStudio::Workflow::OutputAdapters

#options

Instance Method Summary collapse

Methods inherited from OpenStudio::Workflow::OutputAdapters

#add_directory_to_zip

Constructor Details

#initialize(options = {}) ⇒ Local

Returns a new instance of Local.



15
16
17
18
19
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 15

def initialize(options = {})
  raise 'The required :output_directory option was not passed to the local output adapter' unless options[:output_directory]

  super
end

Instance Method Details

#communicate_completeObject

Write to the filesystem that the process has completed



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 37

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 StandardError
      f.flush
    end
  end
end

#communicate_energyplus_stdout(_ = nil, _ = nil) ⇒ Object

Do nothing on EnergyPlus stdout



69
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 69

def communicate_energyplus_stdout(_ = nil, _ = nil); end

#communicate_failureObject

Write to the filesystem that the process has failed



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 51

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 StandardError
      f.flush
    end
  end
end

#communicate_measure_attributes(measure_attributes, _ = nil) ⇒ Object

Write the measure attributes to the filesystem



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 77

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 StandardError
      f.flush
    end
  end
end

#communicate_measure_result(_ = nil, _ = nil) ⇒ Object

Do nothing on Measure result



73
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 73

def communicate_measure_result(_ = nil, _ = nil); end

#communicate_objective_function(objectives, _ = nil) ⇒ Object

Write the objective function results to the filesystem



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 93

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 StandardError
      f.flush
    end
  end
end

#communicate_results(directory, results, skip_zip_results) ⇒ Object

Write the results of the workflow to the filesystem



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 109

def communicate_results(directory, results, skip_zip_results)
  if !skip_zip_results
    zip_results(directory)
  end

  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 StandardError
        f.flush
      end
    end
  else
    # puts "Unknown datapoint result type. Please handle #{results.class}"
  end
end

#communicate_startedObject

Write to the filesystem that the process has started



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 23

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 StandardError
      f.flush
    end
  end
end

#communicate_transition(_ = nil, _ = nil, _ = nil) ⇒ Object

Do nothing on a state transition



65
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 65

def communicate_transition(_ = nil, _ = nil, _ = nil); end