From d6e6d06d3926a101df153ce5b61f7ef4fefe26bf Mon Sep 17 00:00:00 2001 From: guille Date: Tue, 6 Jun 2023 14:31:25 -0400 Subject: [PATCH] Code quality check --- hub/city_model_structure/building.py | 2 +- .../building_demand/thermal_zone.py | 6 +++--- hub/exports/energy_building_exports_factory.py | 2 +- hub/helpers/geometry_helper.py | 2 +- hub/imports/construction/nrcan_physics_parameters.py | 10 +++++----- hub/imports/construction/nrel_physics_parameters.py | 7 ++----- hub/imports/weather/helpers/weather.py | 1 - hub/persistence/db_control.py | 1 - 8 files changed, 13 insertions(+), 18 deletions(-) diff --git a/hub/city_model_structure/building.py b/hub/city_model_structure/building.py index 83f50143..d469f985 100644 --- a/hub/city_model_structure/building.py +++ b/hub/city_model_structure/building.py @@ -84,7 +84,7 @@ class Building(CityObject): elif surface.type == cte.INTERIOR_SLAB: self._interior_slabs.append(surface) else: - logging.error(f'Building {self.name} [{self.aliases}] has an unexpected surface type {surface.type}.\n') + logging.error(f'Building %s [%s] has an unexpected surface type %s.', self.name, self.aliases, surface.type) @property def shell(self) -> Polyhedron: diff --git a/hub/city_model_structure/building_demand/thermal_zone.py b/hub/city_model_structure/building_demand/thermal_zone.py index aad93286..f93db5a5 100644 --- a/hub/city_model_structure/building_demand/thermal_zone.py +++ b/hub/city_model_structure/building_demand/thermal_zone.py @@ -520,10 +520,10 @@ class ThermalZone: if _schedules_defined: _schedules = [] - for day, _ in enumerate(_days): + for day_index, day in enumerate(_days): _schedule = copy.deepcopy(_base_schedule) - _schedule.day_types = [_days[day]] - _schedule.values = values[:day] + _schedule.day_types = [day] + _schedule.values = values[:day_index] _schedules.append(_schedule) _internal_gain.average_internal_gain = _average_internal_gain diff --git a/hub/exports/energy_building_exports_factory.py b/hub/exports/energy_building_exports_factory.py index 5f736dfb..3fefaeea 100644 --- a/hub/exports/energy_building_exports_factory.py +++ b/hub/exports/energy_building_exports_factory.py @@ -67,4 +67,4 @@ class EnergyBuildingsExportsFactory: Export the city given to the class using the given export type handler :return: None """ - return getattr(self, self._export_type, lambda: None) \ No newline at end of file + return getattr(self, self._export_type, lambda: None) diff --git a/hub/helpers/geometry_helper.py b/hub/helpers/geometry_helper.py index 0c35c6a5..eeb6edfc 100644 --- a/hub/helpers/geometry_helper.py +++ b/hub/helpers/geometry_helper.py @@ -295,7 +295,7 @@ class GeometryHelper: distance = math.inf country = 'Unknown' city = 'Unknown' - region = 'Unknown' + region_code = 'Unknown' with open(_data_path, 'r', encoding='utf-8') as file: for _, line in enumerate(file): fields = line.split('\t') diff --git a/hub/imports/construction/nrcan_physics_parameters.py b/hub/imports/construction/nrcan_physics_parameters.py index b8155013..13cd231a 100644 --- a/hub/imports/construction/nrcan_physics_parameters.py +++ b/hub/imports/construction/nrcan_physics_parameters.py @@ -35,16 +35,16 @@ class NrcanPhysicsParameters: nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog for building in city.buildings: if building.function not in Dictionaries().hub_function_to_nrcan_construction_function.keys(): - logging.error(f'Building {building.name} has an unknown building function {building.function}\n') + logging.error(f'Building %s has an unknown building function %s', building.name, building.function ) continue function = Dictionaries().hub_function_to_nrcan_construction_function[building.function] try: archetype = self._search_archetype(nrcan_catalog, function, building.year_of_construction, self._climate_zone) except KeyError: - logging.error(f'Building {building.name} has unknown construction archetype for building function: {function} ' - f'[{building.function}], building year of construction: {building.year_of_construction} ' - f'and climate zone {self._climate_zone}\n') + logging.error(f'Building %s has unknown construction archetype for building function: %s ' + f'[%s], building year of construction: %s and climate zone %s', building.name, function, + building.function, building.year_of_construction, self._climate_zone) continue # if building has no thermal zones defined from geometry, and the building will be divided in storeys, @@ -100,7 +100,7 @@ class NrcanPhysicsParameters: thermal_boundary.construction_name = construction_archetype.name try: thermal_boundary.window_ratio = 0 - if thermal_boundary.type == cte.WALL or thermal_boundary.type == cte.ROOF: + if thermal_boundary.type in ( cte.WALL, cte.ROOF): if construction_archetype.window is not None: if -math.sqrt(2) / 2 < math.sin(thermal_boundary.parent_surface.azimuth) < math.sqrt(2) / 2: if 0 < math.cos(thermal_boundary.parent_surface.azimuth): diff --git a/hub/imports/construction/nrel_physics_parameters.py b/hub/imports/construction/nrel_physics_parameters.py index 071b92f8..eec57bc2 100644 --- a/hub/imports/construction/nrel_physics_parameters.py +++ b/hub/imports/construction/nrel_physics_parameters.py @@ -32,11 +32,8 @@ class NrelPhysicsParameters: city = self._city nrel_catalog = ConstructionCatalogFactory('nrel').catalog for building in city.buildings: - if building.function not in Dictionaries().hub_function_to_nrel_construction_function.keys(): - logging.error(f'Building {building.name} has unknown function [{building.function}]') - continue - if building.function not in Dictionaries().hub_function_to_nrel_construction_function.keys(): - logging.error(f'Building {building.name} has unknown function {building.function}\n') + if building.function not in Dictionaries().hub_function_to_nrel_construction_function: + logging.error(f'Building %s has unknown function %s', building.name, building.function) continue function = Dictionaries().hub_function_to_nrel_construction_function[building.function] try: diff --git a/hub/imports/weather/helpers/weather.py b/hub/imports/weather/helpers/weather.py index 9327d0de..c52580a6 100644 --- a/hub/imports/weather/helpers/weather.py +++ b/hub/imports/weather/helpers/weather.py @@ -129,4 +129,3 @@ class Weather: logging.warning('Specific weather data unknown for %s using Montreal data instead', region_code) return self._epw_file['CA.10.06'] return self._epw_file[region_code] - diff --git a/hub/persistence/db_control.py b/hub/persistence/db_control.py index 752ce3cd..6f2477da 100644 --- a/hub/persistence/db_control.py +++ b/hub/persistence/db_control.py @@ -211,4 +211,3 @@ class DBControl: :param application_uuid: the id of the application to get """ self._application.delete(application_uuid) -