Commit 7fadbca4 authored by Eric Duminil's avatar Eric Duminil
Browse files

Run template

parent ece8acd3
...@@ -101,10 +101,7 @@ def check_paths(repo_path: Path, workflow_path: Path): ...@@ -101,10 +101,7 @@ def check_paths(repo_path: Path, workflow_path: Path):
logging.debug(" * Available citygml : %s", gml.name) logging.debug(" * Available citygml : %s", gml.name)
def prepare_workflow(workflow_path, citygmls): def prepare_workflow(workflow_path: Path, citygmls: list[str]):
if isinstance(citygmls, str):
citygmls = [citygmls]
tree = et.parse(workflow_path / PARAMS) tree = et.parse(workflow_path / PARAMS)
root = tree.getroot() root = tree.getroot()
...@@ -137,8 +134,8 @@ def prepare_workflow(workflow_path, citygmls): ...@@ -137,8 +134,8 @@ def prepare_workflow(workflow_path, citygmls):
return name return name
def get_all_files(folder): def get_all_files(folder: Path) -> dict[Path, float]:
files = [f for f in Path(folder).glob('**/*') if f.is_file() and f.name != PARAMS] 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} return {f: f.stat().st_mtime for f in files}
...@@ -149,7 +146,7 @@ def simstadt_script(): ...@@ -149,7 +146,7 @@ def simstadt_script():
return './SimStadt.sh' 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) os.chdir(simstadt_path)
try: try:
logging.info("\n# Launching %s:", name) logging.info("\n# Launching %s:", name)
...@@ -166,16 +163,19 @@ def run_simstadt(simstadt_path, workflow_path, name): ...@@ -166,16 +163,19 @@ def run_simstadt(simstadt_path, workflow_path, name):
logging.info(result.stderr) 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 :") logging.info("# Listing written files :")
for result_file, modification_time in after.items(): for result_file, modification_time in after.items():
before_time = before.get(result_file, 0) before_time = before.get(result_file, 0)
if modification_time > before_time: if modification_time > before_time:
logging.info(" * '%s'", result_file.relative_to(repo_path)) logging.info(" * '%s'", result_file.relative_to(repo_path))
modified_files.append(result_file)
logging.info("\n") 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 repo_path = workflow_path.parent.parent
check_paths(repo_path, workflow_path) check_paths(repo_path, workflow_path)
...@@ -186,7 +186,7 @@ def run_workflow(simstadt_path: Path, workflow_path: Path, citygmls: list[str]): ...@@ -186,7 +186,7 @@ def run_workflow(simstadt_path: Path, workflow_path: Path, citygmls: list[str]):
run_simstadt(simstadt_path, workflow_path, name) run_simstadt(simstadt_path, workflow_path, name)
after = get_all_files(workflow_path) 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]): def main(glob: str, repo: Path, project_name: str, workflows: list[str], citygmls: list[str]):
......
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.*/' 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)) 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))
Supports Markdown
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