complete test and correct errors in construction catalog
This commit is contained in:
parent
6b86dae410
commit
d7f1b46cf5
|
@ -10,7 +10,6 @@ class Catalog:
|
|||
Catalogs base class not implemented instance of the Catalog base class, catalogs will inherit from this class.
|
||||
"""
|
||||
|
||||
@property
|
||||
def names(self, category=None):
|
||||
"""
|
||||
Base property to return the catalog entries names
|
||||
|
|
|
@ -22,41 +22,52 @@ class NrelCatalog(Catalog):
|
|||
archetypes_path = str(Path(path / 'us_archetypes.xml').resolve())
|
||||
constructions_path = str(Path(path / 'us_constructions.xml').resolve())
|
||||
with open(constructions_path) as xml:
|
||||
self._constructions = xmltodict.parse(xml.read(), force_list=('material', 'window', 'construction'))
|
||||
self._constructions = xmltodict.parse(xml.read(), force_list=('material', 'window', 'construction', 'layer'))
|
||||
with open(archetypes_path) as xml:
|
||||
self._archetypes = xmltodict.parse(xml.read(), force_list=('archetype', 'construction'))
|
||||
self._catalog_windows = []
|
||||
self._catalog_materials = []
|
||||
self._catalog_constructions = []
|
||||
self._catalog_archetypes = []
|
||||
self._catalog_windows = self._load_windows()
|
||||
self._catalog_materials = self._load_materials()
|
||||
self._catalog_constructions = self._load_constructions()
|
||||
self._catalog_archetypes = self._load_archetypes()
|
||||
|
||||
# store the full catalog data model in self._content
|
||||
self._content = Content(self._catalog_archetypes,
|
||||
self._catalog_constructions,
|
||||
self._catalog_materials,
|
||||
self._catalog_windows)
|
||||
|
||||
def _load_windows(self):
|
||||
_catalog_windows = []
|
||||
windows = self._constructions['library']['windows']['window']
|
||||
for window in windows:
|
||||
frame_ratio = window['frame_ratio']
|
||||
frame_ratio = window['frame_ratio']['#text']
|
||||
g_value = window['shgc']
|
||||
overall_u_value = float(window['conductivity']) / float(window['thickness'])
|
||||
construction_name = window['@name']
|
||||
self._catalog_windows.append(Window(frame_ratio, g_value, overall_u_value, construction_name))
|
||||
overall_u_value = float(window['conductivity']['#text']) / float(window['thickness']['#text'])
|
||||
name = window['@name']
|
||||
_catalog_windows.append(Window(frame_ratio, g_value, overall_u_value, name))
|
||||
return _catalog_windows
|
||||
|
||||
def _load_materials(self):
|
||||
_catalog_materials = []
|
||||
materials = self._constructions['library']['materials']['material']
|
||||
for material in materials:
|
||||
material_id = material['@id']
|
||||
name = material['@name']
|
||||
solar_absorptance = material['solar_absorptance']
|
||||
thermal_absorptance = material['thermal_absorptance']
|
||||
visible_absorptance = material['visible_absorptance']
|
||||
solar_absorptance = material['solar_absorptance']['#text']
|
||||
thermal_absorptance = material['thermal_absorptance']['#text']
|
||||
visible_absorptance = material['visible_absorptance']['#text']
|
||||
no_mass = True
|
||||
thermal_resistance = None,
|
||||
conductivity = None,
|
||||
density = None,
|
||||
specific_heat = None
|
||||
if material['no_mass'] == 'true':
|
||||
if 'no_mass' in material and material['no_mass'] == 'true':
|
||||
no_mass = True
|
||||
thermal_resistance = material['thermal_resistance']
|
||||
thermal_resistance = material['thermal_resistance']['#text']
|
||||
else:
|
||||
conductivity = material['conductivity']
|
||||
density = material['density']
|
||||
specific_heat = material['specific_heat']
|
||||
conductivity = material['conductivity']['#text']
|
||||
density = material['density']['#text']
|
||||
specific_heat = material['specific_heat']['#text']
|
||||
_material = Material(material_id,
|
||||
name,
|
||||
solar_absorptance,
|
||||
|
@ -67,8 +78,11 @@ class NrelCatalog(Catalog):
|
|||
conductivity,
|
||||
density,
|
||||
specific_heat)
|
||||
self._catalog_materials.append(_material)
|
||||
_catalog_materials.append(_material)
|
||||
return _catalog_materials
|
||||
|
||||
def _load_constructions(self):
|
||||
_catalog_constructions = []
|
||||
constructions = self._constructions['library']['constructions']['construction']
|
||||
for construction in constructions:
|
||||
construction_id = construction['@id']
|
||||
|
@ -77,32 +91,37 @@ class NrelCatalog(Catalog):
|
|||
layers = []
|
||||
for layer in construction['layers']['layer']:
|
||||
layer_id = layer['@id']
|
||||
name = layer['@name']
|
||||
layer_name = layer['@name']
|
||||
material_id = layer['material']
|
||||
thickness = layer['thickness']
|
||||
for material in self._materials:
|
||||
thickness = 0
|
||||
if 'thickness' in layer:
|
||||
thickness = layer['thickness']['#text']
|
||||
for material in self._catalog_materials:
|
||||
if material_id == material.id:
|
||||
layers.append(Layer(layer_id, name, material, thickness))
|
||||
layers.append(Layer(layer_id, layer_name, material, thickness))
|
||||
break
|
||||
self._catalog_constructions.append(Construction(construction_id, construction_type, name, layers))
|
||||
_catalog_constructions.append(Construction(construction_id, construction_type, name, layers))
|
||||
return _catalog_constructions
|
||||
|
||||
def _load_archetypes(self):
|
||||
_catalog_archetypes = []
|
||||
archetypes = self._archetypes['archetypes']['archetype']
|
||||
for archetype in archetypes:
|
||||
archetype_id = archetype['@id']
|
||||
function = nrel_to_function[archetype['@building_type']]
|
||||
construction_period = reference_standard_to_construction_period[archetype['reference_standard']]
|
||||
average_storey_height = archetype['average_storey_height']
|
||||
number_of_storeys = archetype['number_of_storeys']
|
||||
thermal_capacity = archetype['thermal_capacity']
|
||||
extra_loses_due_to_thermal_bridges = archetype['extra_loses_due_to_thermal_bridges']
|
||||
indirect_heated_ratio = archetype['indirect_heated_ratio']
|
||||
infiltration_rate_for_ventilation_system_off = archetype['infiltration_rate_for_ventilation_system_off']
|
||||
infiltration_rate_for_ventilation_system_on = archetype['infiltration_rate_for_ventilation_system_on']
|
||||
construction_period = reference_standard_to_construction_period[archetype['@reference_standard']]
|
||||
average_storey_height = archetype['average_storey_height']['#text']
|
||||
number_of_storeys = archetype['number_of_storeys']['#text']
|
||||
thermal_capacity = archetype['thermal_capacity']['#text']
|
||||
extra_loses_due_to_thermal_bridges = archetype['extra_loses_due_to_thermal_bridges']['#text']
|
||||
indirect_heated_ratio = archetype['indirect_heated_ratio']['#text']
|
||||
infiltration_rate_for_ventilation_system_off = archetype['infiltration_rate_for_ventilation_system_off']['#text']
|
||||
infiltration_rate_for_ventilation_system_on = archetype['infiltration_rate_for_ventilation_system_on']['#text']
|
||||
archetype_constructions = []
|
||||
for archetype_construction in archetype['constructions']['construction']:
|
||||
for construction in self._constructions:
|
||||
for construction in self._catalog_constructions:
|
||||
if construction.id == archetype_construction['@id']:
|
||||
window_ratio = archetype_construction['window_ratio']
|
||||
window_ratio = archetype_construction['window_ratio']['#text']
|
||||
window = archetype_construction['window']
|
||||
_construction = Construction(construction.id,
|
||||
construction.type,
|
||||
|
@ -111,25 +130,19 @@ class NrelCatalog(Catalog):
|
|||
window_ratio,
|
||||
window)
|
||||
archetype_constructions.append(_construction)
|
||||
self._catalog_archetypes.append(Archetype(archetype_id,
|
||||
function,
|
||||
archetype_constructions,
|
||||
construction_period,
|
||||
average_storey_height,
|
||||
number_of_storeys,
|
||||
thermal_capacity,
|
||||
extra_loses_due_to_thermal_bridges,
|
||||
indirect_heated_ratio,
|
||||
infiltration_rate_for_ventilation_system_off,
|
||||
infiltration_rate_for_ventilation_system_on))
|
||||
_catalog_archetypes.append(Archetype(archetype_id,
|
||||
function,
|
||||
archetype_constructions,
|
||||
construction_period,
|
||||
average_storey_height,
|
||||
number_of_storeys,
|
||||
thermal_capacity,
|
||||
extra_loses_due_to_thermal_bridges,
|
||||
indirect_heated_ratio,
|
||||
infiltration_rate_for_ventilation_system_off,
|
||||
infiltration_rate_for_ventilation_system_on))
|
||||
return _catalog_archetypes
|
||||
|
||||
# store the full catalog data model in self._content
|
||||
self._content = Content(self._catalog_archetypes,
|
||||
self._catalog_constructions,
|
||||
self._catalog_materials,
|
||||
self._catalog_windows)
|
||||
|
||||
@property
|
||||
def names(self, category=None):
|
||||
"""
|
||||
Get the catalog elements names
|
||||
|
|
|
@ -8,7 +8,7 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|||
from pathlib import Path
|
||||
from typing import TypeVar
|
||||
from catalogs.construction.nrel_catalog import NrelCatalog
|
||||
from catalogs.construction.nrcan_catalog import NrcanCatalog
|
||||
# from catalogs.construction.nrcan_catalog import NrcanCatalog
|
||||
Catalog = TypeVar('Catalog')
|
||||
|
||||
class ConstructionCatalogFactory:
|
||||
|
@ -28,7 +28,7 @@ class ConstructionCatalogFactory:
|
|||
"""
|
||||
Retrieve NRCAN catalog
|
||||
"""
|
||||
return NrcanCatalog(self._city, self._base_path)
|
||||
# return NrcanCatalog(self._city, self._base_path)
|
||||
|
||||
@property
|
||||
def catalog(self) -> Catalog:
|
||||
|
@ -36,4 +36,12 @@ 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._catalog_type, lambda: None)
|
||||
|
||||
@property
|
||||
def catalog_debug(self) -> Catalog:
|
||||
"""
|
||||
Enrich the city given to the class using the class given handler
|
||||
:return: Catalog
|
||||
"""
|
||||
return NrelCatalog(self._path)
|
|
@ -6,11 +6,19 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|||
"""
|
||||
|
||||
class Window:
|
||||
def __init__(self, frame_ratio, g_value, overall_u_value, construction_name):
|
||||
def __init__(self, frame_ratio, g_value, overall_u_value, name):
|
||||
self._frame_ratio = frame_ratio
|
||||
self._g_value = g_value
|
||||
self._overall_u_value = overall_u_value
|
||||
self._construction_name = construction_name
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
Get window name
|
||||
:return: str
|
||||
"""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def frame_ratio(self):
|
||||
|
@ -34,12 +42,4 @@ class Window:
|
|||
Get thermal opening overall U-value in W/m2K
|
||||
:return: float
|
||||
"""
|
||||
return self._overall_u_value
|
||||
|
||||
@property
|
||||
def construction_name(self):
|
||||
"""
|
||||
Get thermal opening construction name
|
||||
:return: str
|
||||
"""
|
||||
return self._construction_name
|
||||
return self._overall_u_value
|
33
unittests/test_construction_catalog.py
Normal file
33
unittests/test_construction_catalog.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
"""
|
||||
TestConstructionCatalog
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2022 Concordia CERC group
|
||||
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
"""
|
||||
|
||||
from unittest import TestCase
|
||||
from catalogs.construction_catalog_factory import ConstructionCatalogFactory
|
||||
|
||||
|
||||
class TestConstructionCatalog(TestCase):
|
||||
|
||||
def test_nrel_catalog(self):
|
||||
catalog = ConstructionCatalogFactory('nrel').catalog_debug
|
||||
catalog_categories = catalog.names()
|
||||
constructions = catalog.names('constructions')
|
||||
windows = catalog.names('windows')
|
||||
materials = catalog.names('materials')
|
||||
self.assertTrue(len(constructions['constructions']), 24)
|
||||
self.assertTrue(len(windows['windows']), 4)
|
||||
self.assertTrue(len(materials['materials']), 19)
|
||||
with self.assertRaises(ValueError):
|
||||
catalog.names('unknown')
|
||||
|
||||
# retrieving all the entries should not raise any exceptions
|
||||
for category in catalog_categories:
|
||||
for value in catalog_categories[category]:
|
||||
catalog.get_entry(value)
|
||||
|
||||
with self.assertRaises(IndexError):
|
||||
catalog.get_entry('unknown')
|
||||
|
|
@ -6,13 +6,12 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|||
"""
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from catalogs.greenery_catalog_factory import GreeneryCatalogFactory
|
||||
|
||||
|
||||
class TestGreeneryCatalog(TestCase):
|
||||
def test_catalog(self):
|
||||
catalog = GreeneryCatalogFactory('nrel').catalog_debug
|
||||
catalog = GreeneryCatalogFactory('nrel').catalog
|
||||
catalog_categories = catalog.names()
|
||||
vegetations = catalog.names('vegetations')
|
||||
plants = catalog.names('plants')
|
||||
|
|
Loading…
Reference in New Issue
Block a user