spec/openstudio/analysis/translator/excel_spec.rb in openstudio-analysis-0.3.2 vs spec/openstudio/analysis/translator/excel_spec.rb in openstudio-analysis-0.3.3
- old
+ new
@@ -1,10 +1,18 @@
require 'spec_helper'
describe OpenStudio::Analysis::Translator::Excel do
+ before :all do
+ clean_dir = File.expand_path 'spec/files/export/analysis'
+
+ if Dir.exist? clean_dir
+ FileUtils.rm_rf clean_dir
+ end
+ end
+
context 'no variables defined' do
- let(:path) { 'spec/files/no_variables.xlsx' }
+ let(:path) { 'spec/files/0_1_09_no_variables.xlsx' }
before(:each) do
@excel = OpenStudio::Analysis::Translator::Excel.new(path)
end
@@ -36,42 +44,42 @@
end
end
context 'small list of incomplete variables' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/small_list_incomplete.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_09_small_list_incomplete.xlsx')
end
it 'should fail to process' do
expect { @excel.process }.to raise_error('Variable adjust_thermostat_setpoints_by_degrees:cooling_adjustment must have a mean')
end
end
context 'small list with with repeated variable names' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/small_list_repeat_vars.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_09_small_list_repeat_vars.xlsx')
end
it 'should fail to process' do
expect { @excel.process }.to raise_error("duplicate variable names found in list [\"Insulation R-value (ft^2*h*R/Btu).\"]")
end
end
context 'small list of variables should not validate' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/small_list_validation_errors.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_09_small_list_validation_errors.xlsx')
end
it 'should fail to process' do
error_message = 'Variable min is greater than variable max for adjust_thermostat_setpoints_by_degrees:heating_adjustment'
expect { @excel.process }.to raise_error(error_message)
end
end
context 'small list of variables' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/small_list.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_09_small_list.xlsx')
@excel.process
end
it 'should have a model' do
expect(@excel.models.first).not_to be_nil
expect(@excel.models.first[:name]).to eq('small_seed')
@@ -105,11 +113,11 @@
end
end
context 'setup version 0.1.9' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/setup_version_2.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_09_setup_version_2.xlsx')
@excel.process
end
it 'should have a version and machine name' do
expect(@excel.version).to eq('0.1.9')
@@ -139,25 +147,24 @@
end
end
context 'proxy setup' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/proxy.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_10_proxy.xlsx')
@excel.process
end
it 'should have a proxy setting' do
expect(@excel.settings['proxy_host']).to eq('192.168.0.1')
expect(@excel.settings['proxy_port']).to eq(8080)
expect(@excel.settings['proxy_username']).to be_nil
-
end
end
context 'proxy setup with user' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/proxy_user.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_10_proxy_user.xlsx')
@excel.process
end
it 'should have a user' do
expect(@excel.settings['proxy_host']).to eq('192.168.0.1')
@@ -166,55 +173,65 @@
end
end
context 'discrete variables' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/discrete_variables.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_11_discrete_variables.xlsx')
@excel.process
end
it 'should have parsed the spreadsheet' do
@excel.variables['data'].each do |measure|
measure['variables'].each do |var|
-
+ # TODO: Add some tests!
+ if var['name'] == 'alter_design_days'
+ puts var.inspect
+ expect(var['type']).to eq 'bool'
+ expect(eval(var['distribution']['discrete_values'])).to match_array ["true", "false"]
+ expect(eval(var['distribution']['discrete_weights'])).to match_array [0.8,0.2]
+ end
end
end
end
it 'should save the file' do
@excel.save_analysis
+ expect(File.exist?('spec/files/export/analysis/0_1_11_discrete_variables.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/0_1_11_discrete_variables.zip')).to eq true
end
end
context 'discrete with dynamic columns' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/discrete_dynamic_columns.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_12_discrete_dynamic_columns.xlsx')
@excel.process
end
it 'should have parsed the spreadsheet' do
@excel.variables['data'].each do |measure|
measure['variables'].each do |var|
- puts var.inspect
+ # TODO: test something?
end
end
end
it 'should save the file' do
@excel.save_analysis
+ expect(File.exist?('spec/files/export/analysis/0_1_12_discrete_dynamic_columns.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/0_1_12_discrete_dynamic_columns.zip')).to eq true
end
end
context 'setup output variables' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/outputvars.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_09_outputvars.xlsx')
@excel.process
end
it 'should have a model' do
expect(@excel.models.first).not_to be_nil
- expect(@excel.models.first[:name]).to eq('output_vars')
+ expect(@excel.models.first[:name]).to eq('0_1_09_outputvars')
end
it 'should have a weather file' do
expect(@excel.weather_files.first).not_to be_nil
puts @excel.weather_files.first
@@ -257,21 +274,19 @@
expect(h['analysis']['problem']['algorithm']['sample_method']).to eq('all_variables')
end
it 'should write a json' do
@excel.save_analysis
- expect(File).to exist('spec/files/export/analysis/output_vars.json')
- expect(File).to exist('spec/files/export/analysis/output_vars.zip')
-
- expect(JSON.parse(File.read('spec/files/export/analysis/output_vars.json'))).not_to be_nil
-
+ expect(File).to exist('spec/files/export/analysis/0_1_09_outputvars.json')
+ expect(File).to exist('spec/files/export/analysis/0_1_09_outputvars.zip')
+ expect(JSON.parse(File.read('spec/files/export/analysis/0_1_09_outputvars.json'))).not_to be_nil
end
end
context 'version 0.1.10' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/template_input_0.1.10.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_1_10_template_input.xlsx')
end
it 'should process' do
expect(@excel.process).to eq(true)
end
@@ -286,11 +301,11 @@
end
end
context 'version 0.2.0' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/template_0_2_0.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_2_0_template.xlsx')
end
it 'should process' do
expect(@excel.process).to eq(true)
end
@@ -313,11 +328,11 @@
end
end
context 'version 0.2.0 simple' do
before(:all) do
- @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/template_0_2_0_simpletest.xlsx')
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_2_0_template_simpletest.xlsx')
end
it 'should process' do
expect(@excel.process).to eq(true)
end
@@ -328,17 +343,18 @@
expect(@excel.settings['openstudio_server_version']).to eq('1.3.2')
puts @excel.run_setup.inspect
end
it 'should have the new measure directory column' do
- expect(@excel.variables['data'][1]['measure_file_name_directory']).to eq('AdjustThermostatSetpointsByDegrees')
- expect(@excel.variables['data'][0]['measure_file_name_directory']).to eq('baseline')
+ expect(@excel.variables['data'][0]['measure_file_name_directory']).to eq('ExampleMeasure')
+ expect(@excel.variables['data'][0]['display_name']).to eq('Baseline')
end
it 'should write a json' do
@excel.save_analysis
-
+ expect(File.exist?('spec/files/export/analysis/0_2_0_template_simpletest.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/0_2_0_template_simpletest.zip')).to eq true
end
end
context 'version 0.3.0 objective functions' do
before(:all) do
@@ -387,9 +403,78 @@
# check the JSON
h = JSON.parse(File.read('spec/files/export/analysis/0_3_0_outputs.json'))
expect(h['analysis']['weather_file']).to be_a Hash
expect(h['analysis']['weather_file']['path']).to eq './weather/partial_weather.epw'
end
+ end
+ context 'version 0.3.0 measure existence checks' do
+ before(:all) do
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_3_0_measure_existence.xlsx')
+ end
+
+ it 'should process' do
+ expect(@excel.process).to eq(true)
+
+ model_name = @excel.models.first[:name]
+ expect(model_name).to eq '0_3_0_outputs'
+ end
+
+ it 'should error out with missing measure information' do
+ expect{@excel.save_analysis}.to raise_error /Measure in directory.*not contain a measure.rb.*$/
+ end
end
+ context 'version 0.3.0 dynamic uuid assignments' do
+ before(:all) do
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_3_0_dynamic_uuids.xlsx')
+ end
+
+ it 'should process' do
+ expect(@excel.process).to eq(true)
+
+ model_uuid = @excel.models.first[:name]
+ expect(model_uuid).to match /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
+ end
+
+ it 'should error out with missing measure information' do
+ @excel.save_analysis
+ model_uuid = @excel.models.first[:name]
+ expect(File.exist?("spec/files/export/analysis/#{model_uuid}.json")).to eq true
+ expect(File.exist?("spec/files/export/analysis/#{model_uuid}.zip")).to eq true
+ end
+ end
+
+ context 'version 0.3.3 and short display names' do
+ before :all do
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_3_3_short_names.xlsx')
+ end
+
+ it 'should process' do
+ expect(@excel.process).to eq(true)
+
+ model_uuid = @excel.models.first[:name]
+ expect(model_uuid).to match /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
+ end
+
+ it 'should process and save short display names' do
+ @excel.save_analysis
+ model_uuid = @excel.models.first[:name]
+ expect(File.exist?("spec/files/export/analysis/#{model_uuid}.json")).to eq true
+ expect(File.exist?("spec/files/export/analysis/#{model_uuid}.zip")).to eq true
+
+ @excel.outputs['output_variables'].each do |o|
+ expect(o['display_name_short']).to eq "Site EUI" if o['name'] == 'standard_report_legacy.total_energy'
+ expect(o['display_name_short']).to eq "Natural Gas Heating Intensity" if o['name'] == 'standard_report_legacy.heating_natural_gas'
+ end
+
+ # Check the JSON
+ j = JSON.parse(File.read("spec/files/export/analysis/#{model_uuid}.json"))
+ expect(j['analysis']['output_variables'].first['display_name']).to eq "Total Site Energy Intensity"
+ expect(j['analysis']['output_variables'].first['display_name_short']).to eq "Site EUI"
+ expect(j['analysis']['problem']['workflow'][0]['variables'][0]['argument']['display_name']).to eq "Orientation"
+ expect(j['analysis']['problem']['workflow'][0]['variables'][0]['argument']['display_name_short']).to eq "Shorter Display Name"
+ expect(j['analysis']['problem']['workflow'][1]['arguments'][0]['display_name']).to eq "unknown"
+ expect(j['analysis']['problem']['workflow'][1]['arguments'][0]['display_name_short']).to eq "un"
+ end
+ end
end