Merge remote-tracking branch 'origin/master'

# Conflicts:
#	hub/catalog_factories/construction_catalog_factory.py
#	hub/imports/construction_factory.py
#	hub/imports/usage_factory.py
This commit is contained in:
Guille Gutierrez 2023-01-26 05:23:22 -05:00
commit ff4fef17fb
16 changed files with 118 additions and 5 deletions

8
hub/.gitignore vendored
View File

@ -1,10 +1,12 @@
!.gitignore !.gitignore
/venv/ **/venv/
.idea/ .idea/
/development_tests/ /development_tests/
/data/energy_systems/heat_pumps/*.csv /data/energy_systems/heat_pumps/*.csv
/data/energy_systems/heat_pumps/*.insel /data/energy_systems/heat_pumps/*.insel
.DS_Store .DS_Store
.env **/.env
hub/logs **/hub/logs/
**/__pycache__/ **/__pycache__/
**/.idea/

View File

@ -8,6 +8,8 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
from pathlib import Path from pathlib import Path
from typing import TypeVar from typing import TypeVar
from hub.catalog_factories.construction.nrel_catalog import NrelCatalog from hub.catalog_factories.construction.nrel_catalog import NrelCatalog
from hub.hub_logger import logger
from hub.helpers.utils import validate_import_export_type
from hub.catalog_factories.construction.nrcan_catalog import NrcanCatalog from hub.catalog_factories.construction.nrcan_catalog import NrcanCatalog
Catalog = TypeVar('Catalog') Catalog = TypeVar('Catalog')
@ -17,6 +19,11 @@ class ConstructionCatalogFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/construction') base_path = Path(Path(__file__).parent.parent / 'data/construction')
self._catalog_type = '_' + file_type.lower() 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 self._path = base_path
@property @property

View File

@ -8,8 +8,11 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
from pathlib import Path from pathlib import Path
from typing import TypeVar from typing import TypeVar
from hub.catalog_factories.greenery.greenery_catalog import GreeneryCatalog 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') Catalog = TypeVar('Catalog')
class GreeneryCatalogFactory: class GreeneryCatalogFactory:
""" """
GreeneryCatalogFactory class GreeneryCatalogFactory class
@ -18,6 +21,11 @@ class GreeneryCatalogFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/greenery') base_path = Path(Path(__file__).parent.parent / 'data/greenery')
self._catalog_type = '_' + file_type.lower() 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 self._path = base_path
@property @property

View File

@ -9,6 +9,8 @@ from pathlib import Path
from typing import TypeVar from typing import TypeVar
from hub.catalog_factories.usage.comnet_catalog import ComnetCatalog from hub.catalog_factories.usage.comnet_catalog import ComnetCatalog
from hub.catalog_factories.usage.nrcan_catalog import NrcanCatalog 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') Catalog = TypeVar('Catalog')
@ -17,6 +19,11 @@ class UsageCatalogFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/usage') base_path = Path(Path(__file__).parent.parent / 'data/usage')
self._catalog_type = '_' + file_type.lower() 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 self._path = base_path
@property @property

View File

@ -9,6 +9,8 @@ from pathlib import Path
from hub.exports.building_energy.energy_ade import EnergyAde from hub.exports.building_energy.energy_ade import EnergyAde
from hub.exports.building_energy.idf import Idf from hub.exports.building_energy.idf import Idf
from hub.exports.building_energy.insel.insel_monthly_energy_balance import InselMonthlyEnergyBalance 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: class EnergyBuildingsExportsFactory:
@ -18,6 +20,11 @@ class EnergyBuildingsExportsFactory:
def __init__(self, export_type, city, path, target_buildings=None, adjacent_buildings=None): def __init__(self, export_type, city, path, target_buildings=None, adjacent_buildings=None):
self._city = city self._city = city
self._export_type = '_' + export_type.lower() 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): if isinstance(path, str):
path = Path(path) path = Path(path)
self._path = path self._path = path

View File

@ -64,8 +64,8 @@ class HeatPumpExport:
# User output # User output
return self._get_user_out_put() return self._get_user_out_put()
except IOError as err: except IOError as err:
print("I/O exception: {}".format(err)) print("I/O exception: {}".format(str(err)))
logger.error(f'An I/O error occurred while running insel: {err}') logger.error(f'An I/O error occurred while running insel: {str(err)}')
finally: finally:
insel_file_handler.close() insel_file_handler.close()
insel_template_handler.close() insel_template_handler.close()

View File

@ -9,6 +9,8 @@ from pathlib import Path
from hub.exports.formats.obj import Obj from hub.exports.formats.obj import Obj
from hub.exports.formats.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm from hub.exports.formats.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from hub.exports.formats.stl import Stl from hub.exports.formats.stl import Stl
from hub.hub_logger import logger
from hub.helpers.utils import validate_import_export_type
class ExportsFactory: class ExportsFactory:
@ -18,6 +20,11 @@ class ExportsFactory:
def __init__(self, export_type, city, path, target_buildings=None, adjacent_buildings=None): def __init__(self, export_type, city, path, target_buildings=None, adjacent_buildings=None):
self._city = city self._city = city
self._export_type = '_' + export_type.lower() 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): if isinstance(path, str):
path = Path(path) path = Path(path)
self._path = path self._path = path

View File

@ -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 bcrypt
import re import re

18
hub/helpers/utils.py Normal file
View File

@ -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__']

View File

@ -7,6 +7,9 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
""" """
from pathlib import Path 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
from hub.imports.construction.nrel_physics_parameters import NrelPhysicsParameters from hub.imports.construction.nrel_physics_parameters import NrelPhysicsParameters
from hub.imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters from hub.imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters
@ -19,6 +22,11 @@ class ConstructionFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/construction') base_path = Path(Path(__file__).parent.parent / 'data/construction')
self._handler = '_' + handler.lower().replace(' ', '_') 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._city = city
self._base_path = base_path self._base_path = base_path

View File

@ -8,6 +8,8 @@ Code contributors: Peter Yefi peteryefi@gmail.com
from pathlib import Path from pathlib import Path
from hub.imports.energy_systems.air_source_hp_parameters import AirSourceHeatPumpParameters 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.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: class EnergySystemsFactory:
@ -19,6 +21,11 @@ class EnergySystemsFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/energy_systems') base_path = Path(Path(__file__).parent.parent / 'data/energy_systems')
self._handler = '_' + handler.lower().replace(' ', '_') 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._city = city
self._base_path = base_path self._base_path = base_path

View File

@ -13,6 +13,8 @@ from hub.imports.geometry.osm_subway import OsmSubway
from hub.imports.geometry.rhino import Rhino from hub.imports.geometry.rhino import Rhino
from hub.imports.geometry.gpandas import GPandas from hub.imports.geometry.gpandas import GPandas
from hub.imports.geometry.geojson import Geojson from hub.imports.geometry.geojson import Geojson
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
class GeometryFactory: class GeometryFactory:
@ -26,6 +28,11 @@ class GeometryFactory:
year_of_construction_field=None, year_of_construction_field=None,
function_field=None): function_field=None):
self._file_type = '_' + file_type.lower() 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._path = path
self._data_frame = data_frame self._data_frame = data_frame
self._height_field = height_field self._height_field = height_field

View File

@ -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_vehicle import LcaVehicle
from hub.imports.life_cycle_assessment.lca_machine import LcaMachine from hub.imports.life_cycle_assessment.lca_machine import LcaMachine
from hub.imports.life_cycle_assessment.lca_material import LcaMaterial 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: class LifeCycleAssessment:
@ -20,6 +22,11 @@ class LifeCycleAssessment:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/life_cycle_assessment') base_path = Path(Path(__file__).parent.parent / 'data/life_cycle_assessment')
self._handler = '_' + handler.lower().replace(' ', '_') 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._city = city
self._base_path = base_path self._base_path = base_path

View File

@ -6,6 +6,8 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
from pathlib import Path from pathlib import Path
from hub.hub_logger import logger
from hub.helpers.utils import validate_import_export_type
class SensorsFactory: class SensorsFactory:
@ -16,6 +18,11 @@ class SensorsFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/sensors') base_path = Path(Path(__file__).parent.parent / 'data/sensors')
self._handler = '_' + handler.lower().replace(' ', '_') 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._city = city
self._end_point = end_point self._end_point = end_point
self._base_path = base_path self._base_path = base_path

View File

@ -9,6 +9,8 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
from pathlib import Path from pathlib import Path
from hub.imports.usage.comnet_usage_parameters import ComnetUsageParameters from hub.imports.usage.comnet_usage_parameters import ComnetUsageParameters
from hub.imports.usage.nrcan_usage_parameters import NrcanUsageParameters from hub.imports.usage.nrcan_usage_parameters import NrcanUsageParameters
from hub.hub_logger import logger
from hub.helpers.utils import validate_import_export_type
class UsageFactory: class UsageFactory:
@ -19,6 +21,11 @@ class UsageFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/usage') base_path = Path(Path(__file__).parent.parent / 'data/usage')
self._handler = '_' + handler.lower().replace(' ', '_') 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._city = city
self._base_path = base_path self._base_path = base_path

View File

@ -7,6 +7,8 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
from pathlib import Path from pathlib import Path
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters 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: class WeatherFactory:
@ -18,6 +20,11 @@ class WeatherFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/weather') base_path = Path(Path(__file__).parent.parent / 'data/weather')
self._handler = '_' + handler.lower().replace(' ', '_') 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._city = city
self._base_path = base_path self._base_path = base_path
self._file_name = file_name self._file_name = file_name