Class: OpenStudioMeasureTester::Dashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio_measure_tester/dashboard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_results_directory) ⇒ Dashboard

Returns a new instance of Dashboard.

Parameters:

  • test_results_directory (String)

    : The directory



14
15
16
17
18
19
20
21
22
# File 'lib/openstudio_measure_tester/dashboard.rb', line 14

def initialize(test_results_directory)
  @test_results_directory = test_results_directory

  erb_file = File.expand_path('templates/dashboard.html.erb', File.dirname(__FILE__))
  @template = File.read(erb_file)
  file = File.read("#{@test_results_directory}/combined_results.json")
  @data = file
  @hash = JSON.parse(@data)
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



11
12
13
# File 'lib/openstudio_measure_tester/dashboard.rb', line 11

def html
  @html
end

Instance Method Details

#renderObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/openstudio_measure_tester/dashboard.rb', line 24

def render
  rendered = ERB.new(@template, trim_mode: nil, eoutvar: '@html').result(binding)
  save_dir = "#{@test_results_directory}/dashboard"

  # Render the dashboard
  FileUtils.mkdir_p save_dir unless Dir.exist? save_dir
  File.open("#{save_dir}/index.html", 'w') { |file| file.write(rendered) }
  # copy over all the resource files to display the website correctly.
  resource_path = File.expand_path('../../dashboard', File.dirname(__FILE__))
  # KAF: for some reason, not overwriting the files.  delete them from destination first
  FileUtils.remove_dir("#{save_dir}/css") if Dir.exist? "#{save_dir}/css"
  FileUtils.remove_dir("#{save_dir}/js") if Dir.exist? "#{save_dir}/js"
  FileUtils.cp_r("#{resource_path}/css", "#{save_dir}/css", remove_destination: true)
  FileUtils.cp_r("#{resource_path}/js", "#{save_dir}/js", remove_destination: true)
end