Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mayer
CircularGreenSimCity
Commits
842bf1e8
Commit
842bf1e8
authored
1 year ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Change Window Ratio in XML
parent
e789be8a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_scripts/run_simstadt_from_python/variable_window_ratio.py
+32
-14
...scripts/run_simstadt_from_python/variable_window_ratio.py
with
32 additions
and
14 deletions
+32
-14
python_scripts/run_simstadt_from_python/variable_window_ratio.py
+
32
-
14
View file @
842bf1e8
...
...
@@ -13,6 +13,9 @@ SIMSTADT2_GLOB = 'Desktop/SimStadt2_0.*/'
REPO_PATH
=
Path
.
home
()
/
'git'
/
'simstadt2'
/
'TestRepository'
PROJECT_NAME
=
'Gruenbuehl'
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'
PARAMS
=
'params.xml'
...
...
@@ -38,31 +41,46 @@ custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY
physics_processor_params
=
physics_processor_step
/
PARAMS
tree
=
et
.
parse
(
physics_processor_params
)
root
=
tree
.
getroot
()
param_
tree
=
et
.
parse
(
physics_processor_params
)
root
=
param_
tree
.
getroot
()
lib_node
=
root
.
find
(
".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string"
)
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
:
content
=
library_file
.
read
()
def
parse_library
(
library_path
:
Path
)
->
et
.
ElementTree
:
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
:
#################### Update lib with custom values ############################
new_content
=
re
.
sub
(
r
"<name>[\w ]+</name>"
,
f
"<name>Custom Physics Library with Window Ratio :
{
window_ratio
}
</name>"
,
content
,
1
)
# FIXME: Use et.parse instead. Because groundSurfaces shouldn't have any WindowRatio
new_content
=
re
.
sub
(
r
"<windowRatio>[\d\.]+</windowRatio>"
,
f
"<windowRatio>
{
window_ratio
}
</windowRatio>"
,
new_content
)
set_custom_window_ratio
(
lib_tree
,
window_ratio
,
custom_library_path
)
# new_content = re.sub(r"<name>[\w ]+</name>",
# f"<name>Custom Physics Library with Window Ratio : {window_ratio}</name>",
# content, 1)
# # FIXME: Use et.parse instead. Because groundSurfaces shouldn't have any WindowRatio
# new_content = re.sub(r"<windowRatio>[\d\.]+</windowRatio>",
# f"<windowRatio>{window_ratio}</windowRatio>",
# new_content)
with
open
(
custom_library_path
,
'w'
)
as
library_file
:
library_file
.
write
(
new_content
)
#
with open(custom_library_path, 'w') as library_file:
#
library_file.write(new_content)
#################################################################################
output_files
=
run_workflow
(
find_simstadt
(
SIMSTADT2_GLOB
),
workflow_path
,
CITYGMLS
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment