Commit 842bf1e8 authored by Eric Duminil's avatar Eric Duminil
Browse files

Change Window Ratio in XML

parent e789be8a
...@@ -13,6 +13,9 @@ SIMSTADT2_GLOB = 'Desktop/SimStadt2_0.*/' ...@@ -13,6 +13,9 @@ SIMSTADT2_GLOB = 'Desktop/SimStadt2_0.*/'
REPO_PATH = Path.home() / 'git' / 'simstadt2' / 'TestRepository' REPO_PATH = Path.home() / 'git' / 'simstadt2' / 'TestRepository'
PROJECT_NAME = 'Gruenbuehl' PROJECT_NAME = 'Gruenbuehl'
CITYGMLS = ['Gruenbuehl_LOD2_ALKIS_1010.gml'] CITYGMLS = ['Gruenbuehl_LOD2_ALKIS_1010.gml']
SURFACES = ['outWalls', 'pitchedRoof']
XML_LIB_URL = 'http://www.simstadt.eu/BuildingPhysicsLibraries'
NAMESPACE = {'': XML_LIB_URL}
PROJECT_PATH = REPO_PATH / f'{PROJECT_NAME}.proj' PROJECT_PATH = REPO_PATH / f'{PROJECT_NAME}.proj'
PARAMS = 'params.xml' PARAMS = 'params.xml'
...@@ -38,31 +41,46 @@ custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY ...@@ -38,31 +41,46 @@ custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY
physics_processor_params = physics_processor_step / PARAMS physics_processor_params = physics_processor_step / PARAMS
tree = et.parse(physics_processor_params) param_tree = et.parse(physics_processor_params)
root = tree.getroot() root = param_tree.getroot()
lib_node = root.find(".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string") lib_node = root.find(".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string")
lib_node.text = str(custom_library_path) lib_node.text = str(custom_library_path)
tree.write(physics_processor_params) param_tree.write(physics_processor_params)
########################################################## ##########################################################
with open(custom_library_path) as library_file: def parse_library(library_path: Path) -> et.ElementTree:
content = library_file.read() et.register_namespace('', XML_LIB_URL)
return et.parse(library_path)
lib_tree = parse_library(custom_library_path)
def set_custom_window_ratio(tree: et.ElementTree, window_ratio_node: float, export_path: Path):
root = tree.getroot()
root.find('name', NAMESPACE).text = f"Custom Physics Library with Window Ratio : {window_ratio}"
for surface in SURFACES:
for node in root.findall(f'.//{surface}', NAMESPACE):
window_ratio_node = node.find('./windowRatio', NAMESPACE)
if window_ratio_node is not None:
window_ratio_node.text = str(window_ratio)
tree.write(export_path)
for window_ratio in WINDOW_RATIOS: for window_ratio in WINDOW_RATIOS:
#################### Update lib with custom values ############################ #################### Update lib with custom values ############################
new_content = re.sub(r"<name>[\w ]+</name>", set_custom_window_ratio(lib_tree, window_ratio, custom_library_path)
f"<name>Custom Physics Library with Window Ratio : {window_ratio}</name>",
content, 1) # new_content = re.sub(r"<name>[\w ]+</name>",
# FIXME: Use et.parse instead. Because groundSurfaces shouldn't have any WindowRatio # f"<name>Custom Physics Library with Window Ratio : {window_ratio}</name>",
new_content = re.sub(r"<windowRatio>[\d\.]+</windowRatio>", # content, 1)
f"<windowRatio>{window_ratio}</windowRatio>", # # FIXME: Use et.parse instead. Because groundSurfaces shouldn't have any WindowRatio
new_content) # new_content = re.sub(r"<windowRatio>[\d\.]+</windowRatio>",
# f"<windowRatio>{window_ratio}</windowRatio>",
# new_content)
with open(custom_library_path, 'w') as library_file: # with open(custom_library_path, 'w') as library_file:
library_file.write(new_content) # library_file.write(new_content)
################################################################################# #################################################################################
output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), workflow_path, CITYGMLS) output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), workflow_path, CITYGMLS)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment