spec/openstudio/excel_spec.rb in openstudio-analysis-0.4.2 vs spec/openstudio/excel_spec.rb in openstudio-analysis-0.4.3
- old
+ new
@@ -15,11 +15,10 @@
before(:each) do
@excel = OpenStudio::Analysis::Translator::Excel.new(path)
end
it 'should have excel data' do
- puts @excel
expect(@excel).not_to be_nil
end
it 'should process the excel file' do
expect(@excel.process).to eq(true)
@@ -80,11 +79,10 @@
expect(@excel.models.first[:name]).to eq('small_seed')
end
it 'should have a weather file' do
expect(@excel.weather_files.first).not_to be_nil
- puts @excel.weather_files.first
expect(@excel.weather_files.first.include?('partial_weather')).to eq(true)
end
it 'should have notes and source' do
@excel.variables['data'].each do |measure|
@@ -98,14 +96,14 @@
end
end
it 'should write a json' do
@excel.save_analysis
- expect(File).to exist('spec/files/export/analysis/small_seed.json')
- expect(File).to exist('spec/files/export/analysis/small_seed.zip')
+ expect(File).to exist('spec/files/export/analysis/example_analysis.json')
+ expect(File).to exist('spec/files/export/analysis/example_analysis.zip')
- expect(JSON.parse(File.read('spec/files/export/analysis/small_seed.json'))).not_to be_nil
+ expect(JSON.parse(File.read('spec/files/export/analysis/example_analysis.json'))).not_to be_nil
end
end
context 'setup version 0.1.9' do
before(:all) do
@@ -120,25 +118,27 @@
it 'should have the new settings' do
expect(@excel.settings['server_instance_type']).to eq('m2.xlarge')
end
it 'should have algorithm setup' do
- expect(@excel.algorithm['number_of_samples']).to eq(100)
- expect(@excel.algorithm['number_of_generations']).to eq(20)
- expect(@excel.algorithm['sample_method']).to eq('all_variables')
- expect(@excel.algorithm['number_of_generations']).to be_a Integer
- expect(@excel.algorithm['tolerance']).to eq(0.115)
- expect(@excel.algorithm['tolerance']).to be_a Float
+ h = @excel.analysis
+
+ expect(h.algorithm['number_of_samples']).to eq(100)
+ expect(h.algorithm['number_of_generations']).to eq(20)
+ expect(h.algorithm['sample_method']).to eq('all_variables')
+ expect(h.algorithm['number_of_generations']).to be_a Integer
+ expect(h.algorithm['tolerance']).to eq(0.115)
+ expect(h.algorithm['tolerance']).to be_a Float
end
it 'should create a valid hash' do
- h = @excel.create_analysis_hash
+ h = @excel.analysis
- expect(h['analysis']['problem']['analysis_type']).to eq('lhs')
- expect(h['analysis']['problem']['algorithm']).not_to be_nil
- expect(h['analysis']['problem']['algorithm']['number_of_samples']).to eq(100)
- expect(h['analysis']['problem']['algorithm']['sample_method']).to eq('all_variables')
+ expect(h.analysis_type).to eq('lhs')
+ expect(h.algorithm).to be_a OpenStudio::Analysis::AlgorithmAttributes
+ expect(h.algorithm['number_of_samples']).to eq(100)
+ expect(h.algorithm['sample_method']).to eq('all_variables')
end
end
context 'proxy setup' do
before(:all) do
@@ -175,23 +175,22 @@
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(var['distribution']['discrete_values']).to match_array [true, false]
expect(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
+ expect(File.exist?('spec/files/export/analysis/example_analysis.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/example_analysis.zip')).to eq true
end
end
context 'discrete with dynamic columns' do
before(:all) do
@@ -207,12 +206,12 @@
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
+ expect(File.exist?('spec/files/export/analysis/test_model.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/test_model.zip')).to eq true
end
end
context 'setup output variables' do
before(:all) do
@@ -225,11 +224,10 @@
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
expect(@excel.weather_files.first.include?('partial_weather')).to eq(true)
end
it 'should have notes and source' do
@excel.variables['data'].each do |measure|
@@ -256,16 +254,16 @@
# expect(@excel.algorithm["tolerance"]).to eq(0.115)
# expect(@excel.algorithm["tolerance"]).to be_a Float
end
it 'should create a valid hash' do
- h = @excel.create_analysis_hash
+ h = @excel.analysis
- expect(h['analysis']['problem']['analysis_type']).to eq('nsga')
- expect(h['analysis']['problem']['algorithm']).not_to be_nil
- expect(h['analysis']['problem']['algorithm']['number_of_samples']).to eq(100)
- expect(h['analysis']['problem']['algorithm']['sample_method']).to eq('all_variables')
+ expect(h.analysis_type).to eq('nsga')
+ expect(h.algorithm).to be_a OpenStudio::Analysis::AlgorithmAttributes
+ expect(h.algorithm['number_of_samples']).to eq(100)
+ expect(h.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/0_1_09_outputvars.json')
@@ -282,15 +280,13 @@
it 'should process' do
expect(@excel.process).to eq(true)
end
it 'should have new setting variables' do
- puts @excel.settings.inspect
expect(@excel.settings['user_id']).to eq('new_user')
expect(@excel.settings['openstudio_server_version']).to eq('1.3.2')
expect(@excel.cluster_name).to eq('analysis_cluster')
- puts @excel.run_setup.inspect
expect(@excel.run_setup['analysis_name']).to eq('LHS Example Project')
end
end
context 'version 0.2.0' do
@@ -301,15 +297,13 @@
it 'should process' do
expect(@excel.process).to eq(true)
end
it 'should have new setting variables' do
- puts @excel.settings.inspect
expect(@excel.settings['user_id']).to eq('new_user')
expect(@excel.settings['openstudio_server_version']).to eq('1.3.2')
expect(@excel.cluster_name).to eq('analysis_cluster_name')
- puts @excel.run_setup.inspect
expect(@excel.run_setup['analysis_name']).to eq('Name goes here')
end
it 'should have the new measure directory column' do
expect(@excel.variables['data'][1]['measure_file_name_directory']).to eq('ReduceLightingLoadsByPercentage')
@@ -328,48 +322,42 @@
it 'should process' do
expect(@excel.process).to eq(true)
end
it 'should have new setting variables' do
- puts @excel.settings.inspect
expect(@excel.settings['user_id']).to eq('new_user')
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'][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
+ expect(File.exist?('spec/files/export/analysis/simple_test.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/simple_test.zip')).to eq true
end
end
context 'version 0.3.0 objective functions' do
before(:all) do
@excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_3_0_outputs.xlsx')
- end
-
- it 'should process' do
expect(@excel.process).to eq(true)
end
it 'should have new setting variables' do
- puts @excel.settings.inspect
expect(@excel.settings['user_id']).to eq('new_user')
expect(@excel.settings['openstudio_server_version']).to eq('1.6.1')
- puts @excel.run_setup.inspect
end
it 'should have typed outputs' do
- h = @excel.create_analysis_hash
- expect(h['analysis']['output_variables']).to be_an Array
- h['analysis']['output_variables'].each do |o|
+ h = @excel.analysis
+
+ expect(h.outputs).to be_an Array
+ h.outputs.each do |o|
if o['name'] == 'standard_report_legacy.total_energy'
expect(o['variable_type']).to eq 'double'
expect(o['objective_function']).to eq true
expect(o['objective_function_index']).to eq 0
expect(o['objective_function_target']).to eq nil
@@ -417,52 +405,53 @@
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')
+ expect(@excel.process).to eq(true)
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
+ expect(File.exist?('spec/files/export/analysis/0_3_0_dynamic_uuids.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/0_3_0_dynamic_uuids.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')
+ expect(@excel.process).to eq(true)
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 = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_3_3_short_names.xlsx')
+ expect(@excel.process).to eq(true)
@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
+ expect(File.exist?('spec/files/export/analysis/0_3_3_short_names.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/0_3_3_short_names.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"))
+ j = JSON.parse(File.read('spec/files/export/analysis/0_3_3_short_names.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'
@@ -471,22 +460,19 @@
end
context 'version 0.3.5 and measure paths' do
before :all do
@excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_3_5_multiple_measure_paths.xlsx')
- end
-
- it 'should process' do
expect(@excel.process).to eq(true)
end
it 'should save the analysis' 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
+ expect(File.exist?('spec/files/export/analysis/0_3_5_multiple_measure_paths.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/0_3_5_multiple_measure_paths.zip')).to eq true
expect(@excel.settings['openstudio_server_version']).to eq('1.8.0')
expect(@excel.settings['spreadsheet_version']).to eq '0.3.5'
expect(@excel.settings['server_instance_type']).to eq 'm3.xlarge'
expect(@excel.settings['worker_instance_type']).to eq 'c3.2xlarge'
@@ -496,39 +482,36 @@
end
context 'version 0.3.7 and worker init-final scripts' do
before :all do
@excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_3_7_worker_init_final.xlsx')
- end
-
- it 'should process' do
expect(@excel.process).to eq(true)
end
it 'should save the analysis' 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
+ expect(File.exist?('spec/files/export/analysis/0_3_7_worker_init_final.json')).to eq true
+ expect(File.exist?('spec/files/export/analysis/0_3_7_worker_init_final.zip')).to eq true
expect(@excel.worker_inits.size).to eq 2
expect(@excel.worker_inits[0][:name]).to eq 'initialize me'
expect(@excel.worker_inits[0][:args]).to eq "[\"first_arg\",2,{a_hash: \"input\"}]"
- # test the evaling of the args
- a = eval(@excel.worker_inits[0][:args])
+ # test the eval'ing of the args
+ a = eval(@excel.analysis.worker_inits.first[:metadata][:args])
expect(a[0]).to eq 'first_arg'
expect(a[1]).to eq 2
expect(a[2]).to be_a Hash
expect(a[2][:a_hash]).to eq 'input'
- expect(@excel.worker_inits[0][:ordered_file_name]).to eq '00_first_file.rb'
- expect(@excel.worker_inits[1][:ordered_file_name]).to eq '01_second_file.rb'
+ expect(File.basename(@excel.analysis.worker_inits.first[:file])).to eq 'first_file.rb'
+ expect(File.basename(@excel.analysis.worker_inits.last[:file])).to eq 'second_file.rb'
- expect(@excel.worker_finals.size).to eq 1
- expect(@excel.worker_inits[0][:ordered_file_name]).to eq '00_first_file.rb'
+ expect(@excel.analysis.worker_finalizes.size).to eq 1
+ expect(File.basename(@excel.analysis.worker_finalizes.first[:file])).to eq 'first_file.rb'
end
end
context 'version 0.3.7 and worker init-final scripts' do
before :all do
@@ -541,8 +524,59 @@
@excel.save_analysis
end
end
- context 'version 0.4.0 full spreadsheet example' do
+ context 'version 0.4.0 multiple seed models' do
+ before :all do
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_4_0_multiple_seeds.xlsx')
+ expect(@excel.process).to eq(true)
+ end
+
+ it 'should save the analysis' do
+ expect { @excel.analysis }.to raise_error /There are more than one seed models defined in the excel file. Call .analyses. to return the array/
+ model_uuid = "#{@excel.name.snake_case}_#{@excel.models.first[:name]}"
+
+ @excel.save_analysis # this will save all the analyses
+
+ @excel.models.each do |f|
+ model_uuid = "#{@excel.name.snake_case}_#{f[:name]}"
+ puts model_uuid
+ 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
+
+ expect(@excel.settings['openstudio_server_version']).to eq('1.11.0-rc2')
+ expect(@excel.settings['spreadsheet_version']).to eq '0.3.7'
+ expect(@excel.settings['server_instance_type']).to eq 'm3.xlarge'
+ expect(@excel.settings['worker_instance_type']).to eq 'c3.4xlarge'
+ expect(@excel.aws_tags).to eq(['org=5500'])
+ end
+ end
+
+ context 'version 0.4.0 pivot test' do
+ before :all do
+ @excel = OpenStudio::Analysis::Translator::Excel.new('spec/files/0_4_0_pivot_test.xlsx')
+ expect(@excel.process).to eq(true)
+ end
+
+ it 'should save the analysis' do
+ a = @excel.analysis
+
+ @excel.save_analysis # this will save all the analyses
+
+ j = JSON.parse(File.read('spec/files/export/analysis/pivot_test.json'))
+
+ expect(j['analysis']['problem']['workflow'][0]['name']).to eq 'reduce_lighting_loads_by_percentage'
+ expect(j['analysis']['problem']['workflow'][0]['variables'][0]['variable_type']).to eq 'pivot'
+ expect(j['analysis']['problem']['workflow'][0]['variables'][0]['pivot']).to eq true
+ expect(j['analysis']['problem']['workflow'][1]['variables'][0]['variable']).to eq true
+ expect(j['analysis']['problem']['workflow'][1]['variables'][0]['pivot']).to eq nil
+
+ expect(@excel.settings['openstudio_server_version']).to eq('1.11.0-rc2')
+ expect(@excel.settings['spreadsheet_version']).to eq '0.3.7'
+ expect(@excel.settings['server_instance_type']).to eq 'm3.xlarge'
+ expect(@excel.settings['worker_instance_type']).to eq 'c3.4xlarge'
+ expect(@excel.aws_tags).to eq(['org=5500'])
+ end
end
end