Class: OpenStudio::Workflow::OutputAdapter::Socket

Inherits:
Local show all
Defined in:
lib/openstudio/workflow/adapters/output/socket.rb

Instance Attribute Summary

Attributes inherited from OpenStudio::Workflow::OutputAdapters

#options

Instance Method Summary collapse

Methods inherited from Local

#communicate_measure_attributes

Methods inherited from OpenStudio::Workflow::OutputAdapters

#add_directory_to_zip, #communicate_measure_attributes

Constructor Details

#initialize(options = {}) ⇒ Socket

Returns a new instance of Socket.



44
45
46
47
48
49
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 44

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

  @socket = TCPSocket.open 'localhost', options[:port]
end

Instance Method Details

#communicate_completeObject



60
61
62
63
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 60

def communicate_complete
  super
  @socket.write("Complete\n")
end

#communicate_energyplus_stdout(line, options = {}) ⇒ Object



79
80
81
82
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 79

def communicate_energyplus_stdout(line, options = {})
  super
  @socket.write(line)
end

#communicate_failureObject



65
66
67
68
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 65

def communicate_failure
  super
  @socket.write("Failure\n")
end

#communicate_measure_result(result, options = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 84

def communicate_measure_result(result, options = {})
  super

  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 = '  '
  @socket.write("#{tab}Result: #{step_result.get.valueName}\n") if !step_result.empty?
  @socket.write("#{tab}Initial Condition: #{initial_condition.get}\n") if !initial_condition.empty?
  @socket.write("#{tab}Final Condition: #{final_condition.get}\n") if !final_condition.empty?
  errors.each { |error| @socket.write("#{tab}Error: #{error}\n") }
  warnings.each { |warning| @socket.write("#{tab}Warn: #{warning}\n") }
  infos.each { |info| @socket.write("#{tab}Info: #{info}\n") }
end

#communicate_objective_function(objectives, options = {}) ⇒ Object



70
71
72
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 70

def communicate_objective_function(objectives, options = {})
  super
end

#communicate_results(directory, results) ⇒ Object



56
57
58
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 56

def communicate_results(directory, results)
  super
end

#communicate_startedObject



51
52
53
54
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 51

def communicate_started
  super
  @socket.write("Started\n")
end

#communicate_transition(message, type, options = {}) ⇒ Object



74
75
76
77
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 74

def communicate_transition(message, type, options = {})
  super
  @socket.write(message + "\n")
end