Complete implementation for the greenery catalog integration
This commit is contained in:
parent
868dfe22d5
commit
d5a4ffe0fa
|
@ -17,8 +17,7 @@ class Catalog:
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def entries(self):
|
||||
def entries(self, category=None):
|
||||
"""
|
||||
Base property to return the catalog entries
|
||||
:return: not implemented error
|
||||
|
|
|
@ -4,6 +4,8 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2022 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
"""
|
||||
|
||||
from catalogs.data_model.greenery.soil import Soil as libs_soil
|
||||
|
||||
|
||||
class Plant:
|
||||
def __init__(self, category, plant):
|
||||
|
@ -15,6 +17,9 @@ class Plant:
|
|||
self._leaf_emissivity = plant.leafEmissivity
|
||||
self._minimal_stomatal_resistance = plant.minimalStomatalResistance
|
||||
self._co2_sequestration = plant.co2Sequestration
|
||||
self._grows_on = []
|
||||
for soil in plant.growsOn:
|
||||
self._grows_on.append(libs_soil(soil))
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -71,3 +76,10 @@ class Plant:
|
|||
Get plant co2 sequestration capacity
|
||||
"""
|
||||
return self._co2_sequestration
|
||||
|
||||
@property
|
||||
def grows_on(self) -> [libs_soil]:
|
||||
"""
|
||||
Get plant compatible soils
|
||||
"""
|
||||
return self._grows_on
|
||||
|
|
|
@ -4,12 +4,12 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2022 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
"""
|
||||
|
||||
from catalogs.data_model.greenery.plant import Plant
|
||||
from catalogs.data_model.greenery.plant import Plant as libs_plant
|
||||
|
||||
class PlantPercentage(Plant):
|
||||
class PlantPercentage(libs_plant):
|
||||
|
||||
def __init__(self, percentage, plant):
|
||||
super().__init__("unknown", plant)
|
||||
def __init__(self, percentage, plant_category, plant):
|
||||
super().__init__(plant_category, plant)
|
||||
self._percentage = percentage
|
||||
|
||||
@property
|
||||
|
|
|
@ -26,6 +26,12 @@ class GreeneryCatalog(Catalog):
|
|||
resource = resource_set.get_resource(URI(str(path)))
|
||||
catalog_data: gc = resource.contents[0]
|
||||
|
||||
plants = []
|
||||
for plant_category in catalog_data.plantCategories:
|
||||
name = plant_category.name
|
||||
for plant in plant_category.plants:
|
||||
plants.append(libs_plant(name, plant))
|
||||
|
||||
vegetations = []
|
||||
for vegetation_category in catalog_data.vegetationCategories:
|
||||
name = vegetation_category.name
|
||||
|
@ -33,7 +39,12 @@ class GreeneryCatalog(Catalog):
|
|||
plant_percentages = []
|
||||
|
||||
for plant_percentage in vegetation.plants:
|
||||
plant_percentages.append(libs_pp(plant_percentage.percentage, plant_percentage.plant))
|
||||
plant_category = "Unknown"
|
||||
for plant in plants:
|
||||
if plant.name == plant_percentage.plant.name:
|
||||
plant_category = plant.category
|
||||
break
|
||||
plant_percentages.append(libs_pp(plant_percentage.percentage,plant_category, plant_percentage.plant))
|
||||
vegetations.append(libs_vegetation(name, vegetation, plant_percentages))
|
||||
plants = []
|
||||
for plant_category in catalog_data.plantCategories:
|
||||
|
@ -47,23 +58,58 @@ class GreeneryCatalog(Catalog):
|
|||
|
||||
self._data = GreeneryContent(vegetations, plants, soils)
|
||||
|
||||
@property
|
||||
def names(self):
|
||||
def names(self, category=None):
|
||||
"""
|
||||
:parm:
|
||||
Get the catalog elements names
|
||||
:parm: optional category filter
|
||||
"""
|
||||
_names = []
|
||||
if category is None:
|
||||
_names = {'vegetations': [], 'plants': [], 'soils': []}
|
||||
for vegetation in self._data.vegetations:
|
||||
_names.append(vegetation.name)
|
||||
_names['vegetations'].append(vegetation.name)
|
||||
for plant in self._data.plants:
|
||||
_names.append(plant.name)
|
||||
_names['plants'].append(plant.name)
|
||||
for soil in self._data.soils:
|
||||
_names.append(soil.name)
|
||||
_names['soils'].append(soil.name)
|
||||
else:
|
||||
_names = {category: []}
|
||||
if category == 'vegetations':
|
||||
for vegetation in self._data.vegetations:
|
||||
_names[category].append(vegetation.name)
|
||||
elif category == 'plants':
|
||||
for plant in self._data.plants:
|
||||
_names[category].append(plant.name)
|
||||
elif category == 'soils':
|
||||
for soil in self._data.soils:
|
||||
_names[category].append(soil.name)
|
||||
else:
|
||||
raise ValueError(f'Unknown category [{category}]')
|
||||
return _names
|
||||
|
||||
def get_entry(self, name):
|
||||
return 'value'
|
||||
"""
|
||||
Get one complete entry from the greenery catalog
|
||||
"""
|
||||
for entry in self._data.vegetations:
|
||||
if entry.name == name:
|
||||
return entry
|
||||
for entry in self._data.plants:
|
||||
if entry.name == name:
|
||||
return entry
|
||||
for entry in self._data.soils:
|
||||
if entry.name == name:
|
||||
return entry
|
||||
raise IndexError(f"{name} doesn't exists in the catalog")
|
||||
|
||||
@property
|
||||
def entries(self):
|
||||
pass
|
||||
def entries(self, category=None):
|
||||
if category is None:
|
||||
return self._data
|
||||
else:
|
||||
if category == 'vegetations':
|
||||
return self._data.vegetations
|
||||
elif category == 'plants':
|
||||
return self._data.plants
|
||||
elif category == 'soils':
|
||||
return self._data.soils
|
||||
else:
|
||||
raise ValueError(f'Unknown category [{category}]')
|
||||
|
|
37
unittests/test_greenery_catalog.py
Normal file
37
unittests/test_greenery_catalog.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
"""
|
||||
TestGeometryFactory test and validate the city model structure geometric parameters
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2020 Project Author 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_categories = catalog.names()
|
||||
vegetations = catalog.names('vegetations')
|
||||
plants = catalog.names('plants')
|
||||
soils = catalog.names('soils')
|
||||
self.assertTrue(len(catalog_categories) == 3)
|
||||
self.assertTrue(len(vegetations['vegetations']) == 4)
|
||||
self.assertTrue(len(plants['plants']) == 14)
|
||||
self.assertTrue(len(soils['soils']) == 6)
|
||||
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')
|
||||
|
||||
self.assertTrue(len(catalog.entries().vegetations) == 4)
|
||||
self.assertTrue(len(catalog.entries().plants) == 14)
|
||||
self.assertTrue(len(catalog.entries().soils) == 6)
|
||||
|
Loading…
Reference in New Issue
Block a user