Class: RunXml

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio/workflow/jobs/run_xml/run_xml.rb

Overview

This actually belongs as another class that gets added as a state dynamically

Instance Method Summary collapse

Constructor Details

#initialize(directory, logger, time_logger, adapter, options = {}) ⇒ RunXml

RunXml



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/openstudio/workflow/jobs/run_xml/run_xml.rb', line 25

def initialize(directory, logger, time_logger, adapter, options = {})
  defaults = { use_monthly_reports: false, analysis_root_path: '.', xml_library_file: 'xml_runner.rb' }
  @options = defaults.merge(options)
  @directory = directory
  # TODO: there is a base number of arguments that each job will need including @run_directory. abstract it out.
  @run_directory = "#{@directory}/run"
  @adapter = adapter
  @results = {}
  @logger = logger
  @time_logger = time_logger
  @logger.info "#{self.class} passed the following options #{@options}"

  # initialize instance variables that are needed in the perform section
  @weather_filename = nil
  @weather_directory = File.expand_path(File.join(@options[:analysis_root_path], 'weather'))
  @logger.info "Weather directory is: #{@weather_directory}"
  @model_xml = nil
  @model = nil
  @model_idf = nil
  @analysis_json = nil
  # TODO: rename datapoint_json to just datapoint
  @datapoint_json = nil
  @output_attributes = {}
  @report_measures = []
  @measure_type_lookup = {
    openstudio_measure: 'RubyMeasure',
    energyplus_measure: 'EnergyPlusMeasure',
    reporting_measure: 'ReportingMeasure'
  }
end

Instance Method Details

#performObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/openstudio/workflow/jobs/run_xml/run_xml.rb', line 56

def perform
  @logger.info "Calling #{__method__} in the #{self.class} class"
  @logger.info "Current directory is #{@directory}"

  @logger.info 'Retrieving datapoint and problem'
  @datapoint_json = @adapter.get_datapoint(@directory, @options)
  @analysis_json = @adapter.get_problem(@directory, @options)

  if @analysis_json && @analysis_json[:analysis]
    @model_xml = load_xml_model
    @weather_filename = load_weather_file

    begin
      apply_xml_measures
    rescue => e
      log_message = "Exception during 'apply_xml_measure' with #{e.message}, #{e.backtrace.join("\n")}"
      raise log_message
    end

    # @logger.debug "XML measure output attributes JSON is #{@output_attributes}"
    File.open("#{@run_directory}/measure_attributes_xml.json", 'w') do |f|
      f << JSON.pretty_generate(@output_attributes)
    end
  end

  create_osm_from_xml

  @results
end