Class: GemEnvironmentReport

Inherits:
OpenStudio::Ruleset::ModelUserScript
  • Object
show all
Defined in:
lib/measures/gem_env_report/measure.rb

Overview

start the measure

Instance Method Summary collapse

Instance Method Details

#arguments(model) ⇒ Object

define the arguments that the user will input



31
32
33
34
35
# File 'lib/measures/gem_env_report/measure.rb', line 31

def arguments(model)
  args = OpenStudio::Measure::OSArgumentVector.new

  return args
end

#descriptionObject

human readable description



21
22
23
# File 'lib/measures/gem_env_report/measure.rb', line 21

def description
  return 'For OpenStudio testing and development; this measure reports out information about the gem path and gems that are available and loaded.  Used for debugging different runtime environments.'
end

#modeler_descriptionObject

human readable description of modeling approach



26
27
28
# File 'lib/measures/gem_env_report/measure.rb', line 26

def modeler_description
  return 'For OpenStudio testing and development; this measure reports out information about the gem path and gems that are available and loaded.  Used for debugging different runtime environments.'
end

#nameObject

human readable name



16
17
18
# File 'lib/measures/gem_env_report/measure.rb', line 16

def name
  return 'gem environment report'
end

#run(model, runner, user_arguments) ⇒ Object

define what happens when the measure is run



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/measures/gem_env_report/measure.rb', line 38

def run(model, runner, user_arguments)
  super(model, runner, user_arguments)

  result = {}

  # Info from the measure's run environment
  result[:measure] = {}

  result[:measure][:openstudio_info] = openstudio_information

  result[:measure][:gem_env] = gem_env_information

  # Info from if measure calls the CLI
  cli_path = OpenStudio.getOpenStudioCLI

  result[:cli] = {}

  os_info_path = File.expand_path('resources/run_openstudio_info.rb', __dir__)
  os_info_cmd = "\"#{cli_path}\" \"#{os_info_path}\""
  result[:cli][:openstudio_info_cmd] = os_info_cmd
  begin
    os_info = `#{os_info_cmd}`
    begin
      os_info_parsed = JSON.parse(os_info)
    rescue StandardError => exception
      os_info_parsed = os_info.to_s
    end
  rescue StandardError => exception
    os_info_parsed = [exception.backtrace.to_s]
  end
  result[:cli][:openstudio_info] = os_info_parsed

  gem_env_info_path = File.expand_path('resources/run_gem_env_info.rb', __dir__)
  gem_env_info_cmd = "\"#{cli_path}\" \"#{gem_env_info_path}\""
  result[:cli][:gem_env_info_cmd] = gem_env_info_cmd
  begin
    gem_info = `#{gem_env_info_cmd}`
    begin
      gem_info_parsed = JSON.parse(gem_info)
    rescue StandardError => exception
      gem_info_parsed = gem_info.to_s
    end
  rescue StandardError => exception
    gem_info_parsed = [exception.backtrace.to_s]
  end
  result[:cli][:gem_env] = gem_info_parsed

  pretty_result = JSON.pretty_generate(result)

  pretty_result.each_line do |ln|
    runner.registerInfo(ln.to_s)
  end

  # Write out to file
  json_name = 'report_gem_env.json'
  json_path = File.expand_path("./#{json_name}")
  File.open(json_path, 'wb') do |f|
    f.puts pretty_result
  end
  json_path = File.absolute_path(json_path)
  runner.registerFinalCondition("Report saved to: #{json_path}")

  return true
end