remove warnings for opened files and remove code duplication

This commit is contained in:
Guille Gutierrez 2023-05-19 16:01:06 -04:00
parent a0335795de
commit 182d01123c
23 changed files with 134 additions and 185 deletions

View File

@ -15,15 +15,11 @@ Catalog = TypeVar('Catalog')
class ConstructionCatalogFactory: class ConstructionCatalogFactory:
def __init__(self, file_type, base_path=None): def __init__(self, handler, base_path=None):
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._handler = '_' + handler.lower()
class_funcs = validate_import_export_type(ConstructionCatalogFactory) validate_import_export_type(ConstructionCatalogFactory, handler)
if self._catalog_type not in class_funcs:
err_msg = f"Wrong import type. Valid functions include {class_funcs}"
logging.error(err_msg)
raise Exception(err_msg)
self._path = base_path self._path = base_path
@property @property
@ -46,4 +42,4 @@ class ConstructionCatalogFactory:
Enrich the city given to the class using the class given handler Enrich the city given to the class using the class given handler
:return: Catalog :return: Catalog
""" """
return getattr(self, self._catalog_type, lambda: None) return getattr(self, self._handler, lambda: None)

View File

@ -14,15 +14,11 @@ Catalog = TypeVar('Catalog')
class EnergySystemsCatalogFactory: class EnergySystemsCatalogFactory:
def __init__(self, file_type, base_path=None): def __init__(self, handler, base_path=None):
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._catalog_type = '_' + file_type.lower() self._handler = '_' + handler.lower()
class_funcs = validate_import_export_type(EnergySystemsCatalogFactory) validate_import_export_type(EnergySystemsCatalogFactory, handler)
if self._catalog_type not in class_funcs:
error_message = f'Wrong import type. Valid functions include {class_funcs}'
logging.error(error_message)
raise Exception(error_message)
self._path = base_path self._path = base_path
@property @property
@ -38,4 +34,4 @@ class EnergySystemsCatalogFactory:
Enrich the city given to the class using the class given handler Enrich the city given to the class using the class given handler
:return: Catalog :return: Catalog
""" """
return getattr(self, self._catalog_type, lambda: None) return getattr(self, self._handler, lambda: None)

View File

@ -17,15 +17,11 @@ class GreeneryCatalogFactory:
""" """
GreeneryCatalogFactory class GreeneryCatalogFactory class
""" """
def __init__(self, file_type, base_path=None): def __init__(self, handler, base_path=None):
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._handler = '_' + handler.lower()
class_funcs = validate_import_export_type(GreeneryCatalogFactory) class_funcs = validate_import_export_type(GreeneryCatalogFactory, handler)
if self._catalog_type not in class_funcs:
error_message = f'Wrong import type. Valid functions include {class_funcs}'
logging.error(error_message)
raise Exception(error_message)
self._path = base_path self._path = base_path
@property @property
@ -42,4 +38,4 @@ class GreeneryCatalogFactory:
Enrich the city given to the class using the class given handler Enrich the city given to the class using the class given handler
:return: Catalog :return: Catalog
""" """
return getattr(self, self._catalog_type, lambda: None) return getattr(self, self._handler, lambda: None)

View File

