diff --git a/hub/.gitignore b/hub/.gitignore index 8f8bdd78..e23b0042 100644 --- a/hub/.gitignore +++ b/hub/.gitignore @@ -1,10 +1,12 @@ !.gitignore -/venv/ +**/venv/ .idea/ /development_tests/ /data/energy_systems/heat_pumps/*.csv /data/energy_systems/heat_pumps/*.insel .DS_Store -.env -hub/logs +**/.env +**/hub/logs/ **/__pycache__/ +**/.idea/ + diff --git a/hub/catalog_factories/construction_catalog_factory.py b/hub/catalog_factories/construction_catalog_factory.py index c246374c..aa75b369 100644 --- a/hub/catalog_factories/construction_catalog_factory.py +++ b/hub/catalog_factories/construction_catalog_factory.py @@ -8,6 +8,8 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca from pathlib import Path from typing import TypeVar from hub.catalog_factories.construction.nrel_catalog import NrelCatalog +from hub.hub_logger import logger +from hub.helpers.utils import validate_import_export_type Catalog = TypeVar('Catalog') @@ -16,6 +18,11 @@ class ConstructionCatalogFactory: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/construction') self._catalog_type = '_' + file_type.lower() + class_funcs = validate_import_export_type(ConstructionCatalogFactory) + if self._catalog_type not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._path = base_path @property diff --git a/hub/catalog_factories/greenery_catalog_factory.py b/hub/catalog_factories/greenery_catalog_factory.py index f0c38df6..80640918 100644 --- a/hub/catalog_factories/greenery_catalog_factory.py +++ b/hub/catalog_factories/greenery_catalog_factory.py @@ -8,8 +8,11 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca from pathlib import Path from typing import TypeVar from hub.catalog_factories.greenery.greenery_catalog import GreeneryCatalog +from hub.hub_logger import logger +from hub.helpers.utils import validate_import_export_type Catalog = TypeVar('Catalog') + class GreeneryCatalogFactory: """ GreeneryCatalogFactory class @@ -18,6 +21,11 @@ class GreeneryCatalogFactory: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/greenery') self._catalog_type = '_' + file_type.lower() + class_funcs = validate_import_export_type(GreeneryCatalogFactory) + if self._catalog_type not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._path = base_path @property diff --git a/hub/catalog_factories/usage_catalog_factory.py b/hub/catalog_factories/usage_catalog_factory.py index a554748a..26aa6631 100644 --- a/hub/catalog_factories/usage_catalog_factory.py +++ b/hub/catalog_factories/usage_catalog_factory.py @@ -9,6 +9,8 @@ from pathlib import Path from typing import TypeVar from hub.catalog_factories.usage.comnet_catalog import ComnetCatalog from hub.catalog_factories.usage.nrcan_catalog import NrcanCatalog +from hub.hub_logger import logger +from hub.helpers.utils import validate_import_export_type Catalog = TypeVar('Catalog') @@ -17,6 +19,11 @@ class UsageCatalogFactory: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/usage') self._catalog_type = '_' + file_type.lower() + class_funcs = validate_import_export_type(UsageCatalogFactory) + if self._catalog_type not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._path = base_path @property diff --git a/hub/exports/energy_building_exports_factory.py b/hub/exports/energy_building_exports_factory.py index dd0d9170..97240d4f 100644 --- a/hub/exports/energy_building_exports_factory.py +++ b/hub/exports/energy_building_exports_factory.py @@ -9,6 +9,8 @@ from pathlib import Path from hub.exports.building_energy.energy_ade import EnergyAde from hub.exports.building_energy.idf import Idf from hub.exports.building_energy.insel.insel_monthly_energy_balance import InselMonthlyEnergyBalance +from hub.helpers.utils import validate_import_export_type +from hub.hub_logger import logger class EnergyBuildingsExportsFactory: @@ -18,6 +20,11 @@ class EnergyBuildingsExportsFactory: def __init__(self, export_type, city, path, target_buildings=None, adjacent_buildings=None): self._city = city self._export_type = '_' + export_type.lower() + class_funcs = validate_import_export_type(EnergyBuildingsExportsFactory) + if self._export_type not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) if isinstance(path, str): path = Path(path) self._path = path diff --git a/hub/exports/energy_systems/heat_pump_export.py b/hub/exports/energy_systems/heat_pump_export.py index 6496dc95..36512b5c 100644 --- a/hub/exports/energy_systems/heat_pump_export.py +++ b/hub/exports/energy_systems/heat_pump_export.py @@ -64,8 +64,8 @@ class HeatPumpExport: # User output return self._get_user_out_put() except IOError as err: - print("I/O exception: {}".format(err)) - logger.error(f'An I/O error occurred while running insel: {err}') + print("I/O exception: {}".format(str(err))) + logger.error(f'An I/O error occurred while running insel: {str(err)}') finally: insel_file_handler.close() insel_template_handler.close() diff --git a/hub/exports/exports_factory.py b/hub/exports/exports_factory.py index 5ee3a686..13df7569 100644 --- a/hub/exports/exports_factory.py +++ b/hub/exports/exports_factory.py @@ -9,6 +9,8 @@ from pathlib import Path from hub.exports.formats.obj import Obj from hub.exports.formats.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm from hub.exports.formats.stl import Stl +from hub.hub_logger import logger +from hub.helpers.utils import validate_import_export_type class ExportsFactory: @@ -18,6 +20,11 @@ class ExportsFactory: def __init__(self, export_type, city, path, target_buildings=None, adjacent_buildings=None): self._city = city self._export_type = '_' + export_type.lower() + class_funcs = validate_import_export_type(ExportsFactory) + if self._export_type not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) if isinstance(path, str): path = Path(path) self._path = path diff --git a/hub/helpers/auth.py b/hub/helpers/auth.py index 161a3ca2..f6cefa66 100644 --- a/hub/helpers/auth.py +++ b/hub/helpers/auth.py @@ -1,3 +1,10 @@ +""" +Constant module +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2023 Concordia CERC group +Project Coder Peter Yefi peteryefi@gmail.com +""" + import bcrypt import re diff --git a/hub/helpers/utils.py b/hub/helpers/utils.py new file mode 100644 index 00000000..ef461f28 --- /dev/null +++ b/hub/helpers/utils.py @@ -0,0 +1,18 @@ +""" +Constant module +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2023 Concordia CERC group +Project Coder Peter Yefi peteryefi@gmail.com +""" + + +def validate_import_export_type(cls_name: type): + """ + Retrieves all the function names in a class which are property types (decoration) + and normal functions + :param cls_name: the class name + :return: [str], a list of functions in the class + """ + return [func for func in dir(cls_name) + if (type(getattr(cls_name, func)) is property or callable(getattr(cls_name, func))) + and func in cls_name.__dict__ and func[0] == '_' and func != '__init__'] diff --git a/hub/imports/construction_factory.py b/hub/imports/construction_factory.py index bc77be4f..b119ca5f 100644 --- a/hub/imports/construction_factory.py +++ b/hub/imports/construction_factory.py @@ -6,6 +6,8 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ from pathlib import Path from hub.imports.construction.us_physics_parameters import UsPhysicsParameters +from hub.hub_logger import logger +from hub.helpers.utils import validate_import_export_type class ConstructionFactory: @@ -16,6 +18,11 @@ class ConstructionFactory: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/construction') self._handler = '_' + handler.lower().replace(' ', '_') + class_funcs = validate_import_export_type(ConstructionFactory) + if self._handler not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._city = city self._base_path = base_path diff --git a/hub/imports/energy_systems_factory.py b/hub/imports/energy_systems_factory.py index f167b848..b1f44876 100644 --- a/hub/imports/energy_systems_factory.py +++ b/hub/imports/energy_systems_factory.py @@ -8,6 +8,8 @@ Code contributors: Peter Yefi peteryefi@gmail.com from pathlib import Path from hub.imports.energy_systems.air_source_hp_parameters import AirSourceHeatPumpParameters from hub.imports.energy_systems.water_to_water_hp_parameters import WaterToWaterHPParameters +from hub.helpers.utils import validate_import_export_type +from hub.hub_logger import logger class EnergySystemsFactory: @@ -19,6 +21,11 @@ class EnergySystemsFactory: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/energy_systems') self._handler = '_' + handler.lower().replace(' ', '_') + class_funcs = validate_import_export_type(EnergySystemsFactory) + if self._handler not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._city = city self._base_path = base_path diff --git a/hub/imports/geometry_factory.py b/hub/imports/geometry_factory.py index d63e2e7a..f80580a5 100644 --- a/hub/imports/geometry_factory.py +++ b/hub/imports/geometry_factory.py @@ -13,6 +13,8 @@ from hub.imports.geometry.osm_subway import OsmSubway from hub.imports.geometry.rhino import Rhino from hub.imports.geometry.gpandas import GPandas from hub.imports.geometry.geojson import Geojson +from hub.helpers.utils import validate_import_export_type +from hub.hub_logger import logger class GeometryFactory: @@ -26,6 +28,11 @@ class GeometryFactory: year_of_construction_field=None, function_field=None): self._file_type = '_' + file_type.lower() + class_funcs = validate_import_export_type(GeometryFactory) + if self._file_type not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._path = path self._data_frame = data_frame self._height_field = height_field diff --git a/hub/imports/life_cycle_assessment_factory.py b/hub/imports/life_cycle_assessment_factory.py index 27add0a0..bc69bc6b 100644 --- a/hub/imports/life_cycle_assessment_factory.py +++ b/hub/imports/life_cycle_assessment_factory.py @@ -10,6 +10,8 @@ from hub.imports.life_cycle_assessment.lca_fuel import LcaFuel from hub.imports.life_cycle_assessment.lca_vehicle import LcaVehicle from hub.imports.life_cycle_assessment.lca_machine import LcaMachine from hub.imports.life_cycle_assessment.lca_material import LcaMaterial +from hub.helpers.utils import validate_import_export_type +from hub.hub_logger import logger class LifeCycleAssessment: @@ -20,6 +22,11 @@ class LifeCycleAssessment: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/life_cycle_assessment') self._handler = '_' + handler.lower().replace(' ', '_') + class_funcs = validate_import_export_type(LifeCycleAssessment) + if self._handler not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._city = city self._base_path = base_path diff --git a/hub/imports/sensors_factory.py b/hub/imports/sensors_factory.py index f161b8fc..d4793950 100644 --- a/hub/imports/sensors_factory.py +++ b/hub/imports/sensors_factory.py @@ -6,6 +6,8 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ from pathlib import Path +from hub.hub_logger import logger +from hub.helpers.utils import validate_import_export_type class SensorsFactory: @@ -16,6 +18,11 @@ class SensorsFactory: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/sensors') self._handler = '_' + handler.lower().replace(' ', '_') + class_funcs = validate_import_export_type(SensorsFactory) + if self._handler not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._city = city self._end_point = end_point self._base_path = base_path diff --git a/hub/imports/usage_factory.py b/hub/imports/usage_factory.py index b192c90c..27f8f8b9 100644 --- a/hub/imports/usage_factory.py +++ b/hub/imports/usage_factory.py @@ -9,6 +9,8 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord from pathlib import Path from hub.imports.usage.hft_usage_parameters import HftUsageParameters from hub.imports.usage.comnet_usage_parameters import ComnetUsageParameters +from hub.hub_logger import logger +from hub.helpers.utils import validate_import_export_type class UsageFactory: @@ -19,6 +21,11 @@ class UsageFactory: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/usage') self._handler = '_' + handler.lower().replace(' ', '_') + class_funcs = validate_import_export_type(UsageFactory) + if self._handler not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._city = city self._base_path = base_path diff --git a/hub/imports/weather_factory.py b/hub/imports/weather_factory.py index 0b214a79..296755de 100644 --- a/hub/imports/weather_factory.py +++ b/hub/imports/weather_factory.py @@ -7,6 +7,8 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca from pathlib import Path from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters +from hub.hub_logger import logger +from hub.helpers.utils import validate_import_export_type class WeatherFactory: @@ -18,6 +20,11 @@ class WeatherFactory: if base_path is None: base_path = Path(Path(__file__).parent.parent / 'data/weather') self._handler = '_' + handler.lower().replace(' ', '_') + class_funcs = validate_import_export_type(WeatherFactory) + if self._handler not in class_funcs: + err_msg = f"Wrong import type. Valid functions include {class_funcs}" + logger.error(err_msg) + raise Exception(err_msg) self._city = city self._base_path = base_path self._file_name = file_name