77 lines
2.9 KiB
Python
77 lines
2.9 KiB
Python
import configuration as c
|
|
import xmltodict
|
|
import json
|
|
from urllib.request import urlopen
|
|
|
|
def process_formula(formula, hdd):
|
|
formula = formula.replace('( hdd < ', '').replace(') ', '').split(':')
|
|
for equation in formula:
|
|
values = equation.split('? ')
|
|
if len(values) == 2:
|
|
if float(values[0]) > hdd:
|
|
return float(values[1])
|
|
else:
|
|
return float(equation)
|
|
|
|
def create_virtual_no_mass_material(u_value, name, materials, construction):
|
|
r_value = 0
|
|
for key in construction:
|
|
if key != 'virtual_no_mass':
|
|
material_thickness = construction[key]
|
|
for material in materials:
|
|
if key in material.keys():
|
|
print(material[key]['conductivity'])
|
|
material_conductivity = material[key]['conductivity']
|
|
r_value += (material_thickness/material_conductivity)
|
|
r_value = 1/u_value - r_value
|
|
new_virtual_no_mass_material = {
|
|
name: {
|
|
"no_mass": True,
|
|
"thermal_resistance": r_value
|
|
}
|
|
}
|
|
materials.append(new_virtual_no_mass_material)
|
|
|
|
|
|
with open(c.nrcan_urls, 'r') as f:
|
|
urls = xmltodict.parse(f.read(), force_list=['standard'])
|
|
|
|
base_url_construction = urls['nrcan']['@base_url_construction']
|
|
dictionary = {"opaque_surfaces": []}
|
|
no_mass_index = 0
|
|
materials = c.materials['materials']
|
|
for standard in urls['nrcan']['standards_per_period']['standard']:
|
|
constructions_location = standard['constructions_location']
|
|
url = f'{base_url_construction}/{constructions_location}'
|
|
_json = json.loads(urlopen(url).read())
|
|
for climate_zone in c.hdd_canadian_climate_zones.keys():
|
|
for table in _json['tables']['surface_thermal_transmittance']['table']:
|
|
if table['surface'] in c.opaque_surfaces:
|
|
u_value = process_formula(table['formula'], c.hdd_canadian_climate_zones[climate_zone])
|
|
layers = {}
|
|
construction = c.surface_types[table['surface']][c.heavy_light[standard["@period_of_construction"]]]
|
|
for key in construction:
|
|
if key != 'virtual_no_mass':
|
|
layers[key] = construction[key]
|
|
else:
|
|
material_name = f'virtual_no_mass_{no_mass_index}'
|
|
layers[material_name] = 0
|
|
no_mass_index += 1
|
|
create_virtual_no_mass_material(u_value,material_name, materials, construction)
|
|
opaque_surface = {
|
|
"opaque_surface": {
|
|
"name": f'{standard["@period_of_construction"]}_{climate_zone}',
|
|
"period_of_construction": f'{standard["@period_of_construction"]}',
|
|
"climate_zone": f'{climate_zone}',
|
|
"type": f"{table['boundary_condition']}{table['surface']}",
|
|
"u_value": u_value,
|
|
"layers": layers
|
|
}
|
|
}
|
|
dictionary['opaque_surfaces'].append(
|
|
opaque_surface
|
|
)
|
|
output_dictionary = {"opaque_surfaces": dictionary['opaque_surfaces'], "materials": materials}
|
|
with open(f'{c.output_path}/opaque_surfaces.json', 'w') as f:
|
|
json.dump(output_dictionary, f, indent=2)
|