@ -4,6 +4,7 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
""" """
import io
from typing import Dict from typing import Dict
import pandas as pd import pandas as pd
@ -129,8 +130,9 @@ class ComnetCatalog(Catalog):
for usage_name in comnet_usages: for usage_name in comnet_usages:
if usage_name == 'C-13 Data Center': if usage_name == 'C-13 Data Center':
continue continue
with open(self._comnet_schedules_path, 'rb') as xls:
_extracted_data = pd.read_excel( _extracted_data = pd.read_excel(
self._comnet_schedules_path, io.BytesIO(xls.read()),
sheet_name=comnet_usages[usage_name], sheet_name=comnet_usages[usage_name],
skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA" skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA"
) )
@ -169,9 +171,10 @@ class ComnetCatalog(Catalog):
:return : Dict :return : Dict
""" """
number_usage_types = 33 number_usage_types = 33
xl_file = pd.ExcelFile(self._comnet_archetypes_path) with open(self._comnet_archetypes_path, 'rb') as xls:
file_data = pd.read_excel( _extracted_data = pd.read_excel(
xl_file, sheet_name="Modeling Data", io.BytesIO(xls.read()),
sheet_name="Modeling Data",
skiprows=[0, 1, 2, 24], skiprows=[0, 1, 2, 24],
nrows=number_usage_types, usecols="A:AB" nrows=number_usage_types, usecols="A:AB"
) )
@ -184,7 +187,7 @@ class ComnetCatalog(Catalog):
process_data = {} process_data = {}
schedules_key = {} schedules_key = {}
for j in range(0, number_usage_types-1): for j in range(0, number_usage_types-1):
usage_parameters = file_data.iloc[j] usage_parameters = _extracted_data.iloc[j]
usage_type = usage_parameters[0] usage_type = usage_parameters[0]
lighting_data[usage_type] = usage_parameters[1:6].values.tolist() lighting_data[usage_type] = usage_parameters[1:6].values.tolist()
plug_loads_data[usage_type] = usage_parameters[8:13].values.tolist() plug_loads_data[usage_type] = usage_parameters[8:13].values.tolist()

View File

@ -15,15 +15,11 @@ Catalog = TypeVar('Catalog')
class UsageCatalogFactory: class UsageCatalogFactory:
def __init__(self, file_type, base_path=None): def __init__(self, handler, base_path=None):
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 = '_' + handler.lower()
class_funcs = validate_import_export_type(UsageCatalogFactory) validate_import_export_type(UsageCatalogFactory, handler)
if self._catalog_type not in class_funcs:
error_message = f"Wrong import type. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
self._path = base_path self._path = base_path
@property @property

View File

@ -17,14 +17,10 @@ class EnergyBuildingsExportsFactory:
""" """
Energy Buildings exports factory class Energy Buildings exports factory class
""" """
def __init__(self, export_type, city, path, target_buildings=None): def __init__(self, handler, city, path, target_buildings=None):
self._city = city self._city = city
self._export_type = '_' + export_type.lower() self._export_type = '_' + handler.lower()
class_funcs = validate_import_export_type(EnergyBuildingsExportsFactory) validate_import_export_type(EnergyBuildingsExportsFactory, handler)
if self._export_type not in class_funcs:
error_message = f"Wrong import type [{self._export_type}]. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
if isinstance(path, str): if isinstance(path, str):
path = Path(path) path = Path(path)
self._path = path self._path = path

View File

@ -15,12 +15,11 @@ class EnergySystemsExportFactory:
Exports factory class for energy systems Exports factory class for energy systems
""" """
def __init__(self, city, user_input, hp_model, output_path, sim_type=0, data_type='heat', base_path=None, def __init__(self, city, handler, hp_model, output_path, sim_type=0, data_type='heat', base_path=None,
demand_path=None): demand_path=None):
""" """
:param city: the city object :param city: the city object
:param user_input: user provided input from UI :param handler: user provided input from UI
:param hp_model: the heat pump model to run :param hp_model: the heat pump model to run
:param output_path: the file to hold simulation results :param output_path: the file to hold simulation results
:param sim_type: the simulation type, 0 for series 1 for parallel :param sim_type: the simulation type, 0 for series 1 for parallel
@ -33,7 +32,7 @@ class EnergySystemsExportFactory:
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._base_path = base_path self._base_path = base_path
self._user_input = user_input self._handler = handler
self._hp_model = hp_model self._hp_model = hp_model
self._data_type = data_type self._data_type = data_type
self._output_path = output_path self._output_path = output_path
@ -49,10 +48,10 @@ class EnergySystemsExportFactory:
""" """
if self._source == 'air': if self._source == 'air':
return AirSourceHPExport(self._base_path, self._city, self._output_path, self._sim_type, self._demand_path)\ return AirSourceHPExport(self._base_path, self._city, self._output_path, self._sim_type, self._demand_path)\
.execute_insel(self._user_input, self._hp_model, self._data_type) .execute_insel(self._handler, self._hp_model, self._data_type)
elif self._source == 'water': elif self._source == 'water':
return WaterToWaterHPExport(self._base_path, self._city, self._output_path, self._sim_type, self._demand_path)\ return WaterToWaterHPExport(self._base_path, self._city, self._output_path, self._sim_type, self._demand_path)\
.execute_insel(self._user_input, self._hp_model) .execute_insel(self._handler, self._hp_model)
def export(self, source='air'): def export(self, source='air'):
""" """

