Bug correction and code quality improvements

This commit is contained in:
Guille Gutierrez 2023-05-31 16:55:44 -04:00
parent 11ba482e73
commit 0956f40e42
45 changed files with 260 additions and 89 deletions

View File

@ -1,3 +1,9 @@
"""
Construction helper module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez Guillermo.GutierrezMorote@concordia.ca
"""
from hub.helpers import constants as cte from hub.helpers import constants as cte
@ -34,12 +40,24 @@ class ConstructionHelper:
@property @property
def reference_standard_to_construction_period(self): def reference_standard_to_construction_period(self):
"""
Get reference standard to construction period dictionary
:return: {}
"""
return self._reference_standard_to_construction_period return self._reference_standard_to_construction_period
@property @property
def nrel_surfaces_types_to_hub_types(self): def nrel_surfaces_types_to_hub_types(self):
"""
Get reference nrel surface type to hub type dictionary
:return: {}
"""
return self._nrel_surfaces_types_to_hub_types return self._nrel_surfaces_types_to_hub_types
@property @property
def nrcan_surfaces_types_to_hub_types(self): def nrcan_surfaces_types_to_hub_types(self):
"""
Get reference nrcan surface type to hub type dictionary
:return: {}
"""
return self._nrcan_surfaces_types_to_hub_types return self._nrcan_surfaces_types_to_hub_types

View File

@ -18,12 +18,15 @@ from hub.catalog_factories.data_models.construction.layer import Layer
class NrcanCatalog(Catalog): class NrcanCatalog(Catalog):
"""
Nrcan catalog class
"""
def __init__(self, path): def __init__(self, path):
_path_archetypes = Path(path / 'nrcan_archetypes.json').resolve() _path_archetypes = Path(path / 'nrcan_archetypes.json').resolve()
_path_constructions = (path / 'nrcan_constructions.json') _path_constructions = (path / 'nrcan_constructions.json').resolve()
with open(_path_archetypes, 'r') as file: with open(_path_archetypes, 'r', encoding='utf-8') as file:
self._archetypes = json.load(file) self._archetypes = json.load(file)
with open(_path_constructions, 'r') as file: with open(_path_constructions, 'r', encoding='utf-8') as file:
self._constructions = json.load(file) self._constructions = json.load(file)
self._catalog_windows = self._load_windows() self._catalog_windows = self._load_windows()
@ -200,17 +203,15 @@ class NrcanCatalog(Catalog):
""" """
if category is None: if category is None:
return self._content return self._content
else: if category.lower() == 'archetypes':
if category.lower() == 'archetypes': return self._content.archetypes
return self._content.archetypes if category.lower() == 'constructions':
elif category.lower() == 'constructions': return self._content.constructions
return self._content.constructions if category.lower() == 'materials':
elif category.lower() == 'materials': return self._content.materials
return self._content.materials if category.lower() == 'windows':
elif category.lower() == 'windows': return self._content.windows
return self._content.windows raise ValueError(f'Unknown category [{category}]')
else:
raise ValueError(f'Unknown category [{category}]')
def get_entry(self, name): def get_entry(self, name):
""" """

View File

