Class: GEBMetricsReportTest
- Inherits:
-
Minitest::Test
- Object
- Minitest::Test
- GEBMetricsReportTest
- Defined in:
- lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb
Instance Method Summary collapse
- #epw_path_default ⇒ Object
- #load_osm ⇒ Object
- #model_in_path_default ⇒ Object
- #model_out_path(test_name) ⇒ Object
- #report_path(test_name) ⇒ Object
- #run_dir(test_name) ⇒ Object
-
#setup_test(test_name, idf_output_requests, model_in_path = model_in_path_default, epw_path = epw_path_default) ⇒ Object
create test files if they do not exist when the test first runs.
-
#setup_test_2(test_name, epw_path) ⇒ Object
method for running the test simulation using OpenStudio 2.x API.
- #sql_path(test_name) ⇒ Object
- #test_geb_metrics_report ⇒ Object
- #workspace_path(test_name) ⇒ Object
Instance Method Details
#epw_path_default ⇒ Object
22 23 24 25 26 27 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 22 def epw_path_default # make sure we have a weather data location epw = File.("#{File.dirname(__FILE__)}/CZ06RV2.epw") assert(File.exist?(epw.to_s)) return epw.to_s end |
#load_osm ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 106 def load_osm # load the test model translator = OpenStudio::OSVersion::VersionTranslator.new model = translator.loadModel(model_in_path_default) assert(!model.empty?) model.get end |
#model_in_path_default ⇒ Object
15 16 17 18 19 20 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 15 def model_in_path_default # return "#{File.dirname(__FILE__)}/SmallOfficeDetailed_90.1-2010_5A.osm" # return "#{File.dirname(__FILE__)}/small_office_simple.osm" # return "#{File.dirname(__FILE__)}/small_office_simple_w_CO2.osm" return "#{File.dirname(__FILE__)}/small_office_simple_w_CO2_daylighting.osm" end |
#model_out_path(test_name) ⇒ Object
34 35 36 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 34 def model_out_path(test_name) return "#{run_dir(test_name)}/example_model.osm" end |
#report_path(test_name) ⇒ Object
46 47 48 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 46 def report_path(test_name) return "#{run_dir(test_name)}/report.html" end |
#run_dir(test_name) ⇒ Object
29 30 31 32 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 29 def run_dir(test_name) # always generate test output in specially named 'output' directory so result files are not made part of the measure return "#{File.dirname(__FILE__)}/output/#{test_name}" end |
#setup_test(test_name, idf_output_requests, model_in_path = model_in_path_default, epw_path = epw_path_default) ⇒ Object
create test files if they do not exist when the test first runs
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 102 103 104 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 67 def setup_test(test_name, idf_output_requests, model_in_path = model_in_path_default, epw_path = epw_path_default) if !File.exist?(run_dir(test_name)) FileUtils.mkdir_p(run_dir(test_name)) end assert(File.exist?(run_dir(test_name))) if File.exist?(report_path(test_name)) FileUtils.rm(report_path(test_name)) end assert(File.exist?(model_in_path)) if File.exist?(model_out_path(test_name)) FileUtils.rm(model_out_path(test_name)) end # convert output requests to OSM for testing, OS App and PAT will add these to the E+ Idf workspace = OpenStudio::Workspace.new('Draft'.to_StrictnessLevel, 'EnergyPlus'.to_IddFileType) workspace.addObjects(idf_output_requests) rt = OpenStudio::EnergyPlus::ReverseTranslator.new request_model = rt.translateWorkspace(workspace) translator = OpenStudio::OSVersion::VersionTranslator.new model = translator.loadModel(model_in_path) assert(!model.empty?) model = model.get model.addObjects(request_model.objects) model.save(model_out_path(test_name), true) if ENV['OPENSTUDIO_TEST_NO_CACHE_SQLFILE'] if File.exist?(sql_path(test_name)) FileUtils.rm_f(sql_path(test_name)) end end # Run the OSW (only need to run for the first time or when new variable is requested) # setup_test_2(test_name, epw_path) end |
#setup_test_2(test_name, epw_path) ⇒ Object
method for running the test simulation using OpenStudio 2.x API
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 51 def setup_test_2(test_name, epw_path) osw_path = File.join(run_dir(test_name), 'in.osw') osw_path = File.absolute_path(osw_path) workflow = OpenStudio::WorkflowJSON.new workflow.setSeedFile(File.absolute_path(model_out_path(test_name))) workflow.setWeatherFile(File.absolute_path(epw_path)) workflow.saveAs(osw_path) cli_path = OpenStudio.getOpenStudioCLI cmd = "\"#{cli_path}\" run -w \"#{osw_path}\"" puts cmd system(cmd) end |
#sql_path(test_name) ⇒ Object
38 39 40 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 38 def sql_path(test_name) return "#{run_dir(test_name)}/run/eplusout.sql" end |
#test_geb_metrics_report ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 114 def test_geb_metrics_report test_name = 'run_geb_measures' # create an instance of the measure measure = GEBMetricsReport.new # create runner with empty OSW osw = OpenStudio::WorkflowJSON.new runner = OpenStudio::Measure::OSRunner.new(osw) # get arguments model = load_osm arguments = measure.arguments argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) args_hash = {} args_hash['baseline_run_output_path'] = File.dirname(__FILE__ ) args_hash['event_date'] = '07-21' args_hash['shed_start'] = '13:00' args_hash['shed_end'] = '15:00' args_hash['take_start'] = '10:00' args_hash['take_end'] = '13:00' # populate argument with specified hash value if specified arguments.each do |arg| temp_arg_var = arg.clone if args_hash.key?(arg.name) assert(temp_arg_var.setValue(args_hash[arg.name])) end argument_map[arg.name] = temp_arg_var end # idf_output_requests = measure.energyPlusOutputRequests(runner, argument_map) idf_output_requests = [] # mimic the process of running this measure in OS App or PAT. Optionally set custom model_in_path and custom epw_path. epw_path = epw_path_default setup_test(test_name, idf_output_requests) assert(File.exist?(model_out_path(test_name))) assert(File.exist?(sql_path(test_name))) assert(File.exist?(epw_path)) puts '~~ ' * 50 puts model_out_path(test_name) puts sql_path(test_name) puts epw_path # set up runner, this will happen automatically when measure is run in PAT or OpenStudio runner.setLastOpenStudioModelPath(OpenStudio::Path.new(model_out_path(test_name))) runner.setLastEnergyPlusWorkspacePath(OpenStudio::Path.new(workspace_path(test_name))) runner.setLastEpwFilePath(epw_path) runner.setLastEnergyPlusSqlFilePath(OpenStudio::Path.new(sql_path(test_name))) # delete the output if it exists if File.exist?(report_path(test_name)) FileUtils.rm(report_path(test_name)) end assert(!File.exist?(report_path(test_name))) # temporarily change directory to the run directory and run the measure start_dir = Dir.pwd begin Dir.chdir(run_dir(test_name)) # run the measure measure.run(runner, argument_map) result = runner.result show_output(result) # puts '+ ' * 40 # puts result assert_equal('Success', result.value.valueName) puts '===> Warnings: ' result.warnings.each do |warning| puts warning.logMessage end assert(result.warnings.empty?) ensure Dir.chdir(start_dir) end # make sure the report file exists assert(File.exist?(report_path(test_name))) end |
#workspace_path(test_name) ⇒ Object
42 43 44 |
# File 'lib/measures/GEB Metrics Report/tests/geb_metrics_report_test.rb', line 42 def workspace_path(test_name) return "#{run_dir(test_name)}/run/in.idf" end |