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
7fadbca4
Commit
7fadbca4
authored
Apr 05, 2024
by
Eric Duminil
Browse files
Run template
parent
ece8acd3
Changes
2
Hide whitespace changes
Inline
Side-by-side
python_scripts/run_simstadt_from_python/run_simstadt_workflow.py
View file @
7fadbca4
...
...
@@ -101,10 +101,7 @@ def check_paths(repo_path: Path, workflow_path: Path):
logging
.
debug
(
" * Available citygml : %s"
,
gml
.
name
)
def
prepare_workflow
(
workflow_path
,
citygmls
):
if
isinstance
(
citygmls
,
str
):
citygmls
=
[
citygmls
]
def
prepare_workflow
(
workflow_path
:
Path
,
citygmls
:
list
[
str
]):
tree
=
et
.
parse
(
workflow_path
/
PARAMS
)
root
=
tree
.
getroot
()
...
...
@@ -137,8 +134,8 @@ def prepare_workflow(workflow_path, citygmls):
return
name
def
get_all_files
(
folder
)
:
files
=
[
f
for
f
in
Path
(
folder
)
.
glob
(
'**/*'
)
if
f
.
is_file
()
and
f
.
name
!=
PARAMS
]
def
get_all_files
(
folder
:
Path
)
->
dict
[
Path
,
float
]
:
files
=
[
f
for
f
in
folder
.
glob
(
'**/*'
)
if
f
.
is_file
()
and
f
.
name
!=
PARAMS
]
return
{
f
:
f
.
stat
().
st_mtime
for
f
in
files
}
...
...
@@ -149,7 +146,7 @@ def simstadt_script():
return
'./SimStadt.sh'
def
run_simstadt
(
simstadt_path
,
workflow_path
,
name
):
def
run_simstadt
(
simstadt_path
:
Path
,
workflow_path
:
Path
,
name
:
str
):
os
.
chdir
(
simstadt_path
)
try
:
logging
.
info
(
"
\n
# Launching %s:"
,
name
)
...
...
@@ -166,16 +163,19 @@ def run_simstadt(simstadt_path, workflow_path, name):
logging
.
info
(
result
.
stderr
)
def
compare_written_files
(
repo_path
,
before
,
after
):
def
compare_written_files
(
repo_path
:
Path
,
before
,
after
)
->
list
[
Path
]:
modified_files
=
[]
logging
.
info
(
"# Listing written files :"
)
for
result_file
,
modification_time
in
after
.
items
():
before_time
=
before
.
get
(
result_file
,
0
)
if
modification_time
>
before_time
:
logging
.
info
(
" * '%s'"
,
result_file
.
relative_to
(
repo_path
))
modified_files
.
append
(
result_file
)
logging
.
info
(
"
\n
"
)
return
modified_files
def
run_workflow
(
simstadt_path
:
Path
,
workflow_path
:
Path
,
citygmls
:
list
[
str
]):
def
run_workflow
(
simstadt_path
:
Path
,
workflow_path
:
Path
,
citygmls
:
list
[
str
])
->
list
[
Path
]
:
repo_path
=
workflow_path
.
parent
.
parent
check_paths
(
repo_path
,
workflow_path
)
...
...
@@ -186,7 +186,7 @@ def run_workflow(simstadt_path: Path, workflow_path: Path, citygmls: list[str]):
run_simstadt
(
simstadt_path
,
workflow_path
,
name
)
after
=
get_all_files
(
workflow_path
)
compare_written_files
(
repo_path
,
before
,
after
)
return
compare_written_files
(
repo_path
,
before
,
after
)
def
main
(
glob
:
str
,
repo
:
Path
,
project_name
:
str
,
workflows
:
list
[
str
],
citygmls
:
list
[
str
]):
...
...
python_scripts/run_simstadt_from_python/variable_window_ratio.py
View file @
7fadbca4
from
run_simstadt_workflow
import
find_simstadt
from
pathlib
import
Path
import
shutil
from
run_simstadt_workflow
import
find_simstadt
,
check_paths
,
SCRIPT_DIR
,
prepare_workflow
,
run_workflow
SIMSTADT2_GLOB
=
'Desktop/SimStadt2_0.*/'
REPO_PATH
=
Path
.
home
()
/
'git'
/
'simstadt2'
/
'TestRepository'
PROJECT_NAME
=
'Gruenbuehl'
CITYGMLS
=
[
'Gruenbuehl_LOD2_ALKIS_1010_2buildings.gml'
]
PROJECT_PATH
=
REPO_PATH
/
f
'
{
PROJECT_NAME
}
.proj'
PARAMS
=
'params.xml'
print
(
find_simstadt
(
SIMSTADT2_GLOB
))
TEMPLATE_NAME
=
'99_HeatDemand'
TEMPLATE
=
SCRIPT_DIR
/
'Template'
/
f
'
{
TEMPLATE_NAME
}
.flow'
# Heat demand, with custom BuildingPhysics
WORKFLOW_PATH
=
PROJECT_PATH
/
f
'
{
TEMPLATE_NAME
}
.flow'
shutil
.
copytree
(
TEMPLATE
,
WORKFLOW_PATH
,
dirs_exist_ok
=
True
)
check_paths
(
REPO_PATH
,
WORKFLOW_PATH
)
prepare_workflow
(
WORKFLOW_PATH
,
CITYGMLS
)
output_files
=
run_workflow
(
find_simstadt
(
SIMSTADT2_GLOB
),
WORKFLOW_PATH
,
CITYGMLS
)
print
(
next
(
file
for
file
in
output_files
if
'HEATING.csv'
in
file
.
name
))
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