@ -5,8 +5,8 @@ Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
""" """
import xmltodict
from pathlib import Path from pathlib import Path
import xmltodict
from hub.catalog_factories.catalog import Catalog from hub.catalog_factories.catalog import Catalog
from hub.catalog_factories.data_models.construction.window import Window from hub.catalog_factories.data_models.construction.window import Window
from hub.catalog_factories.data_models.construction.material import Material from hub.catalog_factories.data_models.construction.material import Material
@ -18,12 +18,15 @@ from hub.catalog_factories.construction.construction_helper import ConstructionH
class NrelCatalog(Catalog): class NrelCatalog(Catalog):
"""
Nrel catalog class
"""
def __init__(self, path): def __init__(self, path):
archetypes_path = str(Path(path / 'us_archetypes.xml').resolve()) archetypes_path = str(Path(path / 'us_archetypes.xml').resolve())
constructions_path = str(Path(path / 'us_constructions.xml').resolve()) constructions_path = str(Path(path / 'us_constructions.xml').resolve())
with open(constructions_path) as xml: with open(constructions_path, 'r', encoding='utf-8') as xml:
self._constructions = xmltodict.parse(xml.read(), force_list=('material', 'window', 'construction', 'layer')) self._constructions = xmltodict.parse(xml.read(), force_list=('material', 'window', 'construction', 'layer'))
with open(archetypes_path) as xml: with open(archetypes_path, 'r', encoding='utf-8') as xml:
self._archetypes = xmltodict.parse(xml.read(), force_list=('archetype', 'construction')) self._archetypes = xmltodict.parse(xml.read(), force_list=('archetype', 'construction'))
self._catalog_windows = self._load_windows() self._catalog_windows = self._load_windows()
self._catalog_materials = self._load_materials() self._catalog_materials = self._load_materials()
@ -58,9 +61,9 @@ class NrelCatalog(Catalog):
thermal_absorptance = float(material['thermal_absorptance']['#text']) thermal_absorptance = float(material['thermal_absorptance']['#text'])
visible_absorptance = float(material['visible_absorptance']['#text']) visible_absorptance = float(material['visible_absorptance']['#text'])
no_mass = False no_mass = False
thermal_resistance = None, thermal_resistance = None
conductivity = None, conductivity = None
density = None, density = None
specific_heat = None specific_heat = None
if 'no_mass' in material and material['no_mass'] == 'true': if 'no_mass' in material and material['no_mass'] == 'true':
no_mass = True no_mass = True
@ -201,17 +204,15 @@ class NrelCatalog(Catalog):
""" """
if category is None: if category is None:
return self._content return self._content
else: if category.lower() == 'archetypes':
if category.lower() == 'archetypes': return self._content.archetypes
return self._content.archetypes if category.lower() == 'constructions':
elif category.lower() == 'constructions': return self._content.constructions
return self._content.constructions if category.lower() == 'materials':
elif category.lower() == 'materials': return self._content.materials
return self._content.materials if category.lower() == 'windows':
elif category.lower() == 'windows': return self._content.windows
return self._content.windows raise ValueError(f'Unknown category [{category}]')
else:
raise ValueError(f'Unknown category [{category}]')
def get_entry(self, name): def get_entry(self, name):
""" """

View File