View File

@ -17,18 +17,14 @@ class ExportsFactory:
""" """
Exports factory class Exports factory class
""" """
def __init__(self, export_type, city, path, def __init__(self, handler, city, path,
target_buildings=None, target_buildings=None,
adjacent_buildings=None, adjacent_buildings=None,
weather_file=None, weather_file=None,
weather_format=None): weather_format=None):
self._city = city self._city = city
self._export_type = '_' + export_type.lower() self._handler = '_' + handler.lower()
class_funcs = validate_import_export_type(ExportsFactory) validate_import_export_type(ExportsFactory, handler)
if self._export_type not in class_funcs:
error_message = f"Wrong export type [{self._export_type}]. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
if isinstance(path, str): if isinstance(path, str):
path = Path(path) path = Path(path)
self._path = path self._path = path
@ -82,11 +78,4 @@ class ExportsFactory:
Export the city given to the class using the given export type handler Export the city given to the class using the given export type handler
:return: None :return: None
""" """
return getattr(self, self._export_type, lambda: None) return getattr(self, self._handler, lambda: None)
def export_debug(self):
"""
Export the city given to the class using the given export type handler
:return: None
"""
return Obj(self._city, self._path)

View File

@ -4,15 +4,19 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Concordia CERC group Copyright © 2023 Concordia CERC group
Project Coder Peter Yefi peteryefi@gmail.com Project Coder Peter Yefi peteryefi@gmail.com
""" """
import logging
def validate_import_export_type(cls_name: type): def validate_import_export_type(cls_name: type, handler: str):
""" """
Retrieves all the function names in a class which are property types (decoration) Retrieves all the function names in a class which are property types (decoration)
and normal functions and normal functions
:param cls_name: the class name :param cls_name: the class name
:return: [str], a list of functions in the class :param handler: import export handler
:return: None
""" """
return [func for func in dir(cls_name) functions = [function[1:] for function in dir(cls_name) if (type(getattr(cls_name, function)) is property or callable(getattr(cls_name, function))) and function in cls_name.__dict__ and function[0] == '_' and function != '__init__']
if (type(getattr(cls_name, func)) is property or callable(getattr(cls_name, func))) if handler.lower() not in functions:
and func in cls_name.__dict__ and func[0] == '_' and func != '__init__'] error_message = f'Wrong import type [{handler}]. Valid functions include {functions}'
logging.error(error_message)
raise Exception(error_message)

View File

@ -6,10 +6,9 @@ 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
""" """
import logging
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
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
from hub.imports.construction.nrel_physics_parameters import NrelPhysicsParameters
class ConstructionFactory: class ConstructionFactory:
@ -17,12 +16,8 @@ class ConstructionFactory:
ConstructionFactory class ConstructionFactory class
""" """
def __init__(self, handler, city): def __init__(self, handler, city):
self._handler = '_' + handler.lower().replace(' ', '_') self._handler = '_' + handler.lower()
class_funcs = validate_import_export_type(ConstructionFactory) validate_import_export_type(ConstructionFactory, handler)
if self._handler not in class_funcs:
error_message = f"Wrong import type [{self._handler}]. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
self._city = city self._city = city
def _nrel(self): def _nrel(self):
@ -49,10 +44,3 @@ class ConstructionFactory:
:return: None :return: None
""" """
getattr(self, self._handler, lambda: None)() getattr(self, self._handler, lambda: None)()
def enrich_debug(self):
"""
Enrich the city given to the class using the class given handler
:return: None
"""
NrelPhysicsParameters(self._city).enrich_buildings()

