Compare commits
8 Commits
591107f8cf
...
10acb712f1
Author | SHA1 | Date | |
---|---|---|---|
|
10acb712f1 | ||
|
44aed37ef4 | ||
|
ac0c4ea186 | ||
7092e75a52 | |||
42a0d3887c | |||
|
a72e0d11fd | ||
53ae043d63 | |||
8ce25e7956 |
|
@ -23,51 +23,30 @@ class DBFactory:
|
||||||
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)
|
||||||
|
|
||||||
def get_city(self, city_id):
|
def city_by_id(self, city_id):
|
||||||
"""
|
"""
|
||||||
Retrieve a single city from postgres
|
Retrieve a single city using the id
|
||||||
:param city_id: the id of the city to get
|
:param city_id: the id of the city to get
|
||||||
"""
|
"""
|
||||||
return self._city.get_by_id(city_id)
|
return self._city.get_by_id(city_id)
|
||||||
|
|
||||||
def get_city_by_name(self, city_name):
|
def cities_by_user(self, user_id):
|
||||||
"""
|
|
||||||
Retrieve a single city from postgres
|
|
||||||
:param city_name: the name of the city to get
|
|
||||||
"""
|
|
||||||
return self._city.get_by_name(city_name)
|
|
||||||
|
|
||||||
def get_city_by_user(self, user_id):
|
|
||||||
"""
|
"""
|
||||||
Retrieve cities created by user
|
Retrieve cities created by user
|
||||||
:param user_id: the id of the user
|
:param user_id: the id of the user
|
||||||
"""
|
"""
|
||||||
return self._city.get_by_user(user_id)
|
return self._city.get_by_user(user_id)
|
||||||
|
|
||||||
def get_simulation_results_by_id(self, sim_id):
|
def simulation_results_by_city_id(self, city_id):
|
||||||
"""
|
"""
|
||||||
Retrieve a single simulation results
|
Retrieve all simulation results for the given city
|
||||||
:param sim_id: the id of the simulation results to get
|
|
||||||
"""
|
|
||||||
return self._simulation_results.get_simulation_results_by_id(sim_id)
|
|
||||||
|
|
||||||
def get_simulation_results_by_name(self, name):
|
|
||||||
"""
|
|
||||||
Retrieve a single simulation results
|
|
||||||
:param name: the name of the simulation results to get
|
|
||||||
"""
|
|
||||||
return self._simulation_results.get_simulation_results_by_name(name)
|
|
||||||
|
|
||||||
def get_simulation_results_by_city_id(self, city_id):
|
|
||||||
"""
|
|
||||||
Retrieve a single simulation results
|
|
||||||
:param city_id: the city id of the simulation results to get
|
:param city_id: the city id of the simulation results to get
|
||||||
"""
|
"""
|
||||||
return self._simulation_results.get_simulation_results_by_city_id(city_id)
|
return self._simulation_results.get_simulation_results_by_city_id(city_id)
|
||||||
|
|
||||||
def get_simulation_results_by_city_object_id(self, city_object_id):
|
def simulation_results_by_city_object_id(self, city_object_id):
|
||||||
"""
|
"""
|
||||||
Retrieve a single simulation results
|
Retrieve all simulation results for the given object_id
|
||||||
:param city_object_id: the city object id of the simulation results to get
|
:param city_object_id: the city object id of the simulation results to get
|
||||||
"""
|
"""
|
||||||
return self._simulation_results.get_simulation_results_by_city_object_id(city_object_id)
|
return self._simulation_results.get_simulation_results_by_city_object_id(city_object_id)
|
||||||
|
@ -84,3 +63,4 @@ class DBFactory:
|
||||||
def building_info(self, name, city_id):
|
def building_info(self, name, city_id):
|
||||||
return self._city_object.get_by_name_and_city(name, city_id)
|
return self._city_object.get_by_name_and_city(name, city_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@ from hub.city_model_structure.attributes.polygon import Polygon
|
||||||
from hub.city_model_structure.attributes.polyhedron import Polyhedron
|
from hub.city_model_structure.attributes.polyhedron import Polyhedron
|
||||||
from hub.helpers.location import Location
|
from hub.helpers.location import Location
|
||||||
|
|
||||||
from PIL import Image
|
|
||||||
|
|
||||||
|
|
||||||
class MapPoint:
|
class MapPoint:
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
|
@ -63,7 +61,7 @@ class GeometryHelper:
|
||||||
return MapPoint(((city.upper_corner[0] - coordinate[0]) * 0.5), ((city.upper_corner[1] - coordinate[1]) * 0.5))
|
return MapPoint(((city.upper_corner[0] - coordinate[0]) * 0.5), ((city.upper_corner[1] - coordinate[1]) * 0.5))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def city_mapping(city, building_names=None, plot=False):
|
def city_mapping(city, building_names=None):
|
||||||
"""
|
"""
|
||||||
Returns a shared_information dictionary like
|
Returns a shared_information dictionary like
|
||||||
|
|
||||||
|
@ -80,7 +78,7 @@ class GeometryHelper:
|
||||||
map_info = [[{} for _ in range(y + 1)] for _ in range(x + 1)]
|
map_info = [[{} for _ in range(y + 1)] for _ in range(x + 1)]
|
||||||
for building_name in building_names:
|
for building_name in building_names:
|
||||||
building = city.city_object(building_name)
|
building = city.city_object(building_name)
|
||||||
shared_information[building_name]: []
|
lines_information[building_name]: []
|
||||||
line = 0
|
line = 0
|
||||||
for ground in building.grounds:
|
for ground in building.grounds:
|
||||||
length = len(ground.perimeter_polygon.coordinates) - 1
|
length = len(ground.perimeter_polygon.coordinates) - 1
|
||||||
|
|
|
@ -78,7 +78,7 @@ class NrelPhysicsParameters:
|
||||||
construction_period_limits = building_archetype.construction_period.split(' - ')
|
construction_period_limits = building_archetype.construction_period.split(' - ')
|
||||||
if construction_period_limits[1] == 'PRESENT':
|
if construction_period_limits[1] == 'PRESENT':
|
||||||
construction_period_limits[1] = 3000
|
construction_period_limits[1] = 3000
|
||||||
if int(construction_period_limits[0]) <= year_of_constructionF < int(construction_period_limits[1]):
|
if int(construction_period_limits[0]) <= year_of_construction < int(construction_period_limits[1]):
|
||||||
if (str(function) == str(building_archetype.function)) and \
|
if (str(function) == str(building_archetype.function)) and \
|
||||||
(climate_zone == str(building_archetype.climate_zone)):
|
(climate_zone == str(building_archetype.climate_zone)):
|
||||||
return building_archetype
|
return building_archetype
|
||||||
|
|
|
@ -18,9 +18,9 @@ class TestConstructionCatalog(TestCase):
|
||||||
constructions = catalog.names('constructions')
|
constructions = catalog.names('constructions')
|
||||||
windows = catalog.names('windows')
|
windows = catalog.names('windows')
|
||||||
materials = catalog.names('materials')
|
materials = catalog.names('materials')
|
||||||
self.assertEqual(24, len(constructions['constructions']))
|
self.assertEqual(33, len(constructions['constructions']))
|
||||||
self.assertEqual(4, len(windows['windows']))
|
self.assertEqual(5, len(windows['windows']))
|
||||||
self.assertEqual(19, len(materials['materials']))
|
self.assertEqual(33, len(materials['materials']))
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
catalog.names('unknown')
|
catalog.names('unknown')
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ class TestDBFactory(TestCase):
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
# Create test database
|
# Create test database
|
||||||
repo = Repository(db_name='test_db', app_env='TEST', dotenv_path='/usr/local/etc/hub/.env')
|
env = '/usr/local/etc/hub/.env'
|
||||||
|
repo = Repository(db_name='test_db', app_env='TEST', dotenv_path=env)
|
||||||
eng = create_engine(f'postgresql://{repo.configuration.get_db_user()}@/{repo.configuration.get_db_user()}')
|
eng = create_engine(f'postgresql://{repo.configuration.get_db_user()}@/{repo.configuration.get_db_user()}')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -53,9 +54,9 @@ class TestDBFactory(TestCase):
|
||||||
|
|
||||||
city_file = "tests_data/C40_Final.gml"
|
city_file = "tests_data/C40_Final.gml"
|
||||||
cls.city = GeometryFactory('citygml', city_file).city
|
cls.city = GeometryFactory('citygml', city_file).city
|
||||||
cls._db_factory = DBFactory(db_name='test_db', app_env='TEST', dotenv_path='../.env')
|
cls._db_factory = DBFactory(db_name='test_db', app_env='TEST', dotenv_path=env)
|
||||||
cls._export_db_factory = ExportDBFactory(db_name='test_db', app_env='TEST', dotenv_path='../.env')
|
cls._export_db_factory = ExportDBFactory(db_name='test_db', app_env='TEST', dotenv_path=env)
|
||||||
user_factory = UserFactory(db_name='test_db', app_env='TEST', dotenv_path='../.env')
|
user_factory = UserFactory(db_name='test_db', app_env='TEST', dotenv_path=env)
|
||||||
cls.unique_id = str(uuid.uuid4())
|
cls.unique_id = str(uuid.uuid4())
|
||||||
cls.application = cls._db_factory.persist_application("test", "test application", cls.unique_id)
|
cls.application = cls._db_factory.persist_application("test", "test application", cls.unique_id)
|
||||||
cls._user = user_factory.create_user("Admin", cls.application.id, "Admin@123", UserRoles.Admin)
|
cls._user = user_factory.create_user("Admin", cls.application.id, "Admin@123", UserRoles.Admin)
|
||||||
|
|
|
@ -119,9 +119,6 @@ class TestGeometryFactory(TestCase):
|
||||||
self.assertIsNotNone(city, 'city is none')
|
self.assertIsNotNone(city, 'city is none')
|
||||||
self.assertTrue(len(city.buildings) == 36)
|
self.assertTrue(len(city.buildings) == 36)
|
||||||
i = 0
|
i = 0
|
||||||
for building in city.buildings:
|
|
||||||
self.assertIsNot(building.volume, inf, 'open volume')
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
def test_import_obj(self):
|
def test_import_obj(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,125 +0,0 @@
|
||||||
"""
|
|
||||||
Test EnergySystemsFactory and various heatpump models
|
|
||||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
||||||
Copyright © 2022 Concordia CERC group
|
|
||||||
Project Coder Peter Yefi peteryefi@gmail.com
|
|
||||||
"""
|
|
||||||
from unittest import TestCase
|
|
||||||
from hub.imports.geometry_factory import GeometryFactory
|
|
||||||
from hub.imports.energy_systems_factory import EnergySystemsFactory
|
|
||||||
from hub.exports.energy_systems_factory import EnergySystemsExportFactory
|
|
||||||
from hub.imports.db_factory import DBFactory
|
|
||||||
from hub.exports.db_factory import DBFactory as ExportDBFactory
|
|
||||||
from hub.persistence.base_repo import BaseRepo
|
|
||||||
from sqlalchemy import create_engine
|
|
||||||
from hub.persistence.models import City
|
|
||||||
from hub.persistence.models import SimulationTypes
|
|
||||||
from hub.persistence.models import HeatPumpTypes
|
|
||||||
from hub.persistence.models import HeatPumpSimulation
|
|
||||||
from hub.persistence.models import User
|
|
||||||
from sqlalchemy.exc import ProgrammingError
|
|
||||||
from hub.imports.user_factory import UserFactory
|
|
||||||
from hub.persistence.models import UserRoles
|
|
||||||
|
|
||||||
# User defined paramenters
|
|
||||||
hp_sim_data = {
|
|
||||||
'StartYear': 2020,
|
|
||||||
'EndYear': 2021,
|
|
||||||
'MaximumHPEnergyInput': 8000,
|
|
||||||
'HoursOfStorageAtMaxDemand': 1,
|
|
||||||
'BuildingSuppTemp': 40,
|
|
||||||
'TemperatureDifference': 15,
|
|
||||||
'FuelLHV': 47100,
|
|
||||||
'FuelPrice': 0.12,
|
|
||||||
'FuelEF': 1887,
|
|
||||||
'FuelDensity': 0.717,
|
|
||||||
'HPSupTemp': 60
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class TestHeatPumpSimulation(TestCase):
|
|
||||||
"""
|
|
||||||
Heat pump simulation test cases
|
|
||||||
"""
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls) -> None:
|
|
||||||
"""
|
|
||||||
Test setup
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
repo = BaseRepo(db_name='test_db', app_env='TEST', dotenv_path='../.env')
|
|
||||||
eng = create_engine(f'postgresql://{repo.config.get_db_user()}@/{repo.config.get_db_user()}')
|
|
||||||
|
|
||||||
try:
|
|
||||||
conn = eng.connect()
|
|
||||||
conn.execute('commit')
|
|
||||||
conn.execute('DROP DATABASE test_db')
|
|
||||||
conn.close()
|
|
||||||
except ProgrammingError as err:
|
|
||||||
print(f'Database does not exist. Nothing to delete')
|
|
||||||
|
|
||||||
cnn = eng.connect()
|
|
||||||
cnn.execute('commit')
|
|
||||||
cnn.execute("CREATE DATABASE test_db")
|
|
||||||
cnn.close()
|
|
||||||
|
|
||||||
# Create test tables if they do not exit
|
|
||||||
User.__table__.create(bind=repo.engine, checkfirst=True)
|
|
||||||
City.__table__.create(bind=repo.engine, checkfirst=True)
|
|
||||||
HeatPumpSimulation.__table__.create(bind=repo.engine, checkfirst=True)
|
|
||||||
|
|
||||||
|
|
||||||
city_file = "tests_data/C40_Final.gml"
|
|
||||||
cls._city = GeometryFactory('citygml', city_file).city
|
|
||||||
EnergySystemsFactory('air source hp', cls._city).enrich()
|
|
||||||
|
|
||||||
cls._db_factory = DBFactory(db_name='test_db', app_env='TEST', dotenv_path='../.env')
|
|
||||||
cls._export_db_factory = ExportDBFactory(db_name='test_db', app_env='TEST', dotenv_path='../.env')
|
|
||||||
user_factory = UserFactory(db_name='test_db', app_env='TEST', dotenv_path='../.env')
|
|
||||||
cls._user = user_factory.create_user("Admin", "admin@hub.com", "Admin@123", UserRoles.Admin)
|
|
||||||
|
|
||||||
def test_heat_pump_simulation_persistence(self):
|
|
||||||
output = EnergySystemsExportFactory(city=self._city, user_input=hp_sim_data, hp_model='018',
|
|
||||||
output_path=None, sim_type=1).export()
|
|
||||||
hp_sim_data["HeatPumpModel"] = '018'
|
|
||||||
hp_sim_data["SimulationType"] = SimulationTypes.Parallel
|
|
||||||
hp_sim_data["HeatPumpType"] = HeatPumpTypes.Air
|
|
||||||
hp_sim_data["HourlyElectricityDemand"] = output["hourly_electricity_demand"]
|
|
||||||
hp_sim_data["DailyElectricityDemand"] = output["daily_electricity_demand"]
|
|
||||||
hp_sim_data["MonthlyElectricityDemand"] = output["monthly_electricity_demand"]
|
|
||||||
hp_sim_data["DailyFossilFuelConsumption"] = output["daily_fossil_consumption"]
|
|
||||||
hp_sim_data["MonthlyFossilFuelConsumption"] = output["monthly_fossil_consumption"]
|
|
||||||
|
|
||||||
saved_city = self._db_factory.persist_city(self._user.id, self._city)
|
|
||||||
hp_sim = self._db_factory.persist_hp_simulation(hp_sim_data, saved_city.id)
|
|
||||||
self.assertEqual(hp_sim.heat_pump_type, HeatPumpTypes.Air)
|
|
||||||
self.assertEqual(hp_sim.simulation_type, SimulationTypes.Parallel)
|
|
||||||
self.assertEqual(hp_sim.fuel_efficiency, hp_sim_data["FuelEF"])
|
|
||||||
self.assertEqual(hp_sim.monthly_electricity_demand, output["monthly_electricity_demand"])
|
|
||||||
self._db_factory.delete_hp_simulation(hp_sim.id)
|
|
||||||
self._db_factory.delete_city(saved_city.id)
|
|
||||||
|
|
||||||
def test_get_heat_pump_simulation_by_city(self):
|
|
||||||
output = EnergySystemsExportFactory(city=self._city, user_input=hp_sim_data, hp_model='012',
|
|
||||||
output_path=None, sim_type=0).export()
|
|
||||||
hp_sim_data["HeatPumpModel"] = '012'
|
|
||||||
hp_sim_data["SimulationType"] = SimulationTypes.Series
|
|
||||||
hp_sim_data["HeatPumpType"] = HeatPumpTypes.Air
|
|
||||||
hp_sim_data["HourlyElectricityDemand"] = output["hourly_electricity_demand"]
|
|
||||||
hp_sim_data["DailyElectricityDemand"] = output["daily_electricity_demand"]
|
|
||||||
hp_sim_data["MonthlyElectricityDemand"] = output["monthly_electricity_demand"]
|
|
||||||
hp_sim_data["DailyFossilFuelConsumption"] = output["daily_fossil_consumption"]
|
|
||||||
hp_sim_data["MonthlyFossilFuelConsumption"] = output["monthly_fossil_consumption"]
|
|
||||||
|
|
||||||
saved_city = self._db_factory.persist_city(self._user.id, self._city)
|
|
||||||
self._db_factory.persist_hp_simulation(hp_sim_data, saved_city.id)
|
|
||||||
|
|
||||||
# retrieved saved simulation by city id
|
|
||||||
hp_sim = self._export_db_factory.get_hp_simulation_by_city(saved_city.id)
|
|
||||||
self.assertEqual(hp_sim[0].heat_pump_type, HeatPumpTypes.Air)
|
|
||||||
self.assertEqual(hp_sim[0].simulation_type, SimulationTypes.Series)
|
|
||||||
self.assertEqual(hp_sim[0].fuel_price, hp_sim_data["FuelPrice"])
|
|
||||||
self.assertEqual(hp_sim[0].hourly_electricity_demand, output["hourly_electricity_demand"])
|
|
||||||
self._db_factory.delete_hp_simulation(hp_sim[0].id)
|
|
||||||
self._db_factory.delete_city(saved_city.id)
|
|
||||||
|
|
|
@ -108,7 +108,6 @@ class TestUsageFactory(TestCase):
|
||||||
self.assertIsNotNone(occupancy.sensible_radiative_internal_gain,
|
self.assertIsNotNone(occupancy.sensible_radiative_internal_gain,
|
||||||
'occupancy sensible radiant internal gain is none')
|
'occupancy sensible radiant internal gain is none')
|
||||||
self.assertIsNotNone(occupancy.occupancy_schedules, 'occupancy schedule is none')
|
self.assertIsNotNone(occupancy.occupancy_schedules, 'occupancy schedule is none')
|
||||||
self.assertIsNone(occupancy.occupants, 'occupancy density is not none')
|
|
||||||
self.assertIsNotNone(usage.lighting, 'lighting is none')
|
self.assertIsNotNone(usage.lighting, 'lighting is none')
|
||||||
lighting = usage.lighting
|
lighting = usage.lighting
|
||||||
self.assertIsNotNone(lighting.density, 'lighting density is none')
|
self.assertIsNotNone(lighting.density, 'lighting density is none')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user