Included checks for import handlers and types
This commit is contained in:
parent
ec9878eaf8
commit
d04906306e
8
hub/.gitignore
vendored
8
hub/.gitignore
vendored
|
@ -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/
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
18
hub/helpers/utils.py
Normal file
18
hub/helpers/utils.py
Normal 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__']
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user