View File

@ -5,6 +5,7 @@ Copyright © 2022 Concordia CERC group
Project Coder Peter Yefi peteryefi@gmail.comCode Project Coder Peter Yefi peteryefi@gmail.comCode
contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import io
import pandas as pd import pandas as pd
from typing import Dict from typing import Dict
@ -31,22 +32,19 @@ class AirSourceHeatPumpParameters:
into a dictionary into a dictionary
:return : Dict :return : Dict
""" """
xl_file = pd.ExcelFile(self._base_path) with open(self._base_path, 'rb') as xls:
xl_file = pd.read_excel(io.BytesIO(xls.read()), sheet_name=None)
heat_pump_dfs = {sheet_name: xl_file.parse(sheet_name)
for sheet_name in xl_file.sheet_names}
cooling_data = {} cooling_data = {}
heating_data = {} heating_data = {}
for sheet, dataframe in heat_pump_dfs.items(): for sheet, dataframe in xl_file.items():
if 'Summary' in sheet: if 'Summary' in sheet:
continue continue
# Remove nan rows and columns and extract cooling and heating data # Remove nan rows and columns and extract cooling and heating data
# for each sheet # for each sheet
df = heat_pump_dfs[sheet].dropna(axis=1, how='all') df = xl_file[sheet].dropna(axis=1, how='all')
cooling_df = df.iloc[4:34, 0:8] cooling_df = df.iloc[4:34, 0:8]
heating_df = df.iloc[4:29, 8:20] heating_df = df.iloc[4:29, 8:20]

View File

@ -4,6 +4,7 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group Copyright © 2022 Concordia CERC group
Project Coder Peter Yefi peteryefi@gmail.com Project Coder Peter Yefi peteryefi@gmail.com
""" """
import io
import pandas as pd import pandas as pd
from typing import Dict from typing import Dict
@ -28,6 +29,20 @@ class WaterToWaterHPParameters:
reads xlsx file containing water to water heat pump information reads xlsx file containing water to water heat pump information
into a dictionary into a dictionary
:return : Dict :return : Dict
with open(self._base_path, 'rb') as xls:
xl_file = pd.read_excel(io.BytesIO(xls.read()))
hp_data = {}
flow_rates = {
'156': [2.84, 4.23, 5.68],
'256': [4.73, 7.13, 9.446],
'335': [6.62, 9.97, 12.93],
}
for sheet, dataframe in xl_file.items():
print(sheet, xl_file[sheet])
df = dataframe[xl_file[sheet].columns[1]]
""" """
xl_file = pd.ExcelFile(self._base_path) xl_file = pd.ExcelFile(self._base_path)
heat_pump_dfs = {sheet_name: xl_file.parse(sheet_name) heat_pump_dfs = {sheet_name: xl_file.parse(sheet_name)
@ -43,6 +58,7 @@ class WaterToWaterHPParameters:
for sheet, dataframe in heat_pump_dfs.items(): for sheet, dataframe in heat_pump_dfs.items():
df = heat_pump_dfs[sheet].dropna(axis=1, how='all') df = heat_pump_dfs[sheet].dropna(axis=1, how='all')
print(df)
df = df.iloc[3:, 6:35] df = df.iloc[3:, 6:35]
if '156' in sheet: if '156' in sheet:

View File

@ -5,12 +5,12 @@ Copyright © 2022 Concordia CERC group
Project Coder Pilar Monsalvete pilar.monsalvete@concordi. Project Coder Pilar Monsalvete pilar.monsalvete@concordi.
Code contributors: Peter Yefi peteryefi@gmail.com Code contributors: Peter Yefi peteryefi@gmail.com
""" """
import logging
from pathlib import Path 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.helpers.utils import validate_import_export_type
from hub.imports.energy_systems.air_source_hp_parameters import AirSourceHeatPumpParameters
from hub.imports.energy_systems.montreal_custom_energy_system_parameters import MontrealCustomEnergySystemParameters from hub.imports.energy_systems.montreal_custom_energy_system_parameters import MontrealCustomEnergySystemParameters
from hub.imports.energy_systems.water_to_water_hp_parameters import WaterToWaterHPParameters
class EnergySystemsFactory: class EnergySystemsFactory:
@ -21,12 +21,8 @@ class EnergySystemsFactory:
def __init__(self, handler, city, base_path=None): def __init__(self, handler, city, base_path=None):
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()
class_funcs = validate_import_export_type(EnergySystemsFactory) validate_import_export_type(EnergySystemsFactory, handler)
if self._handler not in class_funcs:
error_message = f"Wrong import type. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
self._city = city self._city = city
self._base_path = base_path self._base_path = base_path

View File

@ -4,16 +4,15 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
""" """
import logging
import geopandas import geopandas
from hub.city_model_structure.city import City from hub.city_model_structure.city import City
from hub.helpers.utils import validate_import_export_type
from hub.imports.geometry.citygml import CityGml from hub.imports.geometry.citygml import CityGml
from hub.imports.geometry.geojson import Geojson
from hub.imports.geometry.gpandas import GPandas
from hub.imports.geometry.obj import Obj from hub.imports.geometry.obj import Obj
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.geojson import Geojson
from hub.helpers.utils import validate_import_export_type
class GeometryFactory: class GeometryFactory:
@ -29,11 +28,7 @@ class GeometryFactory:
function_field=None, function_field=None,
function_to_hub=None): function_to_hub=None):
self._file_type = '_' + file_type.lower() self._file_type = '_' + file_type.lower()
class_funcs = validate_import_export_type(GeometryFactory) validate_import_export_type(GeometryFactory, file_type)
if self._file_type not in class_funcs:
error_message = f"Wrong import type. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
self._path = path self._path = path
self._data_frame = data_frame self._data_frame = data_frame
self._name_field = name_field self._name_field = name_field

