From a5f48b821ceca0c301e904ac290f4a1c7114430e Mon Sep 17 00:00:00 2001 From: Nathan Moore Date: Fri, 24 Jan 2025 14:56:20 -0700 Subject: [PATCH] rubocop formatting --- lib/urbanopt/reopt/feature_report_adapter.rb | 9 +++--- .../reopt/reopt_ghp_post_processor.rb | 28 ++++++++----------- .../reopt/reopt_schema/REopt-GHP-input.json | 5 ++-- lib/urbanopt/reopt/scenario_report_adapter.rb | 16 ++++------- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/lib/urbanopt/reopt/feature_report_adapter.rb b/lib/urbanopt/reopt/feature_report_adapter.rb index babadfbd..b9ec8a21 100755 --- a/lib/urbanopt/reopt/feature_report_adapter.rb +++ b/lib/urbanopt/reopt/feature_report_adapter.rb @@ -41,9 +41,9 @@ def reopt_json_from_feature_report(feature_report, reopt_assumptions_hash = nil, else @@logger.info('Using default REopt assumptions') reopt_inputs = { - Settings:{}, + Settings: {}, Site: {}, - Financial:{}, + Financial: {}, ElectricTariff: { monthly_demand_rates: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], monthly_energy_rates: [0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13] @@ -158,7 +158,6 @@ def reopt_json_from_feature_report(feature_report, reopt_assumptions_hash = nil, # [*return:*] _URBANopt::Reporting::DefaultReports::FeatureReport_ - Returns an updated FeatureReport. ## def update_feature_report(feature_report, reopt_output, timeseries_csv_path = nil, resilience_stats = nil) - # Check if the \REopt response is valid if reopt_output['status'] != 'optimal' @@logger.error("ERROR cannot update Feature Report #{feature_report.name} #{feature_report.id} - REopt optimization was non-optimal") @@ -439,7 +438,7 @@ def modrow(x, i) # :nodoc: x[$storage_to_grid_col] = $storage_to_grid[i] || 0 if defined?(storage) x[$storage_soc_col] = $storage_soc[i] || 0 if defined?(storage) x[$generator_total_col] = $generator_total[i] || 0 if defined?(generator) - x[$generator_to_battery_col] = $generator_to_battery[i] || 0 if (defined?(generator) && defined?(storage)) + x[$generator_to_battery_col] = $generator_to_battery[i] || 0 if defined?(generator) && defined?(storage) x[$generator_to_load_col] = $generator_to_load[i] || 0 if defined?(generator) x[$generator_to_grid_col] = $generator_to_grid[i] || 0 if defined?(generator) x[$pv_total_col] = $pv_total[i] || 0 @@ -447,7 +446,7 @@ def modrow(x, i) # :nodoc: x[$pv_to_load_col] = $pv_to_load[i] || 0 x[$pv_to_grid_col] = $pv_to_grid[i] || 0 x[$wind_total_col] = $wind_total[i] || 0 if defined?(wind) - x[$wind_to_battery_col] = $wind_to_battery[i] || 0 if (defined?(wind) && defined?(storage)) + x[$wind_to_battery_col] = $wind_to_battery[i] || 0 if defined?(wind) && defined?(storage) x[$wind_to_load_col] = $wind_to_load[i] || 0 if defined?(wind) x[$wind_to_grid_col] = $wind_to_grid[i] || 0 if defined?(wind) return x diff --git a/lib/urbanopt/reopt/reopt_ghp_post_processor.rb b/lib/urbanopt/reopt/reopt_ghp_post_processor.rb index 7572e81a..08e16cbc 100644 --- a/lib/urbanopt/reopt/reopt_ghp_post_processor.rb +++ b/lib/urbanopt/reopt/reopt_ghp_post_processor.rb @@ -13,7 +13,6 @@ module URBANopt # :nodoc: module REopt # :nodoc: class REoptGHPPostProcessor - def initialize(run_dir, system_parameter, modelica_result, reopt_ghp_assumptions = nil, nrel_developer_key = nil, localhost) # initialize @@logger @@logger ||= URBANopt::REopt.reopt_logger @@ -42,11 +41,11 @@ def initialize(run_dir, system_parameter, modelica_result, reopt_ghp_assumptions File.open(system_parameter, 'r') do |file| @system_parameter_input_hash = JSON.parse(file.read, symbolize_names: true) end - #Determine loop order + # Determine loop order loop_order = File.join(File.dirname(system_parameter), '_loop_order.json') if File.exist?(loop_order) File.open(loop_order, 'r') do |file| - loop_order_input= JSON.parse(file.read, symbolize_names: true) + loop_order_input = JSON.parse(file.read, symbolize_names: true) # Check the type of the parsed data if loop_order_input.is_a?(Array) @loop_order_input_hash = loop_order_input @@ -61,7 +60,7 @@ def initialize(run_dir, system_parameter, modelica_result, reopt_ghp_assumptions puts "GHE IDs in group: #{item[:list_ghe_ids_in_group].inspect}" end else - puts "Unexpected JSON structure" + puts 'Unexpected JSON structure' end end end @@ -77,7 +76,6 @@ def initialize(run_dir, system_parameter, modelica_result, reopt_ghp_assumptions # # Create REopt input and output building report def run_reopt_lcca(system_parameter_hash: nil, reopt_ghp_assumptions_hash: nil, modelica_result: nil) - adapter = URBANopt::REopt::REoptGHPAdapter.new # if these arguments are specified, use them @@ -89,14 +87,13 @@ def run_reopt_lcca(system_parameter_hash: nil, reopt_ghp_assumptions_hash: nil, @reopt_ghp_assumptions_input_hash = reopt_ghp_assumptions_hash end - if !modelica_result.nil? @modelica_result_input = modelica_result end # Create folder for REopt input files only if they dont exist - reopt_ghp_dir = File.join(@run_dir, "reopt_ghp") - reopt_ghp_input = File.join(reopt_ghp_dir, "reopt_ghp_inputs") + reopt_ghp_dir = File.join(@run_dir, 'reopt_ghp') + reopt_ghp_input = File.join(reopt_ghp_dir, 'reopt_ghp_inputs') unless Dir.exist?(reopt_ghp_dir) FileUtils.mkdir_p(reopt_ghp_dir) end @@ -104,7 +101,7 @@ def run_reopt_lcca(system_parameter_hash: nil, reopt_ghp_assumptions_hash: nil, FileUtils.mkdir_p(reopt_ghp_input) end - reopt_ghp_output = File.join(reopt_ghp_dir, "reopt_ghp_outputs") + reopt_ghp_output = File.join(reopt_ghp_dir, 'reopt_ghp_outputs') unless Dir.exist?(reopt_ghp_output) FileUtils.mkdir_p(reopt_ghp_output) end @@ -142,14 +139,11 @@ def run_reopt_lcca(system_parameter_hash: nil, reopt_ghp_assumptions_hash: nil, # reopt_ghp_output_file reopt_output_file = File.join(reopt_ghp_output, "#{base_name}_output.json") - #call the REopt API + # call the REopt API api = URBANopt::REopt::REoptLiteGHPAPI.new(reopt_input_data, DEVELOPER_NREL_KEY, reopt_output_file, @localhost) - api.get_api_results() - + api.get_api_results end - end - - end #REoptGHPPostProcessor - end #REopt -end #URBANopt + end # REoptGHPPostProcessor + end # REopt +end # URBANopt diff --git a/lib/urbanopt/reopt/reopt_schema/REopt-GHP-input.json b/lib/urbanopt/reopt/reopt_schema/REopt-GHP-input.json index 73795571..741153bf 100644 --- a/lib/urbanopt/reopt/reopt_schema/REopt-GHP-input.json +++ b/lib/urbanopt/reopt/reopt_schema/REopt-GHP-input.json @@ -44,7 +44,7 @@ }, "building_sqft": { "type": "float", - "requierd": true, + "required": true, "description": "to calculate cost of hydronic loop", "note": "for the GHX iteration, set building_sqft to a number close to 0 but not exactly 0" }, @@ -69,7 +69,7 @@ "number_of_boreholes": { "type": "int", "required": true, - "note": "in the GHP iteration, set this value to 0" + "note": "in the GHP iteration, set this value to 0" }, "length_boreholes_ft": { "type": "float", @@ -146,4 +146,3 @@ } } } - \ No newline at end of file diff --git a/lib/urbanopt/reopt/scenario_report_adapter.rb b/lib/urbanopt/reopt/scenario_report_adapter.rb index bea02820..57b212b7 100755 --- a/lib/urbanopt/reopt/scenario_report_adapter.rb +++ b/lib/urbanopt/reopt/scenario_report_adapter.rb @@ -43,9 +43,9 @@ def reopt_json_from_scenario_report(scenario_report, reopt_assumptions_json = ni else @@logger.info('Using default REopt assumptions') reopt_inputs = { - Settings:{}, + Settings: {}, Site: {}, - Financial:{}, + Financial: {}, ElectricTariff: { monthly_demand_rates: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], monthly_energy_rates: [0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13] @@ -277,12 +277,8 @@ def update_scenario_report(scenario_report, reopt_output, timeseries_csv_path = wind = reopt_output['outputs']['Wind'] # find size_class size_class = nil - if reopt_output['inputs']['Wind']['size_class'] - size_class = reopt_output['inputs']['Wind']['size_class'] - else - size_class = 'commercial' # default - end - scenario_report.distributed_generation.add_tech 'wind', URBANopt::Reporting::DefaultReports::Wind.new({ size_kw: (wind['size_kw'] || 0), size_class: size_class, average_yearly_energy_produced_kwh: (wind['average_yearly_energy_produced_kwh'] || 0) }) + size_class = reopt_output['inputs']['Wind']['size_class'] || 'commercial' + scenario_report.distributed_generation.add_tech 'wind', URBANopt::Reporting::DefaultReports::Wind.new({ size_kw: (wind['size_kw'] || 0), size_class:, average_yearly_energy_produced_kwh: (wind['average_yearly_energy_produced_kwh'] || 0) }) end if reopt_output['outputs'].key?('Generator') @@ -491,7 +487,7 @@ def modrow(data, idx) # :nodoc: data[$storage_to_grid_col] = $storage_to_grid[idx] || 0 if defined?(storage) data[$storage_soc_col] = $storage_soc[idx] || 0 if defined?(storage) data[$generator_total_col] = $generator_total[idx] || 0 if defined?(generator) - data[$generator_to_battery_col] = $generator_to_battery[idx] || 0 if (defined?(generator) && defined?(storage)) + data[$generator_to_battery_col] = $generator_to_battery[idx] || 0 if defined?(generator) && defined?(storage) data[$generator_to_load_col] = $generator_to_load[idx] || 0 if defined?(generator) data[$generator_to_grid_col] = $generator_to_grid[idx] || 0 if defined?(generator) data[$pv_total_col] = $pv_total[idx] || 0 @@ -499,7 +495,7 @@ def modrow(data, idx) # :nodoc: data[$pv_to_load_col] = $pv_to_load[idx] || 0 data[$pv_to_grid_col] = $pv_to_grid[idx] || 0 data[$wind_total_col] = $wind_total[idx] || 0 if defined?(wind) - data[$wind_to_battery_col] = $wind_to_battery[idx] || 0 if (defined?(wind) && defined?(storage)) + data[$wind_to_battery_col] = $wind_to_battery[idx] || 0 if defined?(wind) && defined?(storage) data[$wind_to_load_col] = $wind_to_load[idx] || 0 if defined?(wind) data[$wind_to_grid_col] = $wind_to_grid[idx] || 0 if defined?(wind) return data