2023-01-10 12:12:01 -05:00
|
|
|
"""
|
|
|
|
Construction
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2022 Project Author name guillermo.gutierrezmorote@concordia.ca
|
2023-01-17 19:00:22 -05:00
|
|
|
Code contributors: Peter Yefi peteryefi@gmail.com
|
2023-01-10 12:12:01 -05:00
|
|
|
"""
|
|
|
|
import json
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
from flask import Response, request
|
|
|
|
from flask_restful import Resource
|
2023-01-17 19:00:22 -05:00
|
|
|
from hub_api.config import Config
|
2023-01-10 12:12:01 -05:00
|
|
|
from city_model_structure.building_demand.layer import Layer
|
|
|
|
from city_model_structure.building_demand.material import Material
|
2023-01-17 19:00:22 -05:00
|
|
|
from persistence.models import UserRoles
|
|
|
|
from hub_api.helpers.auth import role_required
|
2023-01-10 12:12:01 -05:00
|
|
|
|
|
|
|
|
2023-01-17 19:00:22 -05:00
|
|
|
class Construction(Resource, Config):
|
2023-01-10 12:12:01 -05:00
|
|
|
def __init__(self):
|
2023-01-17 19:00:22 -05:00
|
|
|
super().__init__()
|
2023-01-10 12:12:01 -05:00
|
|
|
|
2023-01-17 19:00:22 -05:00
|
|
|
@role_required([UserRoles.Admin.value, UserRoles.Hub_Reader.value])
|
|
|
|
def put(self, city_id):
|
|
|
|
city = self.get_city(city_id)
|
2023-01-10 12:12:01 -05:00
|
|
|
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'}
|
2023-01-17 19:00:22 -05:00
|
|
|
return Response(json.dumps(response), status=400)
|
2023-01-10 12:12:01 -05:00
|
|
|
|
2023-01-17 19:00:22 -05:00
|
|
|
return Response(json.dumps(response), status=200)
|