Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create compsets heron function 2 #19

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/heron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to open the file using a with statement as mentioned here: https://pylint.readthedocs.io/en/latest/user_guide/messages/refactor/consider-using-with.html

except json.JSONDecodeError as e:
raise ValueError(f"The content of {textfile_path} is not in proper JSON format and cannot be read")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good, you may want to add a from e at the end of this line. this ensures that your error message appears as well as the original JSON error (more info: https://docs.python.org/3/tutorial/errors.html#exception-chaining)

comp_set_name = comp_set_dict.get('Component Set Name')

ref_driver = comp_set_dict.get('Reference Driver')
Expand Down Expand Up @@ -90,10 +93,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}"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@
<driver>
<variable>BOP2_capacity</variable>
</driver>
<scaling_factor_x>
<fixed_value>0.692</fixed_value>
</scaling_factor_x>
<!-- Some of this component cashFlow info are imported from: Sets1//componentSet_turbines.txt-->
<reference_driver>
<fixed_value>26.4222377835452</fixed_value>
Expand Down
Loading