nrcan_catalog_creator/transparent_surfaces.py

45 lines
1.7 KiB
Python
Raw Normal View History

2023-02-16 08:00:16 -05:00
import configuration as c
import xmltodict
import json
from urllib.request import urlopen
2023-02-22 05:35:30 -05:00
print('start transparent surfaces')
2023-02-16 08:00:16 -05:00
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)
with open(c.nrcan_urls, 'r') as f:
urls = xmltodict.parse(f.read(), force_list=['standard'])
base_url_construction = urls['nrcan']['@base_url_construction']
windows_dictionary = {"transparent_surfaces": []}
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.transparent_surfaces:
u_value = process_formula(table['formula'], c.hdd_canadian_climate_zones[climate_zone])
windows_dictionary['transparent_surfaces'].append(
{
2023-02-21 15:46:22 -05:00
f'{ table["surface"]}_{standard["@period_of_construction"]}_{climate_zone}': {
2023-02-16 08:00:16 -05:00
"period_of_construction": f'{standard["@period_of_construction"]}',
"climate_zone": f'{climate_zone}',
"shgc": c.shgc_for_canadian_climate_zones[climate_zone],
"type": table['surface'],
"frame_ratio": 0,
"u_value": u_value
}
})
with open(f'{c.output_path}/transparent_surfaces.json', 'w') as f:
json.dump(windows_dictionary, f, indent=2)