building info can now be retrieved via application, user and scenario
This commit is contained in:
parent
ce995c375d
commit
1abf76125f
|
@ -7,9 +7,9 @@ Project CoderPeter Yefi peteryefi@gmail.com
|
|||
import json
|
||||
from typing import Dict
|
||||
|
||||
from hub.city_model_structure.city import City
|
||||
|
||||
from hub.persistence.repositories.application import Application
|
||||
from hub.persistence.repositories.city import City as CityRepository
|
||||
from hub.persistence.repositories.city import City
|
||||
from hub.persistence.repositories.city_object import CityObject
|
||||
from hub.persistence.repositories.simulation_results import SimulationResults
|
||||
from hub.persistence.repositories.user import User
|
||||
|
@ -22,7 +22,7 @@ class DBControl:
|
|||
"""
|
||||
|
||||
def __init__(self, db_name, app_env, dotenv_path):
|
||||
self._city_repository = CityRepository(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env)
|
||||
self._city = City(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env)
|
||||
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)
|
||||
|
@ -63,7 +63,23 @@ class DBControl:
|
|||
:param application_id: Application id
|
||||
:return: [City]
|
||||
"""
|
||||
return self._city_repository.get_by_user_id_and_application_id(user_id, application_id)
|
||||
return self._city.get_by_user_id_and_application_id(user_id, application_id)
|
||||
|
||||
def building(self, name, user_id, application_id, scenario) -> CityObject:
|
||||
"""
|
||||
Retrieve the building from the database
|
||||
:param name: Building name
|
||||
:param user_id: User id
|
||||
:param application_id: Application id
|
||||
:param scenario: Scenario
|
||||
:
|
||||
"""
|
||||
cities = self._city.get_by_user_id_application_id_and_scenario(user_id, application_id, scenario)
|
||||
for city in cities:
|
||||
result = self.building_info(name, city[0].id)
|
||||
if result is not None:
|
||||
return result
|
||||
return None
|
||||
|
||||
def building_info(self, name, city_id) -> CityObject:
|
||||
"""
|
||||
|
@ -76,14 +92,14 @@ class DBControl:
|
|||
|
||||
def buildings_info(self, request_values, city_id) -> [CityObject]:
|
||||
"""
|
||||
Retrieve the building info from the database
|
||||
Retrieve the buildings info from the database
|
||||
:param request_values: Building names
|
||||
:param city_id: City ID
|
||||
:return: [CityObject]
|
||||
"""
|
||||
buildings = []
|
||||
for name in request_values['names']:
|
||||
buildings.append(self._city_object.get_by_name_or_alias_and_city(name, city_id))
|
||||
buildings.append(self.building_info(name, city_id))
|
||||
return buildings
|
||||
|
||||
def results(self, user_id, application_id, request_values, result_names=None) -> Dict:
|
||||
|
@ -99,7 +115,7 @@ class DBControl:
|
|||
results = {}
|
||||
for scenario in request_values['scenarios']:
|
||||
scenario_name = next(iter(scenario))
|
||||
result_sets = self._city_repository.get_by_user_id_application_id_and_scenario(
|
||||
result_sets = self._city.get_by_user_id_application_id_and_scenario(
|
||||
user_id,
|
||||
application_id,
|
||||
scenario_name
|
||||
|
@ -136,7 +152,7 @@ class DBControl:
|
|||
:param user_id: User who create the city
|
||||
return identity_id
|
||||
"""
|
||||
return self._city_repository.insert(city, pickle_path, scenario, application_id, user_id)
|
||||
return self._city.insert(city, pickle_path, scenario, application_id, user_id)
|
||||
|
||||
def update_city(self, city_id, city):
|
||||
"""
|
||||
|
@ -144,7 +160,7 @@ class DBControl:
|
|||
:param city_id: the id of the city to update
|
||||
:param city: the updated city object
|
||||
"""
|
||||
return self._city_repository.update(city_id, city)
|
||||
return self._city.update(city_id, city)
|
||||
|
||||
def persist_application(self, name: str, description: str, application_uuid: str):
|
||||
"""
|
||||
|
@ -214,7 +230,7 @@ class DBControl:
|
|||
Deletes a single city from the database
|
||||
:param city_id: the id of the city to get
|
||||
"""
|
||||
self._city_repository.delete(city_id)
|
||||
self._city.delete(city_id)
|
||||
|
||||
def delete_results_by_name(self, name, city_id=None, city_object_id=None):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user