small corrections
This commit is contained in:
parent
794b9e1b85
commit
486a861477
|
@ -6,6 +6,8 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||||
Code contributors: Peter Yefi peteryefi@gmail.com
|
Code contributors: Peter Yefi peteryefi@gmail.com
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import bz2
|
||||||
import sys
|
import sys
|
||||||
import pickle
|
import pickle
|
||||||
import math
|
import math
|
||||||
|
@ -267,6 +269,16 @@ class City:
|
||||||
with open(city_filename, 'wb') as file:
|
with open(city_filename, 'wb') as file:
|
||||||
pickle.dump(self, file)
|
pickle.dump(self, file)
|
||||||
|
|
||||||
|
def save_compressed(self, city_filename):
|
||||||
|
"""
|
||||||
|
Save a city into the given filename
|
||||||
|
:param city_filename: destination city filename
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
|
||||||
|
with bz2.BZ2File('bz2_test.pbz2', 'wb') as f:
|
||||||
|
pickle.dump(self, f)
|
||||||
|
|
||||||
def region(self, center, radius) -> City:
|
def region(self, center, radius) -> City:
|
||||||
"""
|
"""
|
||||||
Get a region from the city
|
Get a region from the city
|
||||||
|
|
|
@ -167,6 +167,8 @@ class InselMonthlyEnergyBalance(Insel):
|
||||||
f'inclination {np.rad2deg(surface.inclination)} (degrees)']
|
f'inclination {np.rad2deg(surface.inclination)} (degrees)']
|
||||||
|
|
||||||
if surface.type != 'Ground':
|
if surface.type != 'Ground':
|
||||||
|
if cte.MONTH not in surface.global_irradiance:
|
||||||
|
raise ValueError(f'surface: {surface.name} from building {building.name} has no global irradiance!')
|
||||||
global_irradiance = surface.global_irradiance[cte.MONTH]
|
global_irradiance = surface.global_irradiance[cte.MONTH]
|
||||||
for j in range(0, len(global_irradiance)):
|
for j in range(0, len(global_irradiance)):
|
||||||
parameters.append(f'{j + 1} {global_irradiance.at[j, radiation_calculation_method]}')
|
parameters.append(f'{j + 1} {global_irradiance.at[j, radiation_calculation_method]}')
|
||||||
|
|
|
@ -10,7 +10,7 @@ import hub.helpers.constants as cte
|
||||||
|
|
||||||
class MontrealFunctionToHubFunction:
|
class MontrealFunctionToHubFunction:
|
||||||
|
|
||||||
# Todo: "office" and "hotel/motel" need to be replaced for a constant value.
|
# Todo: "office" "Mausolée" and "hotel/motel" need to be replaced for a constant value.
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._dictionary = {
|
self._dictionary = {
|
||||||
"Administration publique municipale et régionale": "Office",
|
"Administration publique municipale et régionale": "Office",
|
||||||
|
@ -542,7 +542,14 @@ class MontrealFunctionToHubFunction:
|
||||||
"Église synagogue mosquée et temple": cte.EVENT_LOCATION,
|
"Église synagogue mosquée et temple": cte.EVENT_LOCATION,
|
||||||
"Établissement avec salle de réception ou de banquet": cte.FULL_SERVICE_RESTAURANT,
|
"Établissement avec salle de réception ou de banquet": cte.FULL_SERVICE_RESTAURANT,
|
||||||
"Établissement avec service de boissons alcoolisées (Bar)": cte.QUICK_SERVICE_RESTAURANT,
|
"Établissement avec service de boissons alcoolisées (Bar)": cte.QUICK_SERVICE_RESTAURANT,
|
||||||
"Établissement dont l'activité principale est la danse (discothèque avec service alcool boite de nuit) sans alcool code 7397": cte.QUICK_SERVICE_RESTAURANT
|
"Établissement dont l'activité principale est la danse (discothèque avec service alcool boite de nuit) sans alcool code 7397": cte.QUICK_SERVICE_RESTAURANT,
|
||||||
|
"Mausolée": cte.NON_HEATED,
|
||||||
|
"Auberge ou gîte touristique (Hôtel à caractère familial, d'au plus 3 étages en hauteur de bâtiment)": cte.HOTEL,
|
||||||
|
"Service de garderie (prématernelle, moins de 50 % de poupons)": cte.PRIMARY_SCHOOL,
|
||||||
|
"Église, synagogue, mosquée et temple": cte.CONVENTION_CENTER
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -18,14 +18,15 @@ class DBFactory:
|
||||||
self._city_repository = CityRepository(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env)
|
self._city_repository = CityRepository(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)
|
self._simulation_results = SimulationResults(db_name=db_name, dotenv_path=dotenv_path, app_env=app_env)
|
||||||
|
|
||||||
def persist_city(self, city: City, application_id: int, user_id: int):
|
def persist_city(self, city: City, pickle_path, application_id: int, user_id: int):
|
||||||
"""
|
"""
|
||||||
Persist city into postgres database
|
Persist city into postgres database
|
||||||
:param city: City to be stored
|
:param city: City to be stored
|
||||||
|
:param pickle_path: Path to save the pickle file
|
||||||
:param application_id: Application id owning this city
|
:param application_id: Application id owning this city
|
||||||
:param user_id: User who create the city
|
:param user_id: User who create the city
|
||||||
"""
|
"""
|
||||||
return self._city_repository.insert(city, application_id, user_id)
|
return self._city_repository.insert(city, pickle_path, application_id, user_id)
|
||||||
|
|
||||||
def update_city(self, city_id, city):
|
def update_city(self, city_id, city):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -134,6 +134,7 @@ class Geojson:
|
||||||
building_name = f'building_{building_id}'
|
building_name = f'building_{building_id}'
|
||||||
building_id += 1
|
building_id += 1
|
||||||
polygons = []
|
polygons = []
|
||||||
|
lod = 1
|
||||||
for part, coordinates in enumerate(geometry['coordinates']):
|
for part, coordinates in enumerate(geometry['coordinates']):
|
||||||
polygons = self._get_polygons(polygons, coordinates)
|
polygons = self._get_polygons(polygons, coordinates)
|
||||||
for zone, polygon in enumerate(polygons):
|
for zone, polygon in enumerate(polygons):
|
||||||
|
@ -142,6 +143,7 @@ class Geojson:
|
||||||
year_of_construction,
|
year_of_construction,
|
||||||
function,
|
function,
|
||||||
[polygon])
|
[polygon])
|
||||||
|
lod = 0
|
||||||
else:
|
else:
|
||||||
if self._max_z < extrusion_height:
|
if self._max_z < extrusion_height:
|
||||||
self._max_z = extrusion_height
|
self._max_z = extrusion_height
|
||||||
|
@ -154,4 +156,5 @@ class Geojson:
|
||||||
self._city = City([self._min_x, self._min_y, 0.0], [self._max_x, self._max_y, self._max_z], 'epsg:26911')
|
self._city = City([self._min_x, self._min_y, 0.0], [self._max_x, self._max_y, self._max_z], 'epsg:26911')
|
||||||
for building in buildings:
|
for building in buildings:
|
||||||
self._city.add_city_object(building)
|
self._city.add_city_object(building)
|
||||||
|
self._city.level_of_detail.geometry = lod
|
||||||
return self._city
|
return self._city
|
||||||
|
|
|
@ -17,7 +17,7 @@ class City(Models):
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'city'
|
__tablename__ = 'city'
|
||||||
id = Column(Integer, Sequence('city_id_seq'), primary_key=True)
|
id = Column(Integer, Sequence('city_id_seq'), primary_key=True)
|
||||||
city = Column(PickleType, nullable=False)
|
pickle_path = Column(String, nullable=False)
|
||||||
name = Column(String, nullable=False)
|
name = Column(String, nullable=False)
|
||||||
level_of_detail = Column(Integer, nullable=False)
|
level_of_detail = Column(Integer, nullable=False)
|
||||||
climate_file = Column(String, nullable=False)
|
climate_file = Column(String, nullable=False)
|
||||||
|
@ -27,8 +27,8 @@ class City(Models):
|
||||||
created = Column(DateTime, default=datetime.datetime.utcnow)
|
created = Column(DateTime, default=datetime.datetime.utcnow)
|
||||||
updated = Column(DateTime, default=datetime.datetime.utcnow)
|
updated = Column(DateTime, default=datetime.datetime.utcnow)
|
||||||
|
|
||||||
def __init__(self, city, name, level_of_detail, climate_file, application_id, user_id, hub_release):
|
def __init__(self, pickle_path, name, level_of_detail, climate_file, application_id, user_id, hub_release):
|
||||||
self.city = city
|
self.pickle_path = str(pickle_path)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.level_of_detail = level_of_detail
|
self.level_of_detail = level_of_detail
|
||||||
self.climate_file = climate_file
|
self.climate_file = climate_file
|
||||||
|
|
|
@ -34,17 +34,19 @@ class City(Repository):
|
||||||
cls._instance = super(City, cls).__new__(cls)
|
cls._instance = super(City, cls).__new__(cls)
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
def insert(self, city: CityHub, application_id, user_id: int) -> Union[Model, Dict]:
|
def insert(self, city: CityHub, pickle_path, application_id, user_id: int) -> Union[Model, Dict]:
|
||||||
"""
|
"""
|
||||||
Inserts a city
|
Inserts a city
|
||||||
:param city: The complete city instance
|
:param city: The complete city instance
|
||||||
|
:param pickle_path: Path to the pickle
|
||||||
:param application_id: Application id owning the instance
|
:param application_id: Application id owning the instance
|
||||||
:param user_id: User id owning the instance
|
:param user_id: User id owning the instance
|
||||||
:return: City and Dictionary
|
:return: City and Dictionary
|
||||||
"""
|
"""
|
||||||
|
city.save_compressed(pickle_path)
|
||||||
try:
|
try:
|
||||||
db_city = Model(
|
db_city = Model(
|
||||||
pickle.dumps(city),
|
pickle_path,
|
||||||
city.name,
|
city.name,
|
||||||
city.level_of_detail.geometry,
|
city.level_of_detail.geometry,
|
||||||
'None' if city.climate_file is None else str(city.climate_file),
|
'None' if city.climate_file is None else str(city.climate_file),
|
||||||
|
@ -54,6 +56,7 @@ class City(Repository):
|
||||||
|
|
||||||
self.session.add(db_city)
|
self.session.add(db_city)
|
||||||
self.session.flush()
|
self.session.flush()
|
||||||
|
self.session.commit()
|
||||||
for building in city.buildings:
|
for building in city.buildings:
|
||||||
object_usage = ''
|
object_usage = ''
|
||||||
for internal_zone in building.internal_zones:
|
for internal_zone in building.internal_zones:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user