2022-11-15 20:48:42 -05:00
|
|
|
"""
|
|
|
|
DBFactory performs read related operations
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project CoderPeter Yefi peteryefi@gmail.com
|
|
|
|
"""
|
2023-02-02 06:12:24 -05:00
|
|
|
from hub.persistence import City
|
|
|
|
from hub.persistence import Application
|
2023-02-02 13:00:58 -05:00
|
|
|
from hub.persistence import User
|
|
|
|
from hub.persistence import CityObject
|
2023-03-03 17:19:36 -05:00
|
|
|
from hub.persistence import SimulationResults
|
2022-11-15 20:48:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
class DBFactory:
|
|
|
|
"""
|
|
|
|
DBFactory class
|
|
|
|
"""
|
|
|
|
|
2022-12-07 19:06:17 -05:00
|
|
|
def __init__(self, db_name, app_env, dotenv_path):
|
2023-02-02 06:12:24 -05:00
|
|
|
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)
|
2023-02-02 13:00:58 -05:00
|
|
|
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)
|
2022-11-15 20:48:42 -05:00
|
|
|
|
2023-03-10 14:04:00 -05:00
|
|
|
def application_info(self, application_uuid):
|
2023-03-03 17:19:36 -05:00
|
|
|
"""
|
2023-03-10 14:04:00 -05:00
|
|
|
Retrieve the application info for the given uuid
|
|
|
|
:param application_uuid: the uuid for the application
|
2023-03-03 17:19:36 -05:00
|
|
|
"""
|
2023-02-02 06:12:24 -05:00
|
|
|
return self._application.get_by_uuid(application_uuid)
|
2022-11-22 20:20:12 -05:00
|
|
|
|
2023-02-21 09:41:26 -05:00
|
|
|
def user_login(self, name, password, application_uuid):
|
2023-03-10 14:04:00 -05:00
|
|
|
"""
|
|
|
|
Retrieve the user info
|
|
|
|
:param name: the user name
|
|
|
|
:param password: the user password
|
|
|
|
:param application_uuid: the application uuid
|
|
|
|
"""
|
2023-02-21 09:41:26 -05:00
|
|
|
return self._user.get_by_name_application_uuid_and_password(name, password, application_uuid)
|
2023-02-02 13:00:58 -05:00
|
|
|
|
2023-03-10 14:04:00 -05:00
|
|
|
def results(self, user_id, application_id, cities, result_names=[]):
|
|
|
|
"""
|
|
|
|
Retrieve the simulation results for the given cities
|
|
|
|
:param user_id: the user id owning the results
|
|
|
|
:param application_id: the application id owning the results
|
|
|
|
:param cities: dictionary containing the city and building names for the results
|
|
|
|
:param result_names: if given, filter the results to the selected names
|
|
|
|
"""
|
|
|
|
results = []
|
|
|
|
for city in cities['cities'].keys():
|
|
|
|
city_id = self._city.get_by_user_id_application_id_and_name(user_id, application_id, city).id
|
|
|
|
for building_name in cities[city]:
|
|
|
|
city_object_id = self._city_object.get_by_name_and_city(building_name, city_id).id
|
|
|
|
results.append(self._simulation_results.get_simulation_results_by_city_id_city_object_id_and_names(
|
|
|
|
city_id,
|
|
|
|
city_object_id,
|
|
|
|
result_names))
|
|
|
|
return results
|
|
|
|
|
2023-02-02 13:00:58 -05:00
|
|
|
|
2023-03-10 12:13:56 -05:00
|
|
|
|