diff --git a/python_scripts/run_simstadt_from_python/run_simstadt_workflow.py b/python_scripts/run_simstadt_from_python/run_simstadt_workflow.py index 3383555a5c62f667afb9d2f63bf13aac060d8740..2a9134f3a97d573057f611110269cfcb836f8ed6 100644 --- a/python_scripts/run_simstadt_from_python/run_simstadt_workflow.py +++ b/python_scripts/run_simstadt_from_python/run_simstadt_workflow.py @@ -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]): diff --git a/python_scripts/run_simstadt_from_python/variable_window_ratio.py b/python_scripts/run_simstadt_from_python/variable_window_ratio.py index a8e683cdfb012dd69817ef44f2f6ec76d86f9dfd..91dee1f29cb844a64adabe90d848a3547fbd8589 100644 --- a/python_scripts/run_simstadt_from_python/variable_window_ratio.py +++ b/python_scripts/run_simstadt_from_python/variable_window_ratio.py @@ -1,6 +1,29 @@ -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))