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, #communicate_results

Methods inherited from OpenStudio::Workflow::OutputAdapters

#add_directory_to_zip, #communicate_measure_attributes, #communicate_results

Constructor Details

#initialize(options = {}) ⇒ Socket

Returns a new instance of Socket.



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

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



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

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

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



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

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

#communicate_failureObject



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

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

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



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

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



68
69
70
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 68

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

#communicate_startedObject



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

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

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



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

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