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.



43
44
45
46
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 43

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



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 64

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(_ = nil, _ = nil) ⇒ Object

Do nothing on EnergyPlus stdout



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

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

#communicate_failureObject

Write to the filesystem that the process has failed



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

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



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 107

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(_ = nil, _ = nil) ⇒ Object

Do nothing on Measure result



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

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

#communicate_objective_function(objectives, _ = nil) ⇒ Object

Write the objective function results to the filesystem



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 123

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



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/openstudio/workflow/adapters/output/local.rb', line 139

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_startedObject

Write to the filesystem that the process has started



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

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



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

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