From bf6a5711ce030ca56fae742c60402e7638755fbb Mon Sep 17 00:00:00 2001 From: guille Date: Mon, 30 Jan 2023 05:20:31 -0500 Subject: [PATCH] Small clean up --- hub_api/city_info.py | 6 +-- hub_api/config.py | 4 +- hub_api/construction.py | 76 ------------------------------- hub_api/energy_demand.py | 4 +- hub_api/helpers/session_helper.py | 73 ----------------------------- 5 files changed, 7 insertions(+), 156 deletions(-) delete mode 100644 hub_api/construction.py diff --git a/hub_api/city_info.py b/hub_api/city_info.py index 4a356aa..e0f3f3d 100644 --- a/hub_api/city_info.py +++ b/hub_api/city_info.py @@ -8,9 +8,9 @@ import json from flask import Response, request, g from flask_restful import Resource from hub_api.helpers.auth import role_required -from persistence.models import UserRoles -from hub_logger import logger -from imports.geometry_factory import GeometryFactory +from hub.persistence.models import UserRoles +from hub.hub_logger import logger +from hub.imports.geometry_factory import GeometryFactory from pathlib import Path import os from hub_api.config import Config diff --git a/hub_api/config.py b/hub_api/config.py index aa68fd3..48a8758 100644 --- a/hub_api/config.py +++ b/hub_api/config.py @@ -3,8 +3,8 @@ Config SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2023 Project Peter Yefi peteryefi@gmail.com """ -from exports.db_factory import DBFactory as CityExportFactory -from imports.db_factory import DBFactory +from hub.exports.db_factory import DBFactory as CityExportFactory +from hub.imports.db_factory import DBFactory import os import pickle diff --git a/hub_api/construction.py b/hub_api/construction.py deleted file mode 100644 index 7d371b5..0000000 --- a/hub_api/construction.py +++ /dev/null @@ -1,76 +0,0 @@ -""" -Construction -SPDX - License - Identifier: LGPL - 3.0 - or -later -Copyright © 2022 Project Author name guillermo.gutierrezmorote@concordia.ca -Code contributors: Peter Yefi peteryefi@gmail.com -""" -import json -import uuid - -from flask import Response, request -from flask_restful import Resource -from hub_api.config import Config -from city_model_structure.building_demand.layer import Layer -from city_model_structure.building_demand.material import Material -from persistence.models import UserRoles -from hub_api.helpers.auth import role_required - - -class Construction(Resource, Config): - def __init__(self): - super().__init__() - - @role_required([UserRoles.Admin.value, UserRoles.Hub_Reader.value]) - def put(self, city_id): - city = self.get_city(city_id) - try: - building_names = request.json['building_names'] - constructions = request.json['constructions'] - for construction in constructions: - construction_type = construction['type'] - layers = construction['layers'] - for building_name in building_names: - for building in city.buildings: - if building.human_readable_name != building_name: - continue - for internal_zone in building.internal_zones: - for thermal_zone in internal_zone.thermal_zones: - thermal_zone.additional_thermal_bridge_u_value = request.json['extra_loses_due_to_thermal_bridges'] - thermal_zone.indirect_heated_area_ratio = request.json['indirect_heated_ratio'] - thermal_zone.infiltration_rate_system_on = request.json['infiltration_rate_for_ventilation_system_on'] - thermal_zone.infiltration_rate_system_off = request.json['infiltration_rate_for_ventilation_system_off'] - for thermal_boundary in thermal_zone.thermal_boundaries: - if thermal_boundary.parent_surface.type == construction_type: - _layers = [] - for layer in layers: - _layer = Layer() - thermal_resistance = layer['material']['thermal_resistance'] - conductivity = layer['material']['conductivity'] - density = layer['material']['density'] - specific_heat = layer['material']['specific_heat'] - _layer.thickness = layer['thickness'] - _material = Material() - _material.id = layer['material']['id'] - _material.name = layer['material']['name'] - _material.solar_absorptance = layer['material']['solar_absorptance'] - _material.thermal_absorptance = layer['material']['thermal_absorptance'] - _material.visible_absorptance = layer['material']['visible_absorptance'] - _material.no_mass = layer['material']['no_mass'] - _material.thermal_resistance = (thermal_resistance if thermal_resistance != '' else None) - _material.conductivity = (conductivity if conductivity != '' else None) - _material.density = (density if density != '' else None) - _material.specific_heat = (specific_heat if specific_heat != '' else None) - _layer.material = _material - _layers.append(_layer) - thermal_boundary.layers = _layers - if 'window' in construction.keys(): - for thermal_opening in thermal_boundary.thermal_openings: - thermal_opening.frame_ratio = construction['window']['frame_ratio'] - thermal_opening.g_value = construction['window']['g_value'] - thermal_opening.overall_u_value = construction['window']['overall_u_value'] - response = {'result': 'succeed'} - except KeyError as ex: - response = {'error': f'Mandatory parameter {ex} is missing'} - return Response(json.dumps(response), status=400) - - return Response(json.dumps(response), status=200) diff --git a/hub_api/energy_demand.py b/hub_api/energy_demand.py index 5685c3a..ad16b83 100644 --- a/hub_api/energy_demand.py +++ b/hub_api/energy_demand.py @@ -6,10 +6,10 @@ from geomeppy import IDF import os import glob import hub_api.helpers.session_helper as sh -import helpers.constants as cte +import hub.helpers.constants as cte import csv from hub_api.helpers.auth import role_required -from persistence.models import UserRoles +from hub.persistence.models import UserRoles from hub_api.config import Config diff --git a/hub_api/helpers/session_helper.py b/hub_api/helpers/session_helper.py index 578f7c7..686e822 100644 --- a/hub_api/helpers/session_helper.py +++ b/hub_api/helpers/session_helper.py @@ -14,79 +14,6 @@ greenery_catalog = None construction_catalog = None usage_catalog = None -roofs_associated_to_percentage = {'10': ['BuildingAX5th:ZoneX56Xspace_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_1', - 'BuildingAX5th:Corridor_Roof_1_0_2', - 'BuildingAX5th:Corridor_Roof_1_0_3', - 'BuildingAX3rd:ZoneX76Xspace_Roof_1_0_0'], - '20': ['BuildingBX2nd:Airbnb2_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_1'], - '30': ['BuildingBX2nd:Airbnb_Roof_1_0_0', - 'BuildingAX5th:ZoneX53Xspace_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_0'], - '40': ['AdditionalBuildings:ZoneX73Xspace_Roof_1_0_2', - 'BuildingBX2nd:Airbnb_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_4', - 'BuildingAX5th:ZoneX54Xspace_Roof_1_0_0'], - '50': ['BuildingBX2nd:Airbnb2_Roof_1_0_0', - 'BuildingBX2nd:Airbnb_Roof_1_0_0', - 'BuildingAX5th:ZoneX53Xspace_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_1', - 'BuildingAX5th:ZoneX55Xspace_Roof_1_0_0'], - '60': ['BuildingBX2nd:Airbnb2_Roof_1_0_0', - 'BuildingBX2nd:Airbnb_Roof_1_0_0', - 'BuildingAX5th:ZoneX53Xspace_Roof_1_0_0', - 'BuildingAX5th:ZoneX54Xspace_Roof_1_0_0'], - '70': ['BuildingBX2nd:Airbnb2_Roof_1_0_0', - 'BuildingBX2nd:Airbnb_Roof_1_0_0', - 'BuildingAX5th:ZoneX56Xspace_Roof_1_0_0', - 'BuildingAX5th:ZoneX53Xspace_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_1', - 'BuildingAX5th:Corridor_Roof_1_0_2', - 'BuildingAX5th:Corridor_Roof_1_0_3', - 'BuildingAX5th:ZoneX54Xspace_Roof_1_0_0', - 'BuildingAX3rd:ZoneX76Xspace_Roof_1_0_0'], - '80': ['BuildingCX2nd:ZoneX41Xspace_Roof_1_0_0', - 'BuildingBX2nd:Corridor_Roof_1_0_0', - 'BuildingBX2nd:Airbnb2_Roof_1_0_0', - 'BuildingBX2nd:Airbnb_Roof_1_0_0', - 'BuildingAX5th:ZoneX53Xspace_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_2', - 'BuildingAX5th:Corridor_Roof_1_0_4', - 'BuildingAX5th:ZoneX54Xspace_Roof_1_0_0'], - '90': ['AdditionalBuildings:ZoneX73Xspace_Roof_1_0_0', - 'AdditionalBuildings:ZoneX73Xspace_Roof_1_0_1', - 'AdditionalBuildings:ZoneX73Xspace_Roof_1_0_2', - 'BuildingCX2nd:ZoneX41Xspace_Roof_1_0_0', - 'BuildingBX2nd:Corridor_Roof_1_0_0', - 'BuildingBX2nd:Airbnb2_Roof_1_0_0', - 'BuildingBX2nd:Airbnb_Roof_1_0_0', - 'BuildingAX5th:ZoneX53Xspace_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_4', - 'BuildingAX5th:ZoneX54Xspace_Roof_1_0_0', - 'BuildingAX5th:ZoneX55Xspace_Roof_1_0_0'], - '100': ['AdditionalBuildings:ZoneX73Xspace_Roof_1_0_0', - 'AdditionalBuildings:ZoneX73Xspace_Roof_1_0_1', - 'AdditionalBuildings:ZoneX73Xspace_Roof_1_0_2', - 'BuildingCX2nd:ZoneX41Xspace_Roof_1_0_0', - 'BuildingBX2nd:Corridor_Roof_1_0_0', - 'BuildingBX2nd:Airbnb2_Roof_1_0_0', - 'BuildingBX2nd:Airbnb_Roof_1_0_0', - 'BuildingAX5th:ZoneX56Xspace_Roof_1_0_0', - 'BuildingAX5th:ZoneX53Xspace_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_0', - 'BuildingAX5th:Corridor_Roof_1_0_1', - 'BuildingAX5th:Corridor_Roof_1_0_2', - 'BuildingAX5th:Corridor_Roof_1_0_3', - 'BuildingAX5th:Corridor_Roof_1_0_4', - 'BuildingAX5th:ZoneX54Xspace_Roof_1_0_0', - 'BuildingAX5th:ZoneX55Xspace_Roof_1_0_0', - 'BuildingAX3rd:ZoneX76Xspace_Roof_1_0_0'], - } - class SessionData: def __init__(self, session):