city_retrofit/hub/exports/db_factory.py

67 lines
2.3 KiB
Python
Raw Normal View History

"""
DBFactory performs read related operations
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project CoderPeter Yefi peteryefi@gmail.com
"""
from hub.persistence import City
from hub.persistence import Application
from hub.persistence import User
from hub.persistence import CityObject
2023-03-03 17:19:36 -05:00
from hub.persistence import SimulationResults
class DBFactory:
"""
DBFactory class
"""
2022-12-07 19:06:17 -05:00
def __init__(self, db_name, app_env, dotenv_path):
self._city = City(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path)
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)
2023-03-03 17:19:36 -05:00
self._simulation_results = SimulationResults(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env)
2023-03-10 12:13:56 -05:00
def city_by_id(self, city_id):
"""
Retrieve a single city using the id
:param city_id: the id of the city to get
"""
return self._city.get_by_id(city_id)
2023-03-10 12:13:56 -05:00
def cities_by_user(self, user_id):
2023-01-11 16:02:33 -05:00
"""
Retrieve cities created by user
:param user_id: the id of the user
"""
return self._city.get_by_user(user_id)
2023-01-11 16:02:33 -05:00
2023-03-10 12:13:56 -05:00
def simulation_results_by_city_id(self, city_id):
2023-03-03 17:19:36 -05:00
"""
2023-03-10 12:13:56 -05:00
Retrieve all simulation results for the given city
2023-03-03 17:19:36 -05:00
:param city_id: the city id of the simulation results to get
"""
return self._simulation_results.get_simulation_results_by_city_id(city_id)
2023-03-10 12:13:56 -05:00
def simulation_results_by_city_object_id(self, city_object_id):
2023-03-03 17:19:36 -05:00
"""
2023-03-10 12:13:56 -05:00
Retrieve all simulation results for the given object_id
2023-03-03 17:19:36 -05:00
: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)
2022-11-22 20:20:12 -05:00
def user_info(self, name, password, application_id):
return self._user.get_by_name_application_id_and_password(name, password, application_id)
def user_login(self, name, password, application_uuid):
return self._user.get_by_name_application_uuid_and_password(name, password, application_uuid)
def building_info(self, name, city_id):
return self._city_object.get_by_name_and_city(name, city_id)
2023-03-10 12:13:56 -05:00