Added exporters for simulation results

This commit is contained in:
Peter Yefi 2023-03-03 17:19:36 -05:00
parent c0c3dc4694
commit 9b12e3589b
2 changed files with 74 additions and 0 deletions

View File

@ -8,6 +8,7 @@ from hub.persistence import City
from hub.persistence import Application
from hub.persistence import User
from hub.persistence import CityObject
from hub.persistence import SimulationResults
class DBFactory:
@ -20,6 +21,7 @@ class DBFactory:
self._application = Application(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path)
self._user = User(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)
def get_city(self, city_id):
"""
@ -42,6 +44,34 @@ class DBFactory:
"""
return self._city.get_by_user(user_id)
def get_simulation_results_by_id(self, sim_id):
"""
Retrieve a single simulation results
: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
"""
return self._simulation_results.get_simulation_results_by_city_id(city_id)
def get_simulation_results_by_city_object_id(self, city_object_id):
"""
Retrieve a single simulation results
: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)
def application_info(self, application_uuid):
return self._application.get_by_uuid(application_uuid)

View File

@ -125,6 +125,50 @@ class SimulationResults(Repository):
except SQLAlchemyError as err:
logger.error(f'Error while fetching city by city_id: {err}')
def get_simulation_results_by_id(self, sim_id) -> [Model]:
"""
Fetch simulation results by id
:param sim_id: a simulation result identifier
:return: [Model] with the provided sim_id
"""
try:
return self.session.execute(select(Model).where(Model.id == sim_id)).first()
except SQLAlchemyError as err:
logger.error(f'Error while fetching simulation results by sim_id: {err}')
def get_simulation_results_by_name(self, name) -> [Model]:
"""
Fetch simulation results by name
:param name: the name of the simulation results
:return: [Model] with the provided name
"""
try:
return self.session.execute(select(Model).where(Model.name == name))
except SQLAlchemyError as err:
logger.error(f'Error while fetching simulation results by name: {err}')
def get_simulation_results_by_city_id(self, city_id) -> [Model]:
"""
Fetch simulation results by name
:param city_id: the id of the city
:return: [Model] with the provided city id
"""
try:
return self.session.execute(select(Model).where(Model.city_id == city_id))
except SQLAlchemyError as err:
logger.error(f'Error while fetching simulation results by name: {err}')
def get_simulation_results_by_city_object_id(self, city_object_id) -> [Model]:
"""
Fetch simulation results by name
:param city_object_id: the id of the city object
:return: [Model] with the provided city object id
"""
try:
return self.session.execute(select(Model).where(Model.city_object_id == city_object_id))
except SQLAlchemyError as err:
logger.error(f'Error while fetching simulation results by name: {err}')
def get_city_object(self, city_object_id) -> [CityObject]:
"""
Fetch a city object based city id