diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index f817cd262..d6707004a 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -13,6 +13,7 @@ on: - 'update_eplus_compare/**/*' - 'weatherdata/**/*' - 'model/refbuildingtests/measures/**/*' + - 'convert_ruby_to_python.rb' jobs: rubocop: @@ -31,7 +32,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: - ruby-version: '2.7' + ruby-version: '3.2.2' - uses: actions/setup-python@v5 with: @@ -43,6 +44,6 @@ jobs: with: autocorrect: true commit-auto-correct: true - rubocop-version: 0.81.0 + rubocop-version: 1.50.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.rubocop.yml b/.rubocop.yml index ace670264..318bcf09e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ # Where a Cop is not listed, it uses the Rubocop defaults. AllCops: + TargetRubyVersion: 2.5 NewCops: enable Exclude: - 'doc/**/*' @@ -14,6 +15,7 @@ AllCops: - 'update_eplus_compare/**/*' - 'weatherdata/**/*' - 'model/refbuildingtests/measures/**/*' + - 'convert_ruby_to_python.rb' # inherit_from: # - http://s3.amazonaws.com/openstudio-resources/styles/rubocop.yml @@ -85,6 +87,9 @@ Metrics/BlockNesting: #CountComments: false #Severity: warning +Metrics/CollectionLiteralLength: + Enabled: false + Metrics/CyclomaticComplexity: Max: 60 Severity: warning @@ -96,7 +101,7 @@ Metrics/CyclomaticComplexity: # Severity: warning Metrics/MethodLength: - Max: 350 + Max: 600 CountComments: false Severity: warning @@ -124,6 +129,10 @@ Style/ClassAndModuleChildren: Style/ClassVars: Enabled: false +# Don't force an if to a case +Style/CaseLikeIf: + Enabled: false + # Allow this syntax -- do not autocorrect. # a = if true # 1 diff --git a/highlevel_tests.rb b/highlevel_tests.rb index ce3959a3f..d7597c35e 100644 --- a/highlevel_tests.rb +++ b/highlevel_tests.rb @@ -107,7 +107,7 @@ def test_rbs_have_matching_osm_tests 'afn_single_zone_ac.rb'] content = File.read('model_tests.rb') - sim_test_commented_out_re = /TODO[ :\w]+(\d+\.\d+\.\d+).*?#\s*result = sim_test\('([\w\.]+)'\)/m + sim_test_commented_out_re = /TODO[ :\w]+(\d+\.\d+\.\d+).*?#\s*result = sim_test\('([\w.]+)'\)/m # eg: [["3.1.0", "coil_cooling_dx.osm"], ["3.1.0", "swimmingpool_indoor.osm"]] matches = content.scan(sim_test_commented_out_re) files_with_todo = matches.map { |m| m[1] } @@ -165,7 +165,7 @@ def test_ensure_pending_osms_are_added end content = File.read('model_tests.rb') - sim_test_commented_out_re = /TODO[ :\w]+(\d+\.\d+\.\d+).*?#\s*result = sim_test\('([\w\.]+)'\)/m + sim_test_commented_out_re = /TODO[ :\w]+(\d+\.\d+\.\d+).*?#\s*result = sim_test\('([\w.]+)'\)/m # eg: [["3.1.0", "coil_cooling_dx.osm"], ["3.1.0", "swimmingpool_indoor.osm"]] matches = content.scan(sim_test_commented_out_re) matches.each do |v, t| diff --git a/model/simulationtests/afn_multiple_zones.rb b/model/simulationtests/afn_multiple_zones.rb index d6f42fb16..b6d136474 100644 --- a/model/simulationtests/afn_multiple_zones.rb +++ b/model/simulationtests/afn_multiple_zones.rb @@ -55,9 +55,7 @@ elsif surface.adjacentSurface.is_initialized adjacent_surfaces << surface end - end - space.surfaces.each do |surface| surface.subSurfaces.each do |sub_surface| sub_surfaces << sub_surface end diff --git a/model/simulationtests/afn_single_zone_ac.rb b/model/simulationtests/afn_single_zone_ac.rb index ab778c80a..e821dc63e 100644 --- a/model/simulationtests/afn_single_zone_ac.rb +++ b/model/simulationtests/afn_single_zone_ac.rb @@ -48,7 +48,7 @@ def addSystemType3(model) # this systems is a constant volume system with no VAV terminals, and needs different default settings # get the sizing:system object associated with the airloophvac - sizingSystem = airLoopHVAC.sizingSystem() + sizingSystem = airLoopHVAC.sizingSystem # set the default parameters correctly for a constant volume system with no VAV terminals sizingSystem.setTypeofLoadtoSizeOn('Sensible') @@ -84,7 +84,7 @@ def addSystemType3(model) outdoorAirSystem = OpenStudio::Model::AirLoopHVACOutdoorAirSystem.new(model, controllerOutdoorAir) - supplyOutletNode = airLoopHVAC.supplyOutletNode() + supplyOutletNode = airLoopHVAC.supplyOutletNode outdoorAirSystem.addToNode(supplyOutletNode) coilCooling.addToNode(supplyOutletNode) @@ -120,7 +120,7 @@ def addSimpleSystem(model) # this systems is a constant volume system with no VAV terminals, and needs different default settings # get the sizing:system object associated with the airloophvac - sizingSystem = airLoopHVAC.sizingSystem() + sizingSystem = airLoopHVAC.sizingSystem # set the default parameters correctly for a constant volume system with no VAV terminals sizingSystem.setTypeofLoadtoSizeOn('Sensible') @@ -156,7 +156,7 @@ def addSimpleSystem(model) # outdoorAirSystem = OpenStudio::Model::AirLoopHVACOutdoorAirSystem.new(model,controllerOutdoorAir) - supplyOutletNode = airLoopHVAC.supplyOutletNode() + supplyOutletNode = airLoopHVAC.supplyOutletNode # outdoorAirSystem.addToNode(supplyOutletNode) fan.addToNode(supplyOutletNode) @@ -191,7 +191,7 @@ def addSimpleSystemAFN(model) # this systems is a constant volume system with no VAV terminals, and needs different default settings # get the sizing:system object associated with the airloophvac - sizingSystem = airLoopHVAC.sizingSystem() + sizingSystem = airLoopHVAC.sizingSystem # set the default parameters correctly for a constant volume system with no VAV terminals sizingSystem.setTypeofLoadtoSizeOn('Sensible') @@ -231,7 +231,7 @@ def addSimpleSystemAFN(model) # outdoorAirSystem = OpenStudio::Model::AirLoopHVACOutdoorAirSystem.new(model,controllerOutdoorAir) - supplyOutletNode = airLoopHVAC.supplyOutletNode() + supplyOutletNode = airLoopHVAC.supplyOutletNode # outdoorAirSystem.addToNode(supplyOutletNode) fan.addToNode(supplyOutletNode) diff --git a/model/simulationtests/autosize_hvac.rb b/model/simulationtests/autosize_hvac.rb index f91166e3a..3d570901d 100644 --- a/model/simulationtests/autosize_hvac.rb +++ b/model/simulationtests/autosize_hvac.rb @@ -146,7 +146,7 @@ def make_tes_coil(model) props = field.properties olist = props.objectLists.first - setter = 'set' + field_name.gsub(' ', '') + setter = "set#{field_name.gsub(' ', '')}" raise "Undefined method #{setter} for field_name=#{field_name} at index #{i}" unless tes_coil.respond_to?(setter) tes_coil.send(setter, object_list_to_curve[olist]) diff --git a/model/simulationtests/chiller_reformulated.rb b/model/simulationtests/chiller_reformulated.rb index 54b696465..f6a77e57b 100644 --- a/model/simulationtests/chiller_reformulated.rb +++ b/model/simulationtests/chiller_reformulated.rb @@ -25,7 +25,7 @@ # Chilled Water Plant chilledWaterPlant = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = chilledWaterPlant.sizingPlant() +sizingPlant = chilledWaterPlant.sizingPlant sizingPlant.setLoopType('Cooling') sizingPlant.setDesignLoopExitTemperature(7.22) sizingPlant.setLoopDesignTemperatureDifference(6.67) @@ -61,7 +61,7 @@ # Condenser System condenserSystem = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = condenserSystem.sizingPlant() +sizingPlant = condenserSystem.sizingPlant sizingPlant.setLoopType('Condenser') sizingPlant.setDesignLoopExitTemperature(29.4) sizingPlant.setLoopDesignTemperatureDifference(5.6) diff --git a/model/simulationtests/coil_cooling_dx_singlespeed_thermalstorage.rb b/model/simulationtests/coil_cooling_dx_singlespeed_thermalstorage.rb index f2f967a92..6e17ba50c 100644 --- a/model/simulationtests/coil_cooling_dx_singlespeed_thermalstorage.rb +++ b/model/simulationtests/coil_cooling_dx_singlespeed_thermalstorage.rb @@ -69,7 +69,7 @@ def curve_quadratic(model, c_1constant, c_2x, c_3xPOW2, minx, maxx, miny = nil, return curve end -def curve_triquadratic(model, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, minx, maxx, miny, maxy, minz, maxz) +def curve_triquadratic(model, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, minx, maxx, miny, maxy, minz, maxz) # rubocop:disable Metrics/ParameterLists curve = OpenStudio::Model::CurveTriquadratic.new(model) curve.setCoefficient1Constant(c1) curve.setCoefficient2xPOW2(c2) diff --git a/model/simulationtests/coil_userdefined.rb b/model/simulationtests/coil_userdefined.rb index d12984837..f44eb0a4a 100644 --- a/model/simulationtests/coil_userdefined.rb +++ b/model/simulationtests/coil_userdefined.rb @@ -38,7 +38,7 @@ z = model.getThermalZones.min_by(&:nameString) airLoop = model.getAirLoopHVACs.min_by(&:nameString) # get supplyOutletNode -supplyOutletNode = airLoop.supplyOutletNode() +supplyOutletNode = airLoop.supplyOutletNode # make CoilUserDefined coil = OpenStudio::Model::CoilUserDefined.new(model) diff --git a/model/simulationtests/doas.rb b/model/simulationtests/doas.rb index fec3bfa1b..b1de44231 100644 --- a/model/simulationtests/doas.rb +++ b/model/simulationtests/doas.rb @@ -131,7 +131,7 @@ hw_temp_sch.defaultDaySchedule.addValue(OpenStudio::Time.new(0, 24, 0, 0), hw_temp_c) hw_stpt_manager = OpenStudio::Model::SetpointManagerScheduled.new(model, hw_temp_sch) hw_stpt_manager.addToNode(hw_loop.supplyOutletNode) -sizingPlant = hw_loop.sizingPlant() +sizingPlant = hw_loop.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(82.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/epw_design_conditions.rb b/model/simulationtests/epw_design_conditions.rb index 138629225..6619056d1 100644 --- a/model/simulationtests/epw_design_conditions.rb +++ b/model/simulationtests/epw_design_conditions.rb @@ -39,13 +39,11 @@ weather_files = Dir.glob('../../weatherdata/EPW/*.epw') weather_files.each do |weather_file| - begin - epw_file = OpenStudio::EpwFile.new(weather_file) - epw_design_conditions = epw_file.designConditions - puts "#{File.basename(weather_file)}: success" - rescue StandardError - puts "#{File.basename(weather_file)}: FAILURE" - end + epw_file = OpenStudio::EpwFile.new(weather_file) + epw_design_conditions = epw_file.designConditions + puts "#{File.basename(weather_file)}: success" + rescue StandardError + puts "#{File.basename(weather_file)}: FAILURE" end else diff --git a/model/simulationtests/ghx_horizontal_trench_kusuda.rb b/model/simulationtests/ghx_horizontal_trench_kusuda.rb index d83f47015..2da8a22aa 100644 --- a/model/simulationtests/ghx_horizontal_trench_kusuda.rb +++ b/model/simulationtests/ghx_horizontal_trench_kusuda.rb @@ -21,7 +21,7 @@ condenserWaterPlant = OpenStudio::Model::PlantLoop.new(model) condenserWaterPlant.setName('Condenser Water Plant') -sizingPlant = condenserWaterPlant.sizingPlant() +sizingPlant = condenserWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(30.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/ghx_horizontal_trench_xing.rb b/model/simulationtests/ghx_horizontal_trench_xing.rb index 52b3b56eb..a99cda188 100644 --- a/model/simulationtests/ghx_horizontal_trench_xing.rb +++ b/model/simulationtests/ghx_horizontal_trench_xing.rb @@ -23,7 +23,7 @@ condenserWaterPlant = OpenStudio::Model::PlantLoop.new(model) condenserWaterPlant.setName('Condenser Water Plant') -sizingPlant = condenserWaterPlant.sizingPlant() +sizingPlant = condenserWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(30.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/ghx_vertical_kusuda.rb b/model/simulationtests/ghx_vertical_kusuda.rb index 9963c0531..3eae72cc8 100644 --- a/model/simulationtests/ghx_vertical_kusuda.rb +++ b/model/simulationtests/ghx_vertical_kusuda.rb @@ -17,7 +17,7 @@ condenserWaterPlant = OpenStudio::Model::PlantLoop.new(model) condenserWaterPlant.setName('Condenser Water Plant') -sizingPlant = condenserWaterPlant.sizingPlant() +sizingPlant = condenserWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(30.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/ghx_vertical_xing.rb b/model/simulationtests/ghx_vertical_xing.rb index 16090629d..87983e829 100644 --- a/model/simulationtests/ghx_vertical_xing.rb +++ b/model/simulationtests/ghx_vertical_xing.rb @@ -19,7 +19,7 @@ condenserWaterPlant = OpenStudio::Model::PlantLoop.new(model) condenserWaterPlant.setName('Condenser Water Plant') -sizingPlant = condenserWaterPlant.sizingPlant() +sizingPlant = condenserWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(30.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/heatpump_hot_water.rb b/model/simulationtests/heatpump_hot_water.rb index f29135f26..b19dd5d3c 100644 --- a/model/simulationtests/heatpump_hot_water.rb +++ b/model/simulationtests/heatpump_hot_water.rb @@ -60,7 +60,7 @@ hot_water_heater = OpenStudio::Model::WaterHeaterHeatPumpWrappedCondenser.new(model) hot_water_heater.addToThermalZone(zone) -tank = hot_water_heater.tank() +tank = hot_water_heater.tank plant.addSupplyBranchForComponent(tank) # hot_water_heater = OpenStudio::Model::WaterHeaterHeatPumpWrappedCondenser.new(model) diff --git a/model/simulationtests/heatpump_plantloop_eir_heatrecovery.rb b/model/simulationtests/heatpump_plantloop_eir_heatrecovery.rb index 0194a0601..ef7c79b2a 100644 --- a/model/simulationtests/heatpump_plantloop_eir_heatrecovery.rb +++ b/model/simulationtests/heatpump_plantloop_eir_heatrecovery.rb @@ -135,7 +135,7 @@ plhp_airsource_clg.electricInputtoOutputRatioModifierFunctionofTemperatureCurve.setName('EIRCurveFuncTemp2 Air Source') plhp_airsource_clg.electricInputtoOutputRatioModifierFunctionofPartLoadRatioCurve.setName('EIRCurveFuncPLR2 Air Source') -# Note: Heat Recovery is ONLY available for 'AirSource' HeatPumpPlantLoopEIRs +# NOTE: Heat Recovery is ONLY available for 'AirSource' HeatPumpPlantLoopEIRs tertiary = true hw_loop.addSupplyBranchForComponent(plhp_airsource_htg) # If not passing tertiary=true here, this would connect the Source Water Side diff --git a/model/simulationtests/interior_partitions.rb b/model/simulationtests/interior_partitions.rb index af4d9e7e5..ef9ce3904 100644 --- a/model/simulationtests/interior_partitions.rb +++ b/model/simulationtests/interior_partitions.rb @@ -65,8 +65,8 @@ y = 1 interiorArea = 0 heights.each_index do |i| - new_x = x + lengths[i] * dir_x[i] - new_y = y + lengths[i] * dir_y[i] + new_x = x + (lengths[i] * dir_x[i]) + new_y = y + (lengths[i] * dir_y[i]) points = OpenStudio::Point3dVector.new points << OpenStudio::Point3d.new(x, y, 0) points << OpenStudio::Point3d.new(new_x, new_y, 0) diff --git a/model/simulationtests/lib/baseline_model.rb b/model/simulationtests/lib/baseline_model.rb index 8f7013065..5c981c536 100644 --- a/model/simulationtests/lib/baseline_model.rb +++ b/model/simulationtests/lib/baseline_model.rb @@ -185,7 +185,7 @@ def add_geometry(params) # Rename all surfaces with a unique name for easy diffing space.surfaces.each do |s| fromSpaceName = space.nameString - surfaceType = s.surfaceType() + surfaceType = s.surfaceType boundaryCondition = s.outsideBoundaryCondition if boundaryCondition.downcase == 'ground' s.setName("#{fromSpaceName} Exterior Ground Floor") @@ -994,7 +994,7 @@ def add_swh_loop(water_heater_type, ambient_temperature_thermal_zone = nil) return service_water_loop end - def add_water_heater(water_heater_type, water_heater_fuel, temp_sch_type_limits = nil, swh_temp_sch = nil, ambient_temperature_thermal_zone = nil, service_water_flowrate_schedule = nil) + def add_water_heater(water_heater_type, water_heater_fuel, temp_sch_type_limits = nil, swh_temp_sch = nil, ambient_temperature_thermal_zone = nil, service_water_flowrate_schedule = nil) # rubocop:disable Metrics/ParameterLists # Water heater # TODO Standards - Change water heater methodology to follow # 'Model Enhancements Appendix A.' diff --git a/model/simulationtests/lowtemprad_constflow.rb b/model/simulationtests/lowtemprad_constflow.rb index ca74eb9bc..f327d838f 100644 --- a/model/simulationtests/lowtemprad_constflow.rb +++ b/model/simulationtests/lowtemprad_constflow.rb @@ -27,7 +27,7 @@ hotWaterPlant = OpenStudio::Model::PlantLoop.new(model) hotWaterPlant.setName('Hot Water Plant') -sizingPlant = hotWaterPlant.sizingPlant() +sizingPlant = hotWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(60.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) @@ -42,7 +42,7 @@ chilledWaterPlant = OpenStudio::Model::PlantLoop.new(model) chilledWaterPlant.setName('Chilled Water Plant') -sizingPlant = chilledWaterPlant.sizingPlant() +sizingPlant = chilledWaterPlant.sizingPlant sizingPlant.setLoopType('Cooling') sizingPlant.setDesignLoopExitTemperature(10.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/lowtemprad_varflow.rb b/model/simulationtests/lowtemprad_varflow.rb index 477f53485..062af5769 100644 --- a/model/simulationtests/lowtemprad_varflow.rb +++ b/model/simulationtests/lowtemprad_varflow.rb @@ -27,7 +27,7 @@ hotWaterPlant = OpenStudio::Model::PlantLoop.new(model) hotWaterPlant.setName('Hot Water Plant') -sizingPlant = hotWaterPlant.sizingPlant() +sizingPlant = hotWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(60.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) @@ -42,7 +42,7 @@ chilledWaterPlant = OpenStudio::Model::PlantLoop.new(model) chilledWaterPlant.setName('Chilled Water Plant') -sizingPlant = chilledWaterPlant.sizingPlant() +sizingPlant = chilledWaterPlant.sizingPlant sizingPlant.setLoopType('Cooling') sizingPlant.setDesignLoopExitTemperature(10.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/python_plugin.rb b/model/simulationtests/python_plugin.rb index 4cd4fa40b..4626a79b4 100644 --- a/model/simulationtests/python_plugin.rb +++ b/model/simulationtests/python_plugin.rb @@ -25,7 +25,7 @@ zone_names = model.getThermalZones.map(&:nameString).sort -zone_names_str_list = '["' + zone_names.join('", "') + '"]' +zone_names_str_list = "[\"#{zone_names.join('", "')}\"]" # Add a PythonPlugin:Variable (all OS SDK PythonPluginVariable objects are # translated to a single E+ PythonPlugin:Variables (extensible object)) @@ -69,7 +69,7 @@ pluginClassName = 'AverageZoneTemps' -python_plugin_file_content = ''"from pyenergyplus.plugin import EnergyPlusPlugin +python_plugin_file_content = "from pyenergyplus.plugin import EnergyPlusPlugin class #{pluginClassName}(EnergyPlusPlugin): @@ -107,7 +107,7 @@ def on_end_of_zone_timestep_before_zone_reporting(self, state) -> int: past_daily_avg_temp = self.api.exchange.get_trend_average(state, self.data['trend'], #{n_timesteps}) self.api.exchange.set_global_value(state, self.data['running_avg_temp_variable'], past_daily_avg_temp) return 0 -"'' +" # Write it to a temporary directory so we don't pollute the current directory # ExternalFile will copy it diff --git a/model/simulationtests/python_plugin_search_paths.rb b/model/simulationtests/python_plugin_search_paths.rb index acdd7bfbc..51904a125 100644 --- a/model/simulationtests/python_plugin_search_paths.rb +++ b/model/simulationtests/python_plugin_search_paths.rb @@ -25,7 +25,7 @@ zone_names = model.getThermalZones.map(&:nameString).sort -zone_names_str_list = '["' + zone_names.join('", "') + '"]' +zone_names_str_list = "[\"#{zone_names.join('", "')}\"]" # Add a PythonPlugin:Variable (all OS SDK PythonPluginVariable objects are # translated to a single E+ PythonPlugin:Variables (extensible object)) @@ -69,7 +69,7 @@ pluginClassName = 'AverageZoneTemps' -python_plugin_file_content = ''"from pyenergyplus.plugin import EnergyPlusPlugin +python_plugin_file_content = "from pyenergyplus.plugin import EnergyPlusPlugin # NOTE: This external script must be locatable, so we'll add it to the PythonPluginSearchPaths import python_plugin_search_paths_script @@ -110,7 +110,7 @@ def on_end_of_zone_timestep_before_zone_reporting(self, state) -> int: past_daily_avg_temp = self.api.exchange.get_trend_average(state, self.data['trend'], #{n_timesteps}) self.api.exchange.set_global_value(state, self.data['running_avg_temp_variable'], past_daily_avg_temp) return 0 -"'' +" # Write it to a temporary directory so we don't pollute the current directory # ExternalFile will copy it diff --git a/model/simulationtests/surface_properties_ground_and_solarmult.rb b/model/simulationtests/surface_properties_ground_and_solarmult.rb index cd4ceffd1..e7d1bf071 100644 --- a/model/simulationtests/surface_properties_ground_and_solarmult.rb +++ b/model/simulationtests/surface_properties_ground_and_solarmult.rb @@ -130,7 +130,7 @@ OpenStudio::Model::OptionalSchedule.new(parkingTempSch), OpenStudio::Model::OptionalSchedule.new(parkingReflSch)) raise if spigs.numberofGroundSurfaceGroups != 2 -raise if spigs.groundSurfaceGroups[1].viewFactor != 0.2 +raise if (spigs.groundSurfaceGroups[1].viewFactor - 0.2).abs > Float::EPSILON # Save the groups groups = spigs.groundSurfaceGroups @@ -150,7 +150,8 @@ g1 = spigs.groundSurfaceGroups[0] raise if g1.groundSurfaceName != 'GndSurfs:Grass' -raise if g1.viewFactor != 0.3 +raise if (g1.viewFactor - 0.3).abs > Float::EPSILON + raise if g1.temperatureSchedule.empty? raise if g1.temperatureSchedule.get != grassTempSch raise if g1.reflectanceSchedule.empty? @@ -158,7 +159,7 @@ g2 = spigs.getGroundSurfaceGroup(1).get raise if g2.groundSurfaceName != 'GndSurfs:Parking' -raise if g2.viewFactor != 0.2 +raise if (g2.viewFactor - 0.2).abs > Float::EPSILON raise if g2.temperatureSchedule.empty? raise if g2.temperatureSchedule.get != parkingTempSch raise if g2.reflectanceSchedule.empty? diff --git a/model/simulationtests/surface_properties_lwr.rb b/model/simulationtests/surface_properties_lwr.rb index e41bc6403..5ecd5b551 100644 --- a/model/simulationtests/surface_properties_lwr.rb +++ b/model/simulationtests/surface_properties_lwr.rb @@ -132,7 +132,7 @@ # values s_sp.addSurroundingSurfaceGroup('SurroundingSurface2', 0.4, tempSch1) raise if s_sp.numberofSurroundingSurfaceGroups != 2 -raise if s_sp.surroundingSurfaceGroups[1].viewFactor != 0.4 +raise if (s_sp.surroundingSurfaceGroups[1].viewFactor - 0.4).abs > Float::EPSILON # Save the groups groups = s_sp.surroundingSurfaceGroups @@ -151,12 +151,12 @@ g1 = s_sp.surroundingSurfaceGroups[0] raise if g1.surroundingSurfaceName != 'SurroundingSurface1' -raise if g1.viewFactor != 0.5 +raise if (g1.viewFactor - 0.5).abs > Float::EPSILON raise if g1.temperatureSchedule != tempSch1 g2 = s_sp.getSurroundingSurfaceGroup(1).get raise if g2.surroundingSurfaceName != 'SurroundingSurface2' -raise if g2.viewFactor != 0.4 +raise if (g2.viewFactor - 0.4).abs > Float::EPSILON raise if g2.temperatureSchedule != tempSch1 ############################################################################### diff --git a/model/simulationtests/thermochromic_windows.rb b/model/simulationtests/thermochromic_windows.rb index cb1e3c69a..69a980c46 100644 --- a/model/simulationtests/thermochromic_windows.rb +++ b/model/simulationtests/thermochromic_windows.rb @@ -67,9 +67,9 @@ # Group rows by opticalDataTemperature column groups = data.group_by { |row| row['opticalDataTemperature'].to_i } -groups.each_with_index do |(opticalDataTemperature, rows), i| +groups.each_with_index do |(optical_data_temp, rows), i| s = OpenStudio::Model::StandardGlazing.new(model) - s.setName("WO18RT#{opticalDataTemperature}") + s.setName("WO18RT#{optical_data_temp}") s.setThickness(0.0075) s.resetSolarTransmittanceatNormalIncidence @@ -90,7 +90,7 @@ s.setWindowGlassSpectralDataSet(data_set) s.setOpticalDataType('Spectral') - data_set.setName("WO18RT#{opticalDataTemperature}SP") + data_set.setName("WO18RT#{optical_data_temp}SP") rows.each do |row| data_set.addSpectralDataField( @@ -102,9 +102,9 @@ end if i.even? - raise 'Failed to add ThermochromicGroup' unless t.addThermochromicGroup(s, opticalDataTemperature) + raise 'Failed to add ThermochromicGroup' unless t.addThermochromicGroup(s, optical_data_temp) else - group = OpenStudio::Model::ThermochromicGroup.new(s, opticalDataTemperature) + group = OpenStudio::Model::ThermochromicGroup.new(s, optical_data_temp) raise 'Failed to add ThermochromicGroup object' unless t.addThermochromicGroup(group) end end diff --git a/model/simulationtests/unitary_system.rb b/model/simulationtests/unitary_system.rb index 5f39c148a..98618a3db 100644 --- a/model/simulationtests/unitary_system.rb +++ b/model/simulationtests/unitary_system.rb @@ -28,7 +28,7 @@ # Hot Water Plant hotWaterPlant = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = hotWaterPlant.sizingPlant() +sizingPlant = hotWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(82.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) @@ -63,7 +63,7 @@ # Chilled Water Plant chilledWaterPlant = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = chilledWaterPlant.sizingPlant() +sizingPlant = chilledWaterPlant.sizingPlant sizingPlant.setLoopType('Cooling') sizingPlant.setDesignLoopExitTemperature(7.22) sizingPlant.setLoopDesignTemperatureDifference(6.67) @@ -130,7 +130,7 @@ # Condenser System condenserSystem = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = condenserSystem.sizingPlant() +sizingPlant = condenserSystem.sizingPlant sizingPlant.setLoopType('Condenser') sizingPlant.setDesignLoopExitTemperature(29.4) sizingPlant.setLoopDesignTemperatureDifference(5.6) diff --git a/model/simulationtests/unitary_system_performance_multispeed.rb b/model/simulationtests/unitary_system_performance_multispeed.rb index f6ba2a235..2c5ff219e 100644 --- a/model/simulationtests/unitary_system_performance_multispeed.rb +++ b/model/simulationtests/unitary_system_performance_multispeed.rb @@ -28,7 +28,7 @@ # Hot Water Plant hotWaterPlant = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = hotWaterPlant.sizingPlant() +sizingPlant = hotWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(82.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) @@ -63,7 +63,7 @@ # Chilled Water Plant chilledWaterPlant = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = chilledWaterPlant.sizingPlant() +sizingPlant = chilledWaterPlant.sizingPlant sizingPlant.setLoopType('Cooling') sizingPlant.setDesignLoopExitTemperature(7.22) sizingPlant.setLoopDesignTemperatureDifference(6.67) @@ -130,7 +130,7 @@ # Condenser System condenserSystem = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = condenserSystem.sizingPlant() +sizingPlant = condenserSystem.sizingPlant sizingPlant.setLoopType('Condenser') sizingPlant.setDesignLoopExitTemperature(29.4) sizingPlant.setLoopDesignTemperatureDifference(5.6) diff --git a/model/simulationtests/unitary_test.rb b/model/simulationtests/unitary_test.rb index 5f7597020..6a2e5f66a 100644 --- a/model/simulationtests/unitary_test.rb +++ b/model/simulationtests/unitary_test.rb @@ -62,7 +62,7 @@ # fan.remove hotWaterPlant = OpenStudio::Model::PlantLoop.new(model) -sizingPlant = hotWaterPlant.sizingPlant() +sizingPlant = hotWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(82.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/vrf_watercooled.rb b/model/simulationtests/vrf_watercooled.rb index e51af58da..46eb27eea 100644 --- a/model/simulationtests/vrf_watercooled.rb +++ b/model/simulationtests/vrf_watercooled.rb @@ -70,7 +70,7 @@ # (Controls could be better) condenserSystem = OpenStudio::Model::PlantLoop.new(model) condenserSystem.setName('CW Loop') -sizingPlant = condenserSystem.sizingPlant() +sizingPlant = condenserSystem.sizingPlant sizingPlant.setLoopType('Condenser') sizingPlant.setDesignLoopExitTemperature(29.4) sizingPlant.setLoopDesignTemperatureDifference(5.6) diff --git a/model/simulationtests/water_economizer.rb b/model/simulationtests/water_economizer.rb index ac9408e47..492ebc149 100644 --- a/model/simulationtests/water_economizer.rb +++ b/model/simulationtests/water_economizer.rb @@ -26,7 +26,7 @@ plant = OpenStudio::Model::PlantLoop.new(model) plant.setName('Economizing Plant') -sizingPlant = plant.sizingPlant() +sizingPlant = plant.sizingPlant sizingPlant.setLoopType('Condenser') sizingPlant.setDesignLoopExitTemperature(26.0) sizingPlant.setLoopDesignTemperatureDifference(5.6) diff --git a/model/simulationtests/zone_hvac.rb b/model/simulationtests/zone_hvac.rb index baa66e1f1..ab0e8ff8b 100644 --- a/model/simulationtests/zone_hvac.rb +++ b/model/simulationtests/zone_hvac.rb @@ -27,7 +27,7 @@ hotWaterPlant = OpenStudio::Model::PlantLoop.new(model) hotWaterPlant.setName('Hot Water Plant') -sizingPlant = hotWaterPlant.sizingPlant() +sizingPlant = hotWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(82.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) @@ -79,7 +79,7 @@ condenserWaterPlant = OpenStudio::Model::PlantLoop.new(model) condenserWaterPlant.setName('Condenser Water Plant') -sizingPlant = condenserWaterPlant.sizingPlant() +sizingPlant = condenserWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(30.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/model/simulationtests/zone_hvac2.rb b/model/simulationtests/zone_hvac2.rb index 946973f74..45e592e4e 100644 --- a/model/simulationtests/zone_hvac2.rb +++ b/model/simulationtests/zone_hvac2.rb @@ -27,7 +27,7 @@ hotWaterPlant = OpenStudio::Model::PlantLoop.new(model) hotWaterPlant.setName('Hot Water Plant') -sizingPlant = hotWaterPlant.sizingPlant() +sizingPlant = hotWaterPlant.sizingPlant sizingPlant.setLoopType('Heating') sizingPlant.setDesignLoopExitTemperature(82.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) @@ -79,7 +79,7 @@ condenserWaterPlant = OpenStudio::Model::PlantLoop.new(model) condenserWaterPlant.setName('Condenser Water Plant') -sizingPlant = condenserWaterPlant.sizingPlant() +sizingPlant = condenserWaterPlant.sizingPlant sizingPlant.setLoopType('Condenser') sizingPlant.setDesignLoopExitTemperature(30.0) sizingPlant.setLoopDesignTemperatureDifference(11.0) diff --git a/test_helpers.rb b/test_helpers.rb index 3f3b13147..a5c0fde03 100644 --- a/test_helpers.rb +++ b/test_helpers.rb @@ -33,7 +33,7 @@ ENV['N'] = [1, nproc - 1].max.to_s puts "Setting ENV['N'] = #{ENV['N']}" end -ENV['MT_CPU'] = ENV['N'] +ENV['MT_CPU'] = ENV.fetch('N', nil) $SdkVersion = OpenStudio.openStudioVersion @@ -96,7 +96,7 @@ end if !ENV['CUSTOMTAG'].nil? - $Custom_tag = ENV['CUSTOMTAG'] + $Custom_tag = ENV.fetch('CUSTOMTAG', nil) # Debug # puts "Setting custom tag to #{$Custom_tag}" end @@ -185,9 +185,7 @@ def get_cli_subcommand_from_env(sdk_version_str, debug: false) # Temporary place to store the OSMs generated by Reverse Translator before # they get simulated through OpenStudio/EnergyPlus $TestDirSddRT = File.join($RootDir, 'testruns/SddReverseTranslator/') -if !File.exist?($TestDirSddRT) - FileUtils.mkdir_p($TestDirSddRT) -end +FileUtils.mkdir_p($TestDirSddRT) puts "Running for OpenStudio #{$SdkLongVersion}" @@ -200,7 +198,7 @@ def get_cli_subcommand_from_env(sdk_version_str, debug: false) is_docker = File.file?(proc_file) && !File.readlines(proc_file).grep(/docker/).empty? if is_docker # Mounted directory is at /root/test - $OutOSWDir = File.join(ENV['HOME'], 'test') + $OutOSWDir = File.join(Dir.home, 'test') else # Directly in here $OutOSWDir = File.join($RootDir, 'test') @@ -493,8 +491,8 @@ def compare_osw_eui_with_previous_version(cp_out_osw, eui_pct_threshold: $EuiPct pct_diff = 100 * (new_eui - old_eui) / old_eui.to_f - assert (pct_diff < eui_pct_threshold), "#{pct_diff.round(3)}% difference in EUI is too large for #{cp_out_osw}" \ - " between #{$SdkPreviousVersion} and #{$SdkVersion}" + assert (pct_diff < eui_pct_threshold), "#{pct_diff.round(3)}% difference in EUI is too large for #{cp_out_osw} " \ + "between #{$SdkPreviousVersion} and #{$SdkVersion}" end # Helper function to post-process the out.osw and save it in test/ with @@ -511,7 +509,7 @@ def compare_osw_eui_with_previous_version(cp_out_osw, eui_pct_threshold: $EuiPct # # @return result_osw [Hash]: the sanitized result_osw should you need to do # more stuff with it -def postprocess_out_osw_and_copy(out_osw, cp_out_osw, compare_eui = true) +def postprocess_out_osw_and_copy(out_osw, cp_out_osw, compare_eui: true) raise "Cannot find file #{out_osw}" if !File.exist?(out_osw) result_osw = nil @@ -567,9 +565,7 @@ def postprocess_out_osw_and_copy(out_osw, cp_out_osw, compare_eui = true) result_osw.delete(:eplusout_err) end - File.open(cp_out_osw, 'w') do |f| - f.write(JSON.pretty_generate(result_osw)) - end + File.write(cp_out_osw, JSON.pretty_generate(result_osw)) end @@ -602,12 +598,14 @@ def sim_test(filename, options = {}) # Cp to the OutOSW directory cp_out_osw = File.join($OutOSWDir, "#{filename}_#{$SdkVersion}_out#{$Custom_tag}.osw") end + # rubocop:disable Style/RedundantCondition if options[:base_dir] base_dir = options[:base_dir] # puts "Setting base_dir to #{base_dir}" else base_dir = $ModelDir end + # rubocop:enable Style/RedundantCondition if options[:compare_eui].nil? compare_eui = true @@ -638,7 +636,7 @@ def sim_test(filename, options = {}) # todo, add other measures to the workflow # Start by deleting the testruns/test_xxx directory and recreating it - FileUtils.rm_rf(dir) if File.exist?(dir) + FileUtils.rm_rf(dir) FileUtils.mkdir_p(dir) ext = File.extname(filename) @@ -799,7 +797,7 @@ def sim_test(filename, options = {}) end # Post-process the out_osw - result_osw = postprocess_out_osw_and_copy(out_osw, cp_out_osw, compare_eui) + result_osw = postprocess_out_osw_and_copy(out_osw, cp_out_osw, compare_eui: compare_eui) # return result_osw for further checks return result_osw @@ -812,7 +810,7 @@ def intersect_test(filename) out_osm = File.join(dir, 'out.osm') rb_file = File.join(dir, 'intersect.rb') - FileUtils.rm_rf(dir) if File.exist?(dir) + FileUtils.rm_rf(dir) FileUtils.mkdir_p(dir) erb_in = '' @@ -833,7 +831,7 @@ def intersect_test(filename) end # test the autosizing methods -def autosizing_test(filename, weather_file = nil, model_measures = [], energyplus_measures = [], reporting_measures = []) +def autosizing_test(filename, weather_file = nil, model_measures = [], energyplus_measures = [], reporting_measures = []) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/ParameterLists dir = File.join($TestDir, filename) in_osw = File.join(dir, 'in.osw') out_osw = File.join(dir, 'out.osw') @@ -850,7 +848,7 @@ def autosizing_test(filename, weather_file = nil, model_measures = [], energyplu # for the simulation itself to rerun run_sim = true if run_sim - FileUtils.rm_rf(dir) if File.exist?(dir) + FileUtils.rm_rf(dir) FileUtils.mkdir_p(dir) FileUtils.cp($OswFile, in_osw) @@ -886,7 +884,7 @@ def autosizing_test(filename, weather_file = nil, model_measures = [], energyplu # false to skip the call to compare_osw_eui_with_previous_version # this is an ever changing test, so EUI comparison is boggus - result_osw = postprocess_out_osw_and_copy(out_osw, cp_out_osw, false) + result_osw = postprocess_out_osw_and_copy(out_osw, cp_out_osw, compare_eui: false) # Load the model versionTranslator = OpenStudio::OSVersion::VersionTranslator.new @@ -1412,7 +1410,7 @@ def sql_test(options = {}) # for the simulation itself to rerun run_sim = true if run_sim - FileUtils.rm_rf(dir) if File.exist?(dir) + FileUtils.rm_rf(dir) FileUtils.mkdir_p(dir) # FileUtils.cp($OswFile, osw) diff --git a/utilities_tests.rb b/utilities_tests.rb index e9973f4c3..df49c7c5b 100644 --- a/utilities_tests.rb +++ b/utilities_tests.rb @@ -19,9 +19,7 @@ def name_result # (Over)write a hash as a pretty json into a file def output_json_status(test_result_file, result_h) - File.open(test_result_file, 'w') do |f| - f.write(JSON.pretty_generate(result_h)) - end + File.write(test_result_file, JSON.pretty_generate(result_h)) end # the tests