forked from s_ranjbar/city_retrofit
remove warnings for opened files and remove code duplication
This commit is contained in:
parent
a0335795de
commit
182d01123c
|
@ -15,15 +15,11 @@ Catalog = TypeVar('Catalog')
|
|||
|
||||
|
||||
class ConstructionCatalogFactory:
|
||||
def __init__(self, file_type, base_path=None):
|
||||
def __init__(self, handler, base_path=None):
|
||||
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}"
|
||||
logging.error(err_msg)
|
||||
raise Exception(err_msg)
|
||||
self._handler = '_' + handler.lower()
|
||||
validate_import_export_type(ConstructionCatalogFactory, handler)
|
||||
self._path = base_path
|
||||
|
||||
@property
|
||||
|
@ -46,4 +42,4 @@ class ConstructionCatalogFactory:
|
|||
Enrich the city given to the class using the class given handler
|
||||
:return: Catalog
|
||||
"""
|
||||
return getattr(self, self._catalog_type, lambda: None)
|
||||
return getattr(self, self._handler, lambda: None)
|
||||
|
|
|
@ -14,15 +14,11 @@ Catalog = TypeVar('Catalog')
|
|||
|
||||
|
||||
class EnergySystemsCatalogFactory:
|
||||
def __init__(self, file_type, base_path=None):
|
||||
def __init__(self, handler, base_path=None):
|
||||
if base_path is None:
|
||||
base_path = Path(Path(__file__).parent.parent / 'data/energy_systems')
|
||||
self._catalog_type = '_' + file_type.lower()
|
||||
class_funcs = validate_import_export_type(EnergySystemsCatalogFactory)
|
||||
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._handler = '_' + handler.lower()
|
||||
validate_import_export_type(EnergySystemsCatalogFactory, handler)
|
||||
self._path = base_path
|
||||
|
||||
@property
|
||||
|
@ -38,4 +34,4 @@ class EnergySystemsCatalogFactory:
|
|||
Enrich the city given to the class using the class given handler
|
||||
:return: Catalog
|
||||
"""
|
||||
return getattr(self, self._catalog_type, lambda: None)
|
||||
return getattr(self, self._handler, lambda: None)
|
||||
|
|
|
@ -17,15 +17,11 @@ class GreeneryCatalogFactory:
|
|||
"""
|
||||
GreeneryCatalogFactory class
|
||||
"""
|
||||
def __init__(self, file_type, base_path=None):
|
||||
def __init__(self, handler, base_path=None):
|
||||
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:
|
||||
error_message = f'Wrong import type. Valid functions include {class_funcs}'
|
||||
logging.error(error_message)
|
||||
raise Exception(error_message)
|
||||
self._handler = '_' + handler.lower()
|
||||
class_funcs = validate_import_export_type(GreeneryCatalogFactory, handler)
|
||||
self._path = base_path
|
||||
|
||||
@property
|
||||
|
@ -42,4 +38,4 @@ class GreeneryCatalogFactory:
|
|||
Enrich the city given to the class using the class given handler
|
||||
:return: Catalog
|
||||
"""
|
||||
return getattr(self, self._catalog_type, lambda: None)
|
||||
return getattr(self, self._handler, lambda: None)
|
||||
|
|
|
@ -4,6 +4,7 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2022 Concordia CERC group
|
||||
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
"""
|
||||
import io
|
||||
from typing import Dict
|
||||
|
||||
import pandas as pd
|
||||
|
@ -129,38 +130,39 @@ class ComnetCatalog(Catalog):
|
|||
for usage_name in comnet_usages:
|
||||
if usage_name == 'C-13 Data Center':
|
||||
continue
|
||||
_extracted_data = pd.read_excel(
|
||||
self._comnet_schedules_path,
|
||||
sheet_name=comnet_usages[usage_name],
|
||||
skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA"
|
||||
)
|
||||
_schedules = {}
|
||||
for row in range(0, 39, 3):
|
||||
_schedule_values = {}
|
||||
schedule_name = _extracted_data.loc[row:row, 'Description'].item()
|
||||
schedule_data_type = comnet_data_types[_extracted_data.loc[row:row, 'Type'].item()]
|
||||
for day in comnet_days:
|
||||
# Monday to Friday
|
||||
start = row
|
||||
end = row + 1
|
||||
if day == cte.SATURDAY:
|
||||
start = start + 1
|
||||
end = end + 1
|
||||
elif day == cte.SUNDAY or day == cte.HOLIDAY:
|
||||
start = start + 2
|
||||
end = end + 2
|
||||
_schedule_values[day] = _extracted_data.iloc[start:end, 3:27].to_numpy().tolist()[0]
|
||||
_schedule = []
|
||||
for day in _schedule_values:
|
||||
if schedule_name == 'ClgSetPt' or schedule_name == 'HtgSetPt' or schedule_name == 'WtrHtrSetPt':
|
||||
# to celsius
|
||||
if 'n.a.' in _schedule_values[day]:
|
||||
_schedule_values[day] = None
|
||||
else:
|
||||
_schedule_values[day] = [(float(value)-32)*5/9 for value in _schedule_values[day]]
|
||||
_schedule.append(Schedule(schedule_name, _schedule_values[day], schedule_data_type, cte.HOUR, cte.DAY, [day]))
|
||||
_schedules[schedule_name] = _schedule
|
||||
dictionary[usage_name] = _schedules
|
||||
with open(self._comnet_schedules_path, 'rb') as xls:
|
||||
_extracted_data = pd.read_excel(
|
||||
io.BytesIO(xls.read()),
|
||||
sheet_name=comnet_usages[usage_name],
|
||||
skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA"
|
||||
)
|
||||
_schedules = {}
|
||||
for row in range(0, 39, 3):
|
||||
_schedule_values = {}
|
||||
schedule_name = _extracted_data.loc[row:row, 'Description'].item()
|
||||
schedule_data_type = comnet_data_types[_extracted_data.loc[row:row, 'Type'].item()]
|
||||
for day in comnet_days:
|
||||
# Monday to Friday
|
||||
start = row
|
||||
end = row + 1
|
||||
if day == cte.SATURDAY:
|
||||
start = start + 1
|
||||
end = end + 1
|
||||
elif day == cte.SUNDAY or day == cte.HOLIDAY:
|
||||
start = start + 2
|
||||
end = end + 2
|
||||
_schedule_values[day] = _extracted_data.iloc[start:end, 3:27].to_numpy().tolist()[0]
|
||||
_schedule = []
|
||||
for day in _schedule_values:
|
||||
if schedule_name == 'ClgSetPt' or schedule_name == 'HtgSetPt' or schedule_name == 'WtrHtrSetPt':
|
||||
# to celsius
|
||||
if 'n.a.' in _schedule_values[day]:
|
||||
_schedule_values[day] = None
|
||||
else:
|
||||
_schedule_values[day] = [(float(value)-32)*5/9 for value in _schedule_values[day]]
|
||||
_schedule.append(Schedule(schedule_name, _schedule_values[day], schedule_data_type, cte.HOUR, cte.DAY, [day]))
|
||||
_schedules[schedule_name] = _schedule
|
||||
dictionary[usage_name] = _schedules
|
||||
return dictionary
|
||||
|
||||
def _read_archetype_file(self) -> Dict:
|
||||
|
@ -169,12 +171,13 @@ class ComnetCatalog(Catalog):
|
|||
:return : Dict
|
||||
"""
|
||||
number_usage_types = 33
|
||||
xl_file = pd.ExcelFile(self._comnet_archetypes_path)
|
||||
file_data = pd.read_excel(
|
||||
xl_file, sheet_name="Modeling Data",
|
||||
skiprows=[0, 1, 2, 24],
|
||||
nrows=number_usage_types, usecols="A:AB"
|
||||
)
|
||||
with open(self._comnet_archetypes_path, 'rb') as xls:
|
||||
_extracted_data = pd.read_excel(
|
||||
io.BytesIO(xls.read()),
|
||||
sheet_name="Modeling Data",
|
||||
skiprows=[0, 1, 2, 24],
|
||||
nrows=number_usage_types, usecols="A:AB"
|
||||
)
|
||||
|
||||
lighting_data = {}
|
||||
plug_loads_data = {}
|
||||
|
@ -184,7 +187,7 @@ class ComnetCatalog(Catalog):
|
|||
process_data = {}
|
||||
schedules_key = {}
|
||||
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]
|
||||
lighting_data[usage_type] = usage_parameters[1:6].values.tolist()
|
||||
plug_loads_data[usage_type] = usage_parameters[8:13].values.tolist()
|
||||
|
|
|
@ -15,15 +15,11 @@ Catalog = TypeVar('Catalog')
|
|||
|
||||
|
||||
class UsageCatalogFactory:
|
||||
def __init__(self, file_type, base_path=None):
|
||||
def __init__(self, handler, base_path=None):
|
||||
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:
|
||||
error_message = f"Wrong import type. Valid functions include {class_funcs}"
|
||||
logging.error(error_message)
|
||||
raise Exception(error_message)
|
||||
self._catalog_type = '_' + handler.lower()
|
||||
validate_import_export_type(UsageCatalogFactory, handler)
|
||||
self._path = base_path
|
||||
|
||||
@property
|
||||
|
|
|
@ -17,14 +17,10 @@ class EnergyBuildingsExportsFactory:
|
|||
"""
|
||||
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._export_type = '_' + export_type.lower()
|
||||
class_funcs = validate_import_export_type(EnergyBuildingsExportsFactory)
|
||||
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)
|
||||
self._export_type = '_' + handler.lower()
|
||||
validate_import_export_type(EnergyBuildingsExportsFactory, handler)
|
||||
if isinstance(path, str):
|
||||
path = Path(path)
|
||||
self._path = path
|
||||
|
|
|
@ -15,12 +15,11 @@ class EnergySystemsExportFactory:
|
|||
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):
|
||||
"""
|
||||
|
||||
: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 output_path: the file to hold simulation results
|
||||
:param sim_type: the simulation type, 0 for series 1 for parallel
|
||||
|
@ -33,7 +32,7 @@ class EnergySystemsExportFactory:
|
|||
if base_path is None:
|
||||
base_path = Path(Path(__file__).parent.parent / 'data/energy_systems')
|
||||
self._base_path = base_path
|
||||
self._user_input = user_input
|
||||
self._handler = handler
|
||||
self._hp_model = hp_model
|
||||
self._data_type = data_type
|
||||
self._output_path = output_path
|
||||
|
@ -49,10 +48,10 @@ class EnergySystemsExportFactory:
|
|||
"""
|
||||
if self._source == 'air':
|
||||
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':
|
||||
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'):
|
||||
"""
|
||||
|
|
|
@ -17,18 +17,14 @@ class ExportsFactory:
|
|||
"""
|
||||
Exports factory class
|
||||
"""
|
||||
def __init__(self, export_type, city, path,
|
||||
def __init__(self, handler, city, path,
|
||||
target_buildings=None,
|
||||
adjacent_buildings=None,
|
||||
weather_file=None,
|
||||
weather_format=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:
|
||||
error_message = f"Wrong export type [{self._export_type}]. Valid functions include {class_funcs}"
|
||||
logging.error(error_message)
|
||||
raise Exception(error_message)
|
||||
self._handler = '_' + handler.lower()
|
||||
validate_import_export_type(ExportsFactory, handler)
|
||||
if isinstance(path, str):
|
||||
path = Path(path)
|
||||
self._path = path
|
||||
|
@ -82,11 +78,4 @@ class ExportsFactory:
|
|||
Export the city given to the class using the given export type handler
|
||||
:return: None
|
||||
"""
|
||||
return getattr(self, self._export_type, 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)
|
||||
return getattr(self, self._handler, lambda: None)
|
|
@ -4,15 +4,19 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2023 Concordia CERC group
|
||||
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)
|
||||
and normal functions
|
||||
: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)
|
||||
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__']
|
||||
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 handler.lower() not in functions:
|
||||
error_message = f'Wrong import type [{handler}]. Valid functions include {functions}'
|
||||
logging.error(error_message)
|
||||
raise Exception(error_message)
|
||||
|
|
|
@ -6,10 +6,9 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@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.construction.nrel_physics_parameters import NrelPhysicsParameters
|
||||
from hub.imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters
|
||||
from hub.imports.construction.nrel_physics_parameters import NrelPhysicsParameters
|
||||
|
||||
|
||||
class ConstructionFactory:
|
||||
|
@ -17,12 +16,8 @@ class ConstructionFactory:
|
|||
ConstructionFactory class
|
||||
"""
|
||||
def __init__(self, handler, city):
|
||||
self._handler = '_' + handler.lower().replace(' ', '_')
|
||||
class_funcs = validate_import_export_type(ConstructionFactory)
|
||||
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._handler = '_' + handler.lower()
|
||||
validate_import_export_type(ConstructionFactory, handler)
|
||||
self._city = city
|
||||
|
||||
def _nrel(self):
|
||||
|
@ -49,10 +44,3 @@ class ConstructionFactory:
|
|||
:return: 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()
|
||||
|
|
|
@ -5,6 +5,7 @@ Copyright © 2022 Concordia CERC group
|
|||
Project Coder Peter Yefi peteryefi@gmail.comCode
|
||||
contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
"""
|
||||
import io
|
||||
|
||||
import pandas as pd
|
||||
from typing import Dict
|
||||
|
@ -31,22 +32,19 @@ class AirSourceHeatPumpParameters:
|
|||
into a dictionary
|
||||
:return : Dict
|
||||
"""
|
||||
xl_file = pd.ExcelFile(self._base_path)
|
||||
|
||||
heat_pump_dfs = {sheet_name: xl_file.parse(sheet_name)
|
||||
for sheet_name in xl_file.sheet_names}
|
||||
with open(self._base_path, 'rb') as xls:
|
||||
xl_file = pd.read_excel(io.BytesIO(xls.read()), sheet_name=None)
|
||||
|
||||
cooling_data = {}
|
||||
heating_data = {}
|
||||
|
||||
for sheet, dataframe in heat_pump_dfs.items():
|
||||
|
||||
for sheet, dataframe in xl_file.items():
|
||||
if 'Summary' in sheet:
|
||||
continue
|
||||
|
||||
# Remove nan rows and columns and extract cooling and heating data
|
||||
# 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]
|
||||
heating_df = df.iloc[4:29, 8:20]
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2022 Concordia CERC group
|
||||
Project Coder Peter Yefi peteryefi@gmail.com
|
||||
"""
|
||||
import io
|
||||
|
||||
import pandas as pd
|
||||
from typing import Dict
|
||||
|
@ -28,6 +29,20 @@ class WaterToWaterHPParameters:
|
|||
reads xlsx file containing water to water heat pump information
|
||||
into a dictionary
|
||||
: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)
|
||||
heat_pump_dfs = {sheet_name: xl_file.parse(sheet_name)
|
||||
|
@ -43,6 +58,7 @@ class WaterToWaterHPParameters:
|
|||
for sheet, dataframe in heat_pump_dfs.items():
|
||||
|
||||
df = heat_pump_dfs[sheet].dropna(axis=1, how='all')
|
||||
print(df)
|
||||
df = df.iloc[3:, 6:35]
|
||||
|
||||
if '156' in sheet:
|
||||
|
|
|
@ -5,12 +5,12 @@ Copyright © 2022 Concordia CERC group
|
|||
Project Coder Pilar Monsalvete pilar.monsalvete@concordi.
|
||||
Code contributors: Peter Yefi peteryefi@gmail.com
|
||||
"""
|
||||
import logging
|
||||
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.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.water_to_water_hp_parameters import WaterToWaterHPParameters
|
||||
|
||||
|
||||
class EnergySystemsFactory:
|
||||
|
@ -21,12 +21,8 @@ class EnergySystemsFactory:
|
|||
def __init__(self, handler, city, base_path=None):
|
||||
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:
|
||||
error_message = f"Wrong import type. Valid functions include {class_funcs}"
|
||||
logging.error(error_message)
|
||||
raise Exception(error_message)
|
||||
self._handler = '_' + handler.lower()
|
||||
validate_import_export_type(EnergySystemsFactory, handler)
|
||||
self._city = city
|
||||
self._base_path = base_path
|
||||
|
||||
|
|
|
@ -4,16 +4,15 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2022 Concordia CERC group
|
||||
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
"""
|
||||
import logging
|
||||
import geopandas
|
||||
|
||||
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.geojson import Geojson
|
||||
from hub.imports.geometry.gpandas import GPandas
|
||||
from hub.imports.geometry.obj import Obj
|
||||
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:
|
||||
|
@ -29,11 +28,7 @@ class GeometryFactory:
|
|||
function_field=None,
|
||||
function_to_hub=None):
|
||||
self._file_type = '_' + file_type.lower()
|
||||
class_funcs = validate_import_export_type(GeometryFactory)
|
||||
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)
|
||||
validate_import_export_type(GeometryFactory, file_type)
|
||||
self._path = path
|
||||
self._data_frame = data_frame
|
||||
self._name_field = name_field
|
||||
|
|
|
@ -5,13 +5,12 @@ Copyright © 2022 Concordia CERC group
|
|||
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
"""
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
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_monthly_energry_balance import InselMonthlyEnergyBalance
|
||||
from hub.imports.results.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
|
||||
|
||||
|
||||
class ResultFactory:
|
||||
|
@ -31,11 +30,7 @@ class ResultFactory:
|
|||
if base_path is None:
|
||||
base_path = Path(Path(__file__).parent.parent / 'data/results')
|
||||
self._handler = '_' + handler.lower().replace(' ', '_')
|
||||
class_funcs = validate_import_export_type(ResultFactory)
|
||||
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)
|
||||
validate_import_export_type(ResultFactory, handler)
|
||||
self._city = city
|
||||
self._base_path = base_path
|
||||
self._hp_model = hp_model
|
||||
|
|
|
@ -6,10 +6,9 @@ Copyright © 2022 Concordia CERC group
|
|||
Project Coder Guille Gutierrez guillermo.gutierrezmorote@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.nrcan_usage_parameters import NrcanUsageParameters
|
||||
from hub.helpers.utils import validate_import_export_type
|
||||
|
||||
|
||||
class UsageFactory:
|
||||
|
@ -17,12 +16,8 @@ class UsageFactory:
|
|||
UsageFactory class
|
||||
"""
|
||||
def __init__(self, handler, city):
|
||||
self._handler = '_' + handler.lower().replace(' ', '_')
|
||||
class_funcs = validate_import_export_type(UsageFactory)
|
||||
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._handler = '_' + handler.lower()
|
||||
validate_import_export_type(UsageFactory, handler)
|
||||
self._city = city
|
||||
|
||||
def _comnet(self):
|
||||
|
|
|
@ -4,11 +4,11 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2022 Concordia CERC group
|
||||
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
"""
|
||||
import logging
|
||||
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.imports.weather.epw_weather_parameters import EpwWeatherParameters
|
||||
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
|
||||
|
||||
|
||||
class WeatherFactory:
|
||||
|
@ -20,11 +20,7 @@ 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:
|
||||
error_message = f"Wrong import type. Valid functions include {class_funcs}"
|
||||
logging.error(error_message)
|
||||
raise Exception(error_message)
|
||||
validate_import_export_type(WeatherFactory, handler)
|
||||
self._city = city
|
||||
self._base_path = base_path
|
||||
self._file_name = file_name
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
"""
|
||||
Persistence package
|
||||
"""
|
||||
|
||||
|
|
|
@ -28,9 +28,6 @@ class DBControl:
|
|||
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)
|
||||
|
||||
@property
|
||||
def identity(self):
|
||||
return self._identity
|
||||
def application_info(self, application_uuid) -> Application:
|
||||
"""
|
||||
Retrieve the application info for the given uuid
|
||||
|
@ -120,7 +117,6 @@ class DBControl:
|
|||
return identity_id
|
||||
"""
|
||||
self._city_repository.insert(city, pickle_path, application_id, user_id)
|
||||
return
|
||||
|
||||
def update_city(self, city_id, city):
|
||||
"""
|
||||
|
|
|
@ -49,7 +49,7 @@ class TestCityMerge(TestCase):
|
|||
city_two.name = 'New_York'
|
||||
city_two.climate_file = self._climate_file
|
||||
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()
|
||||
subprocess.run([self._executable, f'{str(self._output_path)}/{city_two.name}_sra.xml'], stdout=subprocess.DEVNULL)
|
||||
except (SubprocessError, TimeoutExpired, CalledProcessError) as error:
|
||||
|
|
|
@ -41,7 +41,7 @@ class TestEnergySystemsFactory(TestCase):
|
|||
city_file = "tests_data/C40_Final.gml"
|
||||
self._output_path = "tests_data/as_user_output.csv"
|
||||
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):
|
||||
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')
|
||||
|
||||
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()
|
||||
df = pd.read_csv(self._output_path)
|
||||
self.assertEqual(df.shape, (13, 3))
|
||||
self.assertEqual(df.iloc[0, 1], 1867715.88)
|
||||
|
||||
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()
|
||||
self.assertEqual(output["hourly_electricity_demand"][0], 38748.5625)
|
||||
self.assertIsNotNone(output["daily_fossil_consumption"])
|
||||
|
|
|
@ -27,7 +27,7 @@ class TestEnergySystemsFactory(TestCase):
|
|||
city_file = "tests_data/C40_Final.gml"
|
||||
self._output_path = "tests_data/w2w_user_output.csv"
|
||||
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):
|
||||
self.assertIsNotNone(self._city.energy_systems, 'City has energy systems')
|
||||
|
@ -62,7 +62,7 @@ class TestEnergySystemsFactory(TestCase):
|
|||
'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')
|
||||
df = pd.read_csv(self._output_path)
|
||||
self.assertEqual(df.shape, (13, 3))
|
||||
|
|
|
@ -41,12 +41,12 @@ class TestHeatPumpResults(TestCase):
|
|||
city_file = "tests_data/C40_Final.gml"
|
||||
self._output_path = "tests_data/as_user_output.csv"
|
||||
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):
|
||||
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()
|
||||
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:
|
||||
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)
|
||||
|
||||
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()
|
||||
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:
|
||||
self.assertIsNone(energy_system.water_to_water_hp)
|
||||
|
|
Loading…
Reference in New Issue
Block a user