View File

@ -5,13 +5,12 @@ Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca 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
""" """
import logging
from pathlib import Path from pathlib import Path
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
from hub.imports.results.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from hub.imports.results.insel_monthly_energry_balance import InselMonthlyEnergyBalance
from hub.imports.results.insel_heatpump_energy_demand import InselHeatPumpEnergyDemand from hub.imports.results.insel_heatpump_energy_demand import InselHeatPumpEnergyDemand
from hub.imports.results.insel_monthly_energry_balance import InselMonthlyEnergyBalance
from hub.imports.results.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
class ResultFactory: class ResultFactory:
@ -31,11 +30,7 @@ class ResultFactory:
if base_path is None: if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/results') base_path = Path(Path(__file__).parent.parent / 'data/results')
self._handler = '_' + handler.lower().replace(' ', '_') self._handler = '_' + handler.lower().replace(' ', '_')
class_funcs = validate_import_export_type(ResultFactory) validate_import_export_type(ResultFactory, handler)
if self._handler not in class_funcs:
error_message = f"Wrong import type [{self._handler}]. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
self._city = city self._city = city
self._base_path = base_path self._base_path = base_path
self._hp_model = hp_model self._hp_model = hp_model

View File

@ -6,10 +6,9 @@ Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca 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
""" """
import logging from hub.helpers.utils import validate_import_export_type
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.helpers.utils import validate_import_export_type
class UsageFactory: class UsageFactory:
@ -17,12 +16,8 @@ class UsageFactory:
UsageFactory class UsageFactory class
""" """
def __init__(self, handler, city): def __init__(self, handler, city):
self._handler = '_' + handler.lower().replace(' ', '_') self._handler = '_' + handler.lower()
class_funcs = validate_import_export_type(UsageFactory) validate_import_export_type(UsageFactory, handler)
if self._handler not in class_funcs:
error_message = f"Wrong import type [{self._handler}]. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
self._city = city self._city = city
def _comnet(self): def _comnet(self):

View File

@ -4,11 +4,11 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group Copyright © 2022 Concordia CERC group
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import logging
from pathlib import Path from pathlib import Path
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
class WeatherFactory: class WeatherFactory:
@ -20,11 +20,7 @@ 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) validate_import_export_type(WeatherFactory, handler)
if self._handler not in class_funcs:
error_message = f"Wrong import type. Valid functions include {class_funcs}"
logging.error(error_message)
raise Exception(error_message)
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

View File

@ -1,4 +1,3 @@
""" """
Persistence package Persistence package
""" """

View File

@ -28,9 +28,6 @@ class DBControl:
self._city_object = CityObject(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path) self._city_object = CityObject(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path)
self._simulation_results = SimulationResults(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env) self._simulation_results = SimulationResults(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env)
@property
def identity(self):
return self._identity
def application_info(self, application_uuid) -> Application: def application_info(self, application_uuid) -> Application:
""" """
Retrieve the application info for the given uuid Retrieve the application info for the given uuid
@ -120,7 +117,6 @@ class DBControl:
return identity_id return identity_id
""" """
self._city_repository.insert(city, pickle_path, application_id, user_id) self._city_repository.insert(city, pickle_path, application_id, user_id)
return
def update_city(self, city_id, city): def update_city(self, city_id, city):
""" """

View File

@ -49,7 +49,7 @@ class TestCityMerge(TestCase):
city_two.name = 'New_York' city_two.name = 'New_York'
city_two.climate_file = self._climate_file city_two.climate_file = self._climate_file
try: try:
ExportsFactory(export_type='sra', city=city_two, path=self._output_path, weather_file=self._weather_file, ExportsFactory(handler='sra', city=city_two, path=self._output_path, weather_file=self._weather_file,
target_buildings=city_two.buildings, weather_format='epw').export() target_buildings=city_two.buildings, weather_format='epw').export()
subprocess.run([self._executable, f'{str(self._output_path)}/{city_two.name}_sra.xml'], stdout=subprocess.DEVNULL) subprocess.run([self._executable, f'{str(self._output_path)}/{city_two.name}_sra.xml'], stdout=subprocess.DEVNULL)
except (SubprocessError, TimeoutExpired, CalledProcessError) as error: except (SubprocessError, TimeoutExpired, CalledProcessError) as error:

View File

@ -41,7 +41,7 @@ class TestEnergySystemsFactory(TestCase):
city_file = "tests_data/C40_Final.gml" city_file = "tests_data/C40_Final.gml"
self._output_path = "tests_data/as_user_output.csv" self._output_path = "tests_data/as_user_output.csv"
self._city = GeometryFactory('citygml', path=city_file).city self._city = GeometryFactory('citygml', path=city_file).city
EnergySystemsFactory('air source hp', self._city).enrich() EnergySystemsFactory('air_source_hp', self._city).enrich()
def test_air_source_heat_pump_import(self): def test_air_source_heat_pump_import(self):
self.assertIsNotNone(self._city.energy_systems, 'City has energy systems') self.assertIsNotNone(self._city.energy_systems, 'City has energy systems')
@ -50,14 +50,14 @@ class TestEnergySystemsFactory(TestCase):
self.assertEqual(self._city.energy_systems[16].air_source_hp.model, '140') self.assertEqual(self._city.energy_systems[16].air_source_hp.model, '140')
def test_air_source_series_heat_pump_export(self): def test_air_source_series_heat_pump_export(self):
EnergySystemsExportFactory(city=self._city, user_input=user_input, hp_model='012', EnergySystemsExportFactory(city=self._city, handler=user_input, hp_model='012',
output_path=self._output_path).export() output_path=self._output_path).export()
df = pd.read_csv(self._output_path) df = pd.read_csv(self._output_path)
self.assertEqual(df.shape, (13, 3)) self.assertEqual(df.shape, (13, 3))
self.assertEqual(df.iloc[0, 1], 1867715.88) self.assertEqual(df.iloc[0, 1], 1867715.88)
def test_air_source_parallel_heat_pump_export(self): def test_air_source_parallel_heat_pump_export(self):
output = EnergySystemsExportFactory(city=self._city, user_input=user_input, hp_model='018', output = EnergySystemsExportFactory(city=self._city, handler=user_input, hp_model='018',
output_path=None, sim_type=1).export() output_path=None, sim_type=1).export()
self.assertEqual(output["hourly_electricity_demand"][0], 38748.5625) self.assertEqual(output["hourly_electricity_demand"][0], 38748.5625)
self.assertIsNotNone(output["daily_fossil_consumption"]) self.assertIsNotNone(output["daily_fossil_consumption"])

View File

@ -27,7 +27,7 @@ class TestEnergySystemsFactory(TestCase):
city_file = "tests_data/C40_Final.gml" city_file = "tests_data/C40_Final.gml"
self._output_path = "tests_data/w2w_user_output.csv" self._output_path = "tests_data/w2w_user_output.csv"
self._city = GeometryFactory('citygml', path=city_file).city self._city = GeometryFactory('citygml', path=city_file).city
EnergySystemsFactory('water to water hp', self._city).enrich() EnergySystemsFactory('water_to_water_hp', self._city).enrich()
def test_water_to_water_heat_pump_import(self): def test_water_to_water_heat_pump_import(self):
self.assertIsNotNone(self._city.energy_systems, 'City has energy systems') self.assertIsNotNone(self._city.energy_systems, 'City has energy systems')
@ -62,7 +62,7 @@ class TestEnergySystemsFactory(TestCase):
'b11': 10 'b11': 10
} }
EnergySystemsExportFactory(city=self._city, user_input=user_input, hp_model='ClimateMaster 256 kW', EnergySystemsExportFactory(city=self._city, handler=user_input, hp_model='ClimateMaster 256 kW',
output_path=self._output_path, sim_type=1).export('water') output_path=self._output_path, sim_type=1).export('water')
df = pd.read_csv(self._output_path) df = pd.read_csv(self._output_path)
self.assertEqual(df.shape, (13, 3)) self.assertEqual(df.shape, (13, 3))

View File

@ -41,12 +41,12 @@ class TestHeatPumpResults(TestCase):
city_file = "tests_data/C40_Final.gml" city_file = "tests_data/C40_Final.gml"
self._output_path = "tests_data/as_user_output.csv" self._output_path = "tests_data/as_user_output.csv"
self._city = GeometryFactory('citygml', path=city_file).city self._city = GeometryFactory('citygml', path=city_file).city
EnergySystemsFactory('air source hp', self._city).enrich() EnergySystemsFactory('air_source_hp', self._city).enrich()
def test_air_source_series_heat_pump_012_results(self): def test_air_source_series_heat_pump_012_results(self):
EnergySystemsExportFactory(city=self._city, user_input=user_input, hp_model='012', EnergySystemsExportFactory(city=self._city, handler=user_input, hp_model='012',
output_path=self._output_path).export() output_path=self._output_path).export()
ResultFactory('heat pump', self._city, self._output_path, '012').enrich() ResultFactory('heat_pump', self._city, self._output_path, '012').enrich()
for energy_system in self._city.energy_systems: for energy_system in self._city.energy_systems:
self.assertIsNone(energy_system.water_to_water_hp) self.assertIsNone(energy_system.water_to_water_hp)
@ -56,9 +56,9 @@ class TestHeatPumpResults(TestCase):
self.assertEqual(energy_system.air_source_hp.hp_monthly_fossil_consumption.iloc[12], 35.853598782915) self.assertEqual(energy_system.air_source_hp.hp_monthly_fossil_consumption.iloc[12], 35.853598782915)
def test_air_source_series_heat_pump_015_results(self): def test_air_source_series_heat_pump_015_results(self):
EnergySystemsExportFactory(city=self._city, user_input=user_input, hp_model='140', EnergySystemsExportFactory(city=self._city, handler=user_input, hp_model='140',
output_path=self._output_path).export() output_path=self._output_path).export()
ResultFactory('heat pump', self._city, self._output_path, '140').enrich() ResultFactory('heat_pump', self._city, self._output_path, '140').enrich()
for energy_system in self._city.energy_systems: for energy_system in self._city.energy_systems:
self.assertIsNone(energy_system.water_to_water_hp) self.assertIsNone(energy_system.water_to_water_hp)