Compare commits
No commits in common. "d198ac91417faa80ea7d70564b723b80ba1c2cee" and "10acb712f10bc9132c6ac1e9933657e41e8d36e1" have entirely different histories.
d198ac9141
...
10acb712f1
|
@ -23,40 +23,44 @@ 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 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)
|
||||||
|
|
||||||
|
def cities_by_user(self, user_id):
|
||||||
|
"""
|
||||||
|
Retrieve cities created by user
|
||||||
|
:param user_id: the id of the user
|
||||||
|
"""
|
||||||
|
return self._city.get_by_user(user_id)
|
||||||
|
|
||||||
|
def simulation_results_by_city_id(self, city_id):
|
||||||
|
"""
|
||||||
|
Retrieve all simulation results for the given city
|
||||||
|
: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 simulation_results_by_city_object_id(self, city_object_id):
|
||||||
|
"""
|
||||||
|
Retrieve all simulation results for the given object_id
|
||||||
|
: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):
|
def application_info(self, application_uuid):
|
||||||
"""
|
|
||||||
Retrieve the application info for the given uuid
|
|
||||||
:param application_uuid: the uuid for the application
|
|
||||||
"""
|
|
||||||
return self._application.get_by_uuid(application_uuid)
|
return self._application.get_by_uuid(application_uuid)
|
||||||
|
|
||||||
|
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):
|
def user_login(self, name, password, application_uuid):
|
||||||
"""
|
|
||||||
Retrieve the user info
|
|
||||||
:param name: the user name
|
|
||||||
:param password: the user password
|
|
||||||
:param application_uuid: the application uuid
|
|
||||||
"""
|
|
||||||
return self._user.get_by_name_application_uuid_and_password(name, password, application_uuid)
|
return self._user.get_by_name_application_uuid_and_password(name, password, application_uuid)
|
||||||
|
|
||||||
def results(self, user_id, application_id, cities, result_names=[]):
|
def building_info(self, name, city_id):
|
||||||
"""
|
return self._city_object.get_by_name_and_city(name, city_id)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,10 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||||
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
"""
|
"""
|
||||||
import math
|
import math
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import requests
|
import requests
|
||||||
from trimesh import Trimesh
|
from trimesh import Trimesh
|
||||||
from trimesh import intersections
|
from trimesh import intersections
|
||||||
|
|
||||||
from hub.city_model_structure.attributes.polygon import Polygon
|
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
|
||||||
|
@ -65,8 +63,8 @@ class GeometryHelper:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def city_mapping(city, building_names=None):
|
def city_mapping(city, building_names=None):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Returns a shared_information dictionary like
|
Returns a shared_information dictionary like
|
||||||
|
|
||||||
{
|
{
|
||||||
"building_name" : [{line: 0 coordinate_1: [x,y,z], coordinate_2:[x, y, z], points: 0}]
|
"building_name" : [{line: 0 coordinate_1: [x,y,z], coordinate_2:[x, y, z], points: 0}]
|
||||||
}
|
}
|
||||||
|
@ -80,6 +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)
|
||||||
|
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
|
||||||
|
|
|
@ -109,19 +109,51 @@ class City(Repository):
|
||||||
except SQLAlchemyError as err:
|
except SQLAlchemyError as err:
|
||||||
logger.error(f'Error while fetching city: {err}')
|
logger.error(f'Error while fetching city: {err}')
|
||||||
|
|
||||||
def get_by_user_id_application_id_and_name(self, user_id, application_id, city_name):
|
def get_by_id(self, city_id: int) -> Model:
|
||||||
"""
|
"""
|
||||||
Fetch city based on the user who created it
|
Fetch a City based on the id
|
||||||
:param user_id: the user id
|
:param city_id: the city id
|
||||||
:param application_id: the application id
|
:return: a city
|
||||||
:param city_name: the city name
|
|
||||||
:return: ModelCity
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
result_set = self.session.execute(select(Model).where(Model.user_id == user_id,
|
return self.session.execute(select(Model).where(Model.id == city_id)).first()[0]
|
||||||
Model.application_id == application_id,
|
except SQLAlchemyError as err:
|
||||||
Model.name == city_name
|
logger.error(f'Error while fetching city: {err}')
|
||||||
)).first()[0]
|
|
||||||
return result_set
|
def _get_by_hub_version_and_name(self, hub_release: str, city_name: str) -> Model:
|
||||||
|
"""
|
||||||
|
Fetch a City based on the name and hub project
|
||||||
|
:param hub_release: the hub release
|
||||||
|
:param city_name: the name of the city
|
||||||
|
:return: a city
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return self.session.execute(select(Model)
|
||||||
|
.where(Model.hub_release == hub_release, Model.name == city_name)
|
||||||
|
).first()
|
||||||
|
except SQLAlchemyError as err:
|
||||||
|
logger.error(f'Error while fetching city: {err}')
|
||||||
|
|
||||||
|
def get_by_name(self, city_name: str) -> [Model]:
|
||||||
|
"""
|
||||||
|
Fetch city based on the name
|
||||||
|
:param city_name: the name of the building
|
||||||
|
:return: [ModelCity] with the provided name
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
result_set = self.session.execute(select(Model).where(Model.name == city_name))
|
||||||
|
return [building[0] for building in result_set]
|
||||||
except SQLAlchemyError as err:
|
except SQLAlchemyError as err:
|
||||||
logger.error(f'Error while fetching city by name: {err}')
|
logger.error(f'Error while fetching city by name: {err}')
|
||||||
|
|
||||||
|
def get_by_user(self, user_id: int) -> [Model]:
|
||||||
|
"""
|
||||||
|
Fetch city based on the user who created it
|
||||||
|
:param user_id: the id of the user
|
||||||
|
:return: [ModelCity] with the provided name
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
result_set = self.session.execute(select(Model).where(Model.user_id == user_id))
|
||||||
|
return [building[0] for building in result_set]
|
||||||
|
except SQLAlchemyError as err:
|
||||||
|
logger.error(f'Error while fetching city by name: {err}')
|
||||||
|
|
|
@ -44,11 +44,11 @@ class SimulationResults(Repository):
|
||||||
:return SimulationResults or Dictionary
|
:return SimulationResults or Dictionary
|
||||||
"""
|
"""
|
||||||
if city_id is not None:
|
if city_id is not None:
|
||||||
city = self._get_city(city_id)
|
city = self.get_city(city_id)
|
||||||
if city is None:
|
if city is None:
|
||||||
return {'message': f'City does not exists'}
|
return {'message': f'City does not exists'}
|
||||||
else:
|
else:
|
||||||
city_object = self._get_city_object(city_object_id)
|
city_object = self.get_city_object(city_object_id)
|
||||||
if city_object is None:
|
if city_object is None:
|
||||||
return {'message': f'City object does not exists'}
|
return {'message': f'City object does not exists'}
|
||||||
try:
|
try:
|
||||||
|
@ -114,7 +114,7 @@ class SimulationResults(Repository):
|
||||||
except SQLAlchemyError as err:
|
except SQLAlchemyError as err:
|
||||||
logger.error(f'Error while deleting application: {err}')
|
logger.error(f'Error while deleting application: {err}')
|
||||||
|
|
||||||
def _get_city(self, city_id) -> [City]:
|
def get_city(self, city_id) -> [City]:
|
||||||
"""
|
"""
|
||||||
Fetch a city object based city id
|
Fetch a city object based city id
|
||||||
:param city_id: a city identifier
|
:param city_id: a city identifier
|
||||||
|
@ -125,6 +125,28 @@ class SimulationResults(Repository):
|
||||||
except SQLAlchemyError as err:
|
except SQLAlchemyError as err:
|
||||||
logger.error(f'Error while fetching city by city_id: {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]:
|
def get_simulation_results_by_city_id(self, city_id) -> [Model]:
|
||||||
"""
|
"""
|
||||||
Fetch simulation results by name
|
Fetch simulation results by name
|
||||||
|
@ -147,7 +169,7 @@ class SimulationResults(Repository):
|
||||||
except SQLAlchemyError as err:
|
except SQLAlchemyError as err:
|
||||||
logger.error(f'Error while fetching simulation results by name: {err}')
|
logger.error(f'Error while fetching simulation results by name: {err}')
|
||||||
|
|
||||||
def _get_city_object(self, city_object_id) -> [CityObject]:
|
def get_city_object(self, city_object_id) -> [CityObject]:
|
||||||
"""
|
"""
|
||||||
Fetch a city object based city id
|
Fetch a city object based city id
|
||||||
:param city_object_id: a city object identifier
|
:param city_object_id: a city object identifier
|
||||||
|
|
Loading…
Reference in New Issue
Block a user