@ -4,17 +4,21 @@ 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
from pathlib import Path from pathlib import Path
from typing import TypeVar from typing import TypeVar
from hub.catalog_factories.construction.nrcan_catalog import NrcanCatalog
from hub.catalog_factories.construction.nrel_catalog import NrelCatalog from hub.catalog_factories.construction.nrel_catalog import NrelCatalog
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
from hub.catalog_factories.construction.nrcan_catalog import NrcanCatalog
Catalog = TypeVar('Catalog') Catalog = TypeVar('Catalog')
class ConstructionCatalogFactory: class ConstructionCatalogFactory:
"""
Construction catalog factory class
"""
def __init__(self, handler, 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')

View File

@ -18,9 +18,12 @@ from hub.catalog_factories.data_models.cost.income import Income
class MontrealCustomCatalog(Catalog): class MontrealCustomCatalog(Catalog):
"""
Montreal custom catalog class
"""
def __init__(self, path): def __init__(self, path):
path = (path / 'montreal_costs.xml') path = (path / 'montreal_costs.xml').resolve()
with open(path) as xml: with open(path, 'r', encoding='utf-8') as xml:
self._archetypes = xmltodict.parse(xml.read(), force_list='archetype') self._archetypes = xmltodict.parse(xml.read(), force_list='archetype')
# store the full catalog data model in self._content # store the full catalog data model in self._content

View File

@ -9,6 +9,9 @@ from hub.catalog_factories.data_models.construction.construction import Construc
class Archetype: class Archetype:
"""
Archetype class
"""
def __init__(self, archetype_id, def __init__(self, archetype_id,
name, name,
function, function,

View File

@ -9,6 +9,9 @@ from hub.catalog_factories.data_models.construction.window import Window
class Construction: class Construction:
"""
Construction class
"""
def __init__(self, construction_id, construction_type, name, layers, window_ratio=None, window=None): def __init__(self, construction_id, construction_type, name, layers, window_ratio=None, window=None):
self._id = construction_id self._id = construction_id
self._type = construction_type self._type = construction_type

View File

@ -7,6 +7,9 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
class Content: class Content:
"""
Content class
"""
def __init__(self, archetypes, constructions, materials, windows): def __init__(self, archetypes, constructions, materials, windows):
self._archetypes = archetypes self._archetypes = archetypes
self._constructions = constructions self._constructions = constructions

View File

@ -7,6 +7,9 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
class Layer: class Layer:
"""
Layer class
"""
def __init__(self, layer_id, name, material, thickness): def __init__(self, layer_id, name, material, thickness):
self._id = layer_id self._id = layer_id
self._name = name self._name = name

View File

@ -7,6 +7,9 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
class Material: class Material:
"""
Material class
"""
def __init__(self, material_id, def __init__(self, material_id,
name, name,
solar_absorptance, solar_absorptance,

View File

@ -7,6 +7,9 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
class Window: class Window:
"""
Window class
"""
def __init__(self, window_id, frame_ratio, g_value, overall_u_value, name, window_type=None): def __init__(self, window_id, frame_ratio, g_value, overall_u_value, name, window_type=None):
self._id = window_id self._id = window_id
self._frame_ratio = frame_ratio self._frame_ratio = frame_ratio

View File

@ -11,6 +11,9 @@ from hub.catalog_factories.data_models.cost.income import Income
class Archetype: class Archetype:
"""
Archetype class
"""
def __init__(self, def __init__(self,
lod, lod,
function, function,

View File

@ -10,6 +10,9 @@ from hub.catalog_factories.data_models.cost.chapter import Chapter
class CapitalCost: class CapitalCost:
"""
Capital cost class
"""
def __init__(self, general_chapters, design_allowance, overhead_and_profit): def __init__(self, general_chapters, design_allowance, overhead_and_profit):
self._general_chapters = general_chapters self._general_chapters = general_chapters
self._design_allowance = design_allowance self._design_allowance = design_allowance

View File

@ -10,6 +10,9 @@ from hub.catalog_factories.data_models.cost.item_description import ItemDescript
class Chapter: class Chapter:
"""
Chapter class
"""
def __init__(self, chapter_type, items): def __init__(self, chapter_type, items):
self._chapter_type = chapter_type self._chapter_type = chapter_type

View File

@ -8,6 +8,9 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
class Content: class Content:
"""
Content class
"""
def __init__(self, archetypes): def __init__(self, archetypes):
self._archetypes = archetypes self._archetypes = archetypes

View File

@ -9,6 +9,9 @@ from typing import Union
class Fuel: class Fuel:
"""
Fuel class
"""
def __init__(self, fuel_type, def __init__(self, fuel_type,
fixed_monthly=None, fixed_monthly=None,
fixed_power=None, fixed_power=None,

View File

@ -9,6 +9,9 @@ from typing import Union
class Income: class Income:
"""
Income class
"""
def __init__(self, construction_subsidy=None, def __init__(self, construction_subsidy=None,
hvac_subsidy=None, hvac_subsidy=None,
photovoltaic_subsidy=None, photovoltaic_subsidy=None,

View File

@ -9,6 +9,9 @@ from typing import Union
class ItemDescription: class ItemDescription:
"""
Item description class
"""
def __init__(self, item_type, def __init__(self, item_type,
initial_investment=None, initial_investment=None,
initial_investment_unit=None, initial_investment_unit=None,

View File

@ -10,6 +10,9 @@ from hub.catalog_factories.data_models.cost.fuel import Fuel
class OperationalCost: class OperationalCost:
"""
Operational cost class
"""
def __init__(self, fuels, maintenance_heating, maintenance_cooling, maintenance_pv, co2): def __init__(self, fuels, maintenance_heating, maintenance_cooling, maintenance_pv, co2):
self._fuels = fuels self._fuels = fuels
self._maintenance_heating = maintenance_heating self._maintenance_heating = maintenance_heating

View File

@ -11,6 +11,9 @@ from hub.catalog_factories.data_models.energy_systems.system import System
class Archetype: class Archetype:
"""
Archetype class
"""
def __init__(self, lod, name, systems): def __init__(self, lod, name, systems):
self._lod = lod self._lod = lod

View File

@ -7,6 +7,9 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
class Content: class Content:
"""
Content class
"""
def __init__(self, archetypes, systems, generations, distributions, emissions): def __init__(self, archetypes, systems, generations, distributions, emissions):
self._archetypes = archetypes self._archetypes = archetypes
self._systems = systems self._systems = systems

View File

@ -7,6 +7,9 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
class DistributionSystem: class DistributionSystem:
"""
Distribution system class
"""
def __init__(self, system_id, name, system_type, supply_temperature, distribution_consumption_fix_flow, def __init__(self, system_id, name, system_type, supply_temperature, distribution_consumption_fix_flow,
distribution_consumption_variable_flow, heat_losses): distribution_consumption_variable_flow, heat_losses):

View File

@ -7,6 +7,9 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
class EmissionSystem: class EmissionSystem:
"""
Emission system class
"""
def __init__(self, system_id, name, system_type, parasitic_energy_consumption): def __init__(self, system_id, name, system_type, parasitic_energy_consumption):
self._system_id = system_id self._system_id = system_id

View File

@ -10,6 +10,9 @@ from typing import Union
class GenerationSystem: class GenerationSystem:
"""
Generation system class
"""
def __init__(self, system_id, name, system_type, fuel_type, source_types, heat_efficiency, cooling_efficiency, def __init__(self, system_id, name, system_type, fuel_type, source_types, heat_efficiency, cooling_efficiency,
electricity_efficiency, source_temperature, source_mass_flow, storage, auxiliary_equipment): electricity_efficiency, source_temperature, source_mass_flow, storage, auxiliary_equipment):

View File

@ -13,6 +13,9 @@ from hub.catalog_factories.data_models.energy_systems.emission_system import Emi
class System: class System:
"""
System class
"""
def __init__(self, def __init__(self,
lod, lod,
system_id, system_id,

View File

@ -7,6 +7,9 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
class Content: class Content:
"""
Content class
"""
def __init__(self, vegetations, plants, soils): def __init__(self, vegetations, plants, soils):
self._vegetations = vegetations self._vegetations = vegetations
self._plants = plants self._plants = plants

View File

@ -9,6 +9,9 @@ from hub.catalog_factories.data_models.greenery.soil import Soil as hub_soil
class Plant: class Plant:
"""
Plant class
"""
def __init__(self, category, plant): def __init__(self, category, plant):
self._name = plant.name self._name = plant.name
self._category = category self._category = category

View File

@ -5,10 +5,13 @@ Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
""" """
from hub.catalog_factories.data_models.greenery.plant import Plant as hub_plant from hub.catalog_factories.data_models.greenery.plant import Plant as HubPlant
class PlantPercentage(hub_plant): class PlantPercentage(HubPlant):
"""
Plant percentage class
"""
def __init__(self, percentage, plant_category, plant): def __init__(self, percentage, plant_category, plant):
super().__init__(plant_category, plant) super().__init__(plant_category, plant)

View File

@ -7,6 +7,9 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
class Soil: class Soil:
"""
Soil class
"""
def __init__(self, soil): def __init__(self, soil):
self._name = soil.name self._name = soil.name
self._roughness = soil.roughness self._roughness = soil.roughness

View File

@ -9,6 +9,9 @@ from hub.catalog_factories.data_models.greenery.plant_percentage import PlantPer
class Vegetation: class Vegetation:
"""
Vegetation class
"""
def __init__(self, category, vegetation, plant_percentages): def __init__(self, category, vegetation, plant_percentages):
self._name = vegetation.name self._name = vegetation.name
self._category = category self._category = category

View File

@ -8,6 +8,9 @@ from hub.catalog_factories.data_models.usages.usage import Usage
class Content: class Content:
"""
Content class
"""
def __init__(self, usages): def __init__(self, usages):
self._usages = usages self._usages = usages
@ -17,4 +20,3 @@ class Content:
Get catalog usages Get catalog usages
""" """
return self._usages return self._usages

View File

@ -18,5 +18,3 @@ class InternalGain:
self._radiative_fraction = radiative_fraction self._radiative_fraction = radiative_fraction
self._latent_fraction = latent_fraction self._latent_fraction = latent_fraction
self._schedules = schedules self._schedules = schedules

View File

@ -11,6 +11,9 @@ from hub.catalog_factories.data_models.usages.schedule import Schedule
class Lighting: class Lighting:
"""
Lighting class
"""
def __init__(self, density, convective_fraction, radiative_fraction, latent_fraction, schedules): def __init__(self, density, convective_fraction, radiative_fraction, latent_fraction, schedules):
self._density = density self._density = density
self._convective_fraction = convective_fraction self._convective_fraction = convective_fraction

View File

@ -14,6 +14,9 @@ from hub.catalog_factories.data_models.usages.domestic_hot_water import Domestic
class Usage: class Usage:
"""
Usage class
"""
def __init__(self, name, def __init__(self, name,
hours_day, hours_day,
days_year, days_year,

View File

@ -1,12 +1,12 @@
""" """
Montreal custom energy systems catalog Montreal custom energy systems catalog module
SPDX - License - Identifier: LGPL - 3.0 - or -later 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
""" """
from ast import literal_eval
import xmltodict import xmltodict
from hub.catalog_factories.catalog import Catalog from hub.catalog_factories.catalog import Catalog
from hub.catalog_factories.data_models.energy_systems.system import System from hub.catalog_factories.data_models.energy_systems.system import System
from hub.catalog_factories.data_models.energy_systems.content import Content from hub.catalog_factories.data_models.energy_systems.content import Content
@ -17,9 +17,12 @@ from hub.catalog_factories.data_models.energy_systems.archetype import Archetype
class MontrealCustomCatalog(Catalog): class MontrealCustomCatalog(Catalog):
"""
Montreal custom energy systems catalog class
"""
def __init__(self, path): def __init__(self, path):
path = str(path / 'montreal_custom_systems.xml') path = str(path / 'montreal_custom_systems.xml')
with open(path) as xml: with open(path, 'r', encoding='utf-8') as xml:
self._archetypes = xmltodict.parse(xml.read(), force_list=('system', 'system_cluster', 'equipment', self._archetypes = xmltodict.parse(xml.read(), force_list=('system', 'system_cluster', 'equipment',
'demand', 'system_id')) 'demand', 'system_id'))
@ -55,7 +58,7 @@ class MontrealCustomCatalog(Catalog):
electricity_efficiency = None electricity_efficiency = None
if 'electrical_efficiency' in equipment: if 'electrical_efficiency' in equipment:
electricity_efficiency = float(equipment['electrical_efficiency']) electricity_efficiency = float(equipment['electrical_efficiency'])
storage = eval(equipment['storage'].capitalize()) storage = literal_eval(equipment['storage'].capitalize())
generation_system = GenerationSystem(equipment_id, generation_system = GenerationSystem(equipment_id,
name, name,
equipment_type, equipment_type,
@ -211,19 +214,17 @@ class MontrealCustomCatalog(Catalog):
""" """
if category is None: if category is None:
return self._content return self._content
else: if category.lower() == 'archetypes':
if category.lower() == 'archetypes': return self._content.archetypes
return self._content.archetypes if category.lower() == 'systems':
elif category.lower() == 'systems': return self._content.systems
return self._content.systems if category.lower() == 'generation_equipments':
elif category.lower() == 'generation_equipments': return self._content.generation_equipments
return self._content.generation_equipments if category.lower() == 'distribution_equipments':
elif category.lower() == 'distribution_equipments': return self._content.distribution_equipments
return self._content.distribution_equipments if category.lower() == 'emission_equipments':
elif category.lower() == 'emission_equipments': return self._content.emission_equipments
return self._content.emission_equipments raise ValueError(f'Unknown category [{category}]')
else:
raise ValueError(f'Unknown category [{category}]')
def get_entry(self, name): def get_entry(self, name):
""" """

View File

@ -4,16 +4,20 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group Copyright © 2022 Concordia CERC group
Project Coder Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca Project Coder Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import logging
from pathlib import Path from pathlib import Path
from typing import TypeVar from typing import TypeVar
from hub.catalog_factories.energy_systems.montreal_custom_catalog import MontrealCustomCatalog from hub.catalog_factories.energy_systems.montreal_custom_catalog import MontrealCustomCatalog
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
Catalog = TypeVar('Catalog') Catalog = TypeVar('Catalog')
class EnergySystemsCatalogFactory: class EnergySystemsCatalogFactory:
"""
Energy system catalog factory class
"""
def __init__(self, handler, 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')

View File

@ -5,33 +5,36 @@ Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
""" """
from pyecore.resources import ResourceSet, URI
from hub.catalog_factories.greenery.ecore_greenery.greenerycatalog import GreeneryCatalog as gc
from hub.catalog_factories.catalog import Catalog
from pathlib import Path from pathlib import Path
from hub.catalog_factories.data_models.greenery.vegetation import Vegetation as libs_vegetation from pyecore.resources import ResourceSet, URI
from hub.catalog_factories.data_models.greenery.plant import Plant as libs_plant from hub.catalog_factories.greenery.ecore_greenery.greenerycatalog import GreeneryCatalog as Gc
from hub.catalog_factories.data_models.greenery.soil import Soil as libs_soil from hub.catalog_factories.catalog import Catalog
from hub.catalog_factories.data_models.greenery.plant_percentage import PlantPercentage as libs_pp from hub.catalog_factories.data_models.greenery.vegetation import Vegetation as HubVegetation
from hub.catalog_factories.data_models.greenery.plant import Plant as HubPlant
from hub.catalog_factories.data_models.greenery.soil import Soil as HubSoil
from hub.catalog_factories.data_models.greenery.plant_percentage import PlantPercentage as HubPlantPercentage
from hub.catalog_factories.data_models.greenery.content import Content as GreeneryContent from hub.catalog_factories.data_models.greenery.content import Content as GreeneryContent
class GreeneryCatalog(Catalog): class GreeneryCatalog(Catalog):
"""
Greenery catalog class
"""
def __init__(self, path): def __init__(self, path):
base_path = Path(Path(__file__).parent / 'ecore_greenery' / 'greenerycatalog_no_quantities.ecore') base_path = Path(Path(__file__).parent / 'ecore_greenery/greenerycatalog_no_quantities.ecore').resolve()
resource_set = ResourceSet() resource_set = ResourceSet()
data_model = resource_set.get_resource(URI(str(base_path))) data_model = resource_set.get_resource(URI(str(base_path)))
data_model_root = data_model.contents[0] data_model_root = data_model.contents[0]
resource_set.metamodel_registry[data_model_root.nsURI] = data_model_root resource_set.metamodel_registry[data_model_root.nsURI] = data_model_root
resource = resource_set.get_resource(URI(str(path))) resource = resource_set.get_resource(URI(str(path)))
catalog_data: gc = resource.contents[0] catalog_data: Gc = resource.contents[0]
plants = [] plants = []
for plant_category in catalog_data.plantCategories: for plant_category in catalog_data.plantCategories:
name = plant_category.name name = plant_category.name
for plant in plant_category.plants: for plant in plant_category.plants:
plants.append(libs_plant(name, plant)) plants.append(HubPlant(name, plant))
vegetations = [] vegetations = []
for vegetation_category in catalog_data.vegetationCategories: for vegetation_category in catalog_data.vegetationCategories:
@ -45,17 +48,19 @@ class GreeneryCatalog(Catalog):
if plant.name == plant_percentage.plant.name: if plant.name == plant_percentage.plant.name:
plant_category = plant.category plant_category = plant.category
break break
plant_percentages.append(libs_pp(plant_percentage.percentage, plant_category, plant_percentage.plant)) plant_percentages.append(
vegetations.append(libs_vegetation(name, vegetation, plant_percentages)) HubPlantPercentage(plant_percentage.percentage, plant_category, plant_percentage.plant)
)
vegetations.append(HubVegetation(name, vegetation, plant_percentages))
plants = [] plants = []
for plant_category in catalog_data.plantCategories: for plant_category in catalog_data.plantCategories:
name = plant_category.name name = plant_category.name
for plant in plant_category.plants: for plant in plant_category.plants:
plants.append(libs_plant(name, plant)) plants.append(HubPlant(name, plant))
soils = [] soils = []
for soil in catalog_data.soils: for soil in catalog_data.soils:
soils.append(libs_soil(soil)) soils.append(HubSoil(soil))
self._content = GreeneryContent(vegetations, plants, soils) self._content = GreeneryContent(vegetations, plants, soils)
@ -103,14 +108,15 @@ class GreeneryCatalog(Catalog):
raise IndexError(f"{name} doesn't exists in the catalog") raise IndexError(f"{name} doesn't exists in the catalog")
def entries(self, category=None): def entries(self, category=None):
"""
Get all entries from the greenery catalog optionally filtered by category
"""
if category is None: if category is None:
return self._content return self._content
else: if category.lower() == 'vegetations':
if category.lower() == 'vegetations': return self._content.vegetations
return self._content.vegetations if category.lower() == 'plants':
elif category.lower() == 'plants': return self._content.plants
return self._content.plants if category.lower() == 'soils':
elif category.lower() == 'soils': return self._content.soils
return self._content.soils raise ValueError(f'Unknown category [{category}]')
else:
raise ValueError(f'Unknown category [{category}]')

View File

@ -24,6 +24,9 @@ from hub.helpers.configuration_helper import ConfigurationHelper as ch
class ComnetCatalog(Catalog): class ComnetCatalog(Catalog):
"""
Comnet catalog class
"""
def __init__(self, path): def __init__(self, path):
self._comnet_archetypes_path = str(path / 'comnet_archetypes.xlsx') self._comnet_archetypes_path = str(path / 'comnet_archetypes.xlsx')
self._comnet_schedules_path = str(path / 'comnet_schedules_archetypes.xlsx') self._comnet_schedules_path = str(path / 'comnet_schedules_archetypes.xlsx')

View File

@ -24,11 +24,14 @@ from hub.catalog_factories.usage.usage_helper import UsageHelper
class NrcanCatalog(Catalog): class NrcanCatalog(Catalog):
"""
Nrcan catalog class
"""
def __init__(self, path): def __init__(self, path):
path = str(path / 'nrcan.xml') path = str(path / 'nrcan.xml')
self._content = None self._content = None
self._schedules = {} self._schedules = {}
with open(path) as xml: with open(path, 'r', encoding='utf-8') as xml:
self._metadata = xmltodict.parse(xml.read()) self._metadata = xmltodict.parse(xml.read())
self._base_url = self._metadata['nrcan']['@base_url'] self._base_url = self._metadata['nrcan']['@base_url']
self._load_schedules() self._load_schedules()
@ -70,8 +73,10 @@ class NrcanCatalog(Catalog):
self._schedules[schedule_type['name']] = _schedules self._schedules[schedule_type['name']] = _schedules
def _get_schedules(self, name): def _get_schedules(self, name):
schedule = None
if name in self._schedules: if name in self._schedules:
return self._schedules[name] schedule = self._schedules[name]
return schedule
def _load_archetypes(self): def _load_archetypes(self):
usages = [] usages = []
@ -94,7 +99,10 @@ class NrcanCatalog(Catalog):
# W/m2 # W/m2
appliances_density = space_type['electric_equipment_per_area_w_per_m2'] appliances_density = space_type['electric_equipment_per_area_w_per_m2']
# peak flow in gallons/h/m2 # peak flow in gallons/h/m2
domestic_hot_water_peak_flow = space_type['service_water_heating_peak_flow_per_area'] * cte.GALLONS_TO_QUBIC_METERS / cte.HOUR_TO_SECONDS domestic_hot_water_peak_flow = (
space_type['service_water_heating_peak_flow_per_area'] *
cte.GALLONS_TO_QUBIC_METERS / cte.HOUR_TO_SECONDS
)
space_types_dictionary[usage_type] = {'occupancy_per_area': occupancy_density, space_types_dictionary[usage_type] = {'occupancy_per_area': occupancy_density,
'lighting_per_area': lighting_density, 'lighting_per_area': lighting_density,
'electric_equipment_per_area': appliances_density, 'electric_equipment_per_area': appliances_density,

View File

@ -4,17 +4,21 @@ 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
from pathlib import Path 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.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
Catalog = TypeVar('Catalog') Catalog = TypeVar('Catalog')
class UsageCatalogFactory: class UsageCatalogFactory:
"""
Usage catalog factory class
"""
def __init__(self, handler, 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')

View File

@ -28,5 +28,5 @@ class Triangular:
for building in self._city.buildings: for building in self._city.buildings:
trimesh = trimesh.union(building.simplified_polyhedron.trimesh) trimesh = trimesh.union(building.simplified_polyhedron.trimesh)
with open(file_path, self._write_mode, encoding='utf-8') as file: with open(file_path, self._write_mode) as file:
file.write(trimesh.export(file_type=self._triangular_format)) file.write(trimesh.export(file_type=self._triangular_format))

View File

@ -8,7 +8,7 @@ Project Coder Peter Yefi peteryefi@gmail.com
import bcrypt import bcrypt
class Auth(object): class Auth:
""" """
Auth class Auth class
""" """

View File

@ -9,6 +9,9 @@ import hub.helpers.constants as cte
class MontrealFunctionToHubFunction: class MontrealFunctionToHubFunction:
"""
Montreal function to hub function class
"""
def __init__(self): def __init__(self):
self._dictionary = {'1000': cte.RESIDENTIAL, self._dictionary = {'1000': cte.RESIDENTIAL,
@ -584,4 +587,8 @@ class MontrealFunctionToHubFunction:
@property @property
def dictionary(self) -> dict: def dictionary(self) -> dict:
"""
Get the dictionary
:return: {}
"""
return self._dictionary return self._dictionary

View File

@ -9,7 +9,9 @@ import hub.helpers.constants as cte
class MontrealSystemToHubEnergyGenerationSystem: class MontrealSystemToHubEnergyGenerationSystem:
"""
Montreal's system to hub energy generation system class
"""
def __init__(self): def __init__(self):
self._dictionary = { self._dictionary = {
'Unitary air conditioner with baseboard heater fuel fired boiler': cte.BOILER, 'Unitary air conditioner with baseboard heater fuel fired boiler': cte.BOILER,
@ -31,4 +33,8 @@ class MontrealSystemToHubEnergyGenerationSystem:
@property @property
def dictionary(self) -> dict: def dictionary(self) -> dict:
"""
Get the dictionary
:return: {}
"""
return self._dictionary return self._dictionary

View File

@ -59,6 +59,10 @@ class LoadsCalculation:
return load_ventilation return load_ventilation
def get_heating_transmitted_load(self, ambient_temperature, ground_temperature): def get_heating_transmitted_load(self, ambient_temperature, ground_temperature):
"""
Calculates the heating transmitted load
:return: int
"""
heating_load_transmitted = 0 heating_load_transmitted = 0
for internal_zone in self._building.internal_zones: for internal_zone in self._building.internal_zones:
for thermal_zone in internal_zone.thermal_zones: for thermal_zone in internal_zone.thermal_zones:
@ -68,6 +72,10 @@ class LoadsCalculation:
return heating_load_transmitted return heating_load_transmitted
def get_cooling_transmitted_load(self, ambient_temperature, ground_temperature): def get_cooling_transmitted_load(self, ambient_temperature, ground_temperature):
"""
Calculates the cooling transmitted load
:return: int
"""
cooling_load_transmitted = 0 cooling_load_transmitted = 0
for internal_zone in self._building.internal_zones: for internal_zone in self._building.internal_zones:
for thermal_zone in internal_zone.thermal_zones: for thermal_zone in internal_zone.thermal_zones:
@ -77,6 +85,10 @@ class LoadsCalculation:
return cooling_load_transmitted return cooling_load_transmitted
def get_heating_ventilation_load_sensible(self, ambient_temperature): def get_heating_ventilation_load_sensible(self, ambient_temperature):
"""
Calculates the heating ventilation load sensible
:return: int
"""
heating_ventilation_load = 0 heating_ventilation_load = 0
for internal_zone in self._building.internal_zones: for internal_zone in self._building.internal_zones:
for thermal_zone in internal_zone.thermal_zones: for thermal_zone in internal_zone.thermal_zones:
@ -85,6 +97,10 @@ class LoadsCalculation:
return heating_ventilation_load return heating_ventilation_load
def get_cooling_ventilation_load_sensible(self, ambient_temperature): def get_cooling_ventilation_load_sensible(self, ambient_temperature):
"""
Calculates the cooling ventilation load sensible
:return: int
"""
cooling_ventilation_load = 0 cooling_ventilation_load = 0
for internal_zone in self._building.internal_zones: for internal_zone in self._building.internal_zones:
for thermal_zone in internal_zone.thermal_zones: for thermal_zone in internal_zone.thermal_zones:
@ -93,6 +109,10 @@ class LoadsCalculation:
return cooling_ventilation_load return cooling_ventilation_load
def get_internal_load_sensible(self): def get_internal_load_sensible(self):
"""
Calculates the internal load sensible
:return: int
"""
cooling_load_occupancy_sensible = 0 cooling_load_occupancy_sensible = 0
cooling_load_lighting = 0 cooling_load_lighting = 0
cooling_load_equipment_sensible = 0 cooling_load_equipment_sensible = 0
@ -113,6 +133,10 @@ class LoadsCalculation:
return internal_load return internal_load
def get_radiation_load(self, irradiance_format, hour): def get_radiation_load(self, irradiance_format, hour):
"""
Calculates the radiation load
:return: int
"""
cooling_load_radiation = 0 cooling_load_radiation = 0
for internal_zone in self._building.internal_zones: for internal_zone in self._building.internal_zones:
for thermal_zone in internal_zone.thermal_zones: for thermal_zone in internal_zone.thermal_zones: