From ed4b282434683fdb8bfedb4107ffc341d9b0923f Mon Sep 17 00:00:00 2001 From: Caleb Sitton Date: Tue, 25 Jun 2024 11:39:38 -0600 Subject: [PATCH 1/5] Fixed cashflow updating bug --- src/heron.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/heron.py b/src/heron.py index 9b2704fe..002c38f2 100644 --- a/src/heron.py +++ b/src/heron.py @@ -90,10 +90,13 @@ def create_componentsets_in_HERON(comp_sets_folder, heron_input_xml): node.append(ET.Comment(f" Some of this component economic info are imported from: {textfile_path}")) print("The 'cashflow' subnode is found too and is updated") Cashflow_NODE_FOUND = "True" + elements_to_update = [] for subsubnode in subnode: if subsubnode.tag in ['reference_driver', 'reference_price', 'scaling_factor_x']: - subnode.remove(subsubnode) + elements_to_update.append(subsubnode) print(f"WARNING: The value of the {subsubnode.tag} is updated.") + for element in elements_to_update: + subnode.remove(element) new_cash_node = subnode new_cash_node.append(ET.Comment(f" Some of this component cashFlow info are imported from: {textfile_path}")) From df2b97e89f44efb60b6eb51f6c3a2a475b8bb3ed Mon Sep 17 00:00:00 2001 From: Caleb Sitton Date: Tue, 25 Jun 2024 11:44:05 -0600 Subject: [PATCH 2/5] Regolded output file for integration test --- .../HERON_update_withCompSets/gold/new_heron_input.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration_tests/HERON_update_withCompSets/gold/new_heron_input.xml b/tests/integration_tests/HERON_update_withCompSets/gold/new_heron_input.xml index 39b186cb..da17c115 100644 --- a/tests/integration_tests/HERON_update_withCompSets/gold/new_heron_input.xml +++ b/tests/integration_tests/HERON_update_withCompSets/gold/new_heron_input.xml @@ -181,9 +181,6 @@ BOP2_capacity - - 0.692 - 26.4222377835452 From 706f15fb6cda6a45e98de2db6c410d1dce238297 Mon Sep 17 00:00:00 2001 From: Caleb Sitton Date: Tue, 25 Jun 2024 14:59:28 -0600 Subject: [PATCH 3/5] Added checks for componentSet files in heron.py --- src/heron.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/heron.py b/src/heron.py index 002c38f2..c89778d2 100644 --- a/src/heron.py +++ b/src/heron.py @@ -56,9 +56,12 @@ def create_componentsets_in_HERON(comp_sets_folder, heron_input_xml): # Goin through the FORCE componentSets to extract relevant info for textfile in comp_set_files_list: - if textfile.startswith('componentSet'): + if textfile.startswith('componentSet') and (textfile.endswith('.json') or textfile.endswith('.txt')): textfile_path = comp_sets_folder+"/"+textfile - comp_set_dict = json.load(open(textfile_path)) + try: + comp_set_dict = json.load(open(textfile_path)) + except json.JSONDecodeError as e: + raise ValueError(f"The content of {textfile_path} is not in proper JSON format and cannot be read") comp_set_name = comp_set_dict.get('Component Set Name') ref_driver = comp_set_dict.get('Reference Driver') From 72cb3e2a902dbc3387c4dc2f17a7419fa9604414 Mon Sep 17 00:00:00 2001 From: Caleb Sitton Date: Wed, 26 Jun 2024 09:16:45 -0600 Subject: [PATCH 4/5] Regolded FullTest integration test output --- .../Aspen_HERON_FullTest/gold/new_heron_input.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration_tests/Aspen_HERON_FullTest/gold/new_heron_input.xml b/tests/integration_tests/Aspen_HERON_FullTest/gold/new_heron_input.xml index 1494e38c..ea7deb71 100644 --- a/tests/integration_tests/Aspen_HERON_FullTest/gold/new_heron_input.xml +++ b/tests/integration_tests/Aspen_HERON_FullTest/gold/new_heron_input.xml @@ -49,9 +49,6 @@ functions - - 10.0 - 2.74763868640817 From ce43d53fbf6d0749b56a3c912b57990fbb25d94c Mon Sep 17 00:00:00 2001 From: Caleb Sitton Date: Wed, 26 Jun 2024 11:29:42 -0600 Subject: [PATCH 5/5] Addressing comments --- src/heron.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/heron.py b/src/heron.py index c89778d2..3eaea7d0 100644 --- a/src/heron.py +++ b/src/heron.py @@ -59,9 +59,10 @@ def create_componentsets_in_HERON(comp_sets_folder, heron_input_xml): if textfile.startswith('componentSet') and (textfile.endswith('.json') or textfile.endswith('.txt')): textfile_path = comp_sets_folder+"/"+textfile try: - comp_set_dict = json.load(open(textfile_path)) + with open(textfile_path) as textfile_opened: + comp_set_dict = json.load(textfile_opened) except json.JSONDecodeError as e: - raise ValueError(f"The content of {textfile_path} is not in proper JSON format and cannot be read") + raise ValueError(f"The content of {textfile_path} is not in proper JSON format and cannot be read") from e comp_set_name = comp_set_dict.get('Component Set Name') ref_driver = comp_set_dict.get('Reference Driver')