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.



16
17
18
19
20
21
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 16

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



28
29
30
31
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 28

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

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



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

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

#communicate_failureObject



33
34
35
36
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 33

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

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 52

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



38
39
40
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 38

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

#communicate_startedObject



23
24
25
26
# File 'lib/openstudio/workflow/adapters/output/socket.rb', line 23

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

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



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

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