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

Progress on xml to son parser #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

GersonEsquivel
Copy link
Contributor

Improved automatic template generation for autocompletion mechanism. Current code also saves output files on user's specified directory.

…Current code also saves output files on user's specified directory.
Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

Not a lot of comments here. I think it looks OK so far, but anticipate a big review when it's closer to being done.

@@ -137,28 +208,45 @@ def handle_choice_element(node):
def process_schema_from_mjson(xml_string, element_name):
root = ET.fromstring(xml_string)
processed_content = process_node(root)

return {element_name: processed_content}

def integrate_detailed_schemas(final_json, processed_facilities, processed_regions, processed_institutions):
for facility_name, facility_config in processed_facilities.items():
Copy link
Member

Choose a reason for hiding this comment

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

Given all the repetition here, you could instead do:

    for agent_type, agent_list in zip(['facility', 'institution', 'region'], 
                                      [processed_facilities, processed_instutitions, processed_regions]):
        if agent_type in final_json["simulation"]:
            for agent_name, agent_config in agent_list.items():
                if agent_name in final_json["simulation"][agent_type]["config"]["ChildAtMostOne"]:
                    new_agent_config = {"InputTmpl": f'"{agent_name}", "MaxOccurs": 1}
                    new_agent_config.update(agent_config)
                    final_json["simulation"][agent_type]["config"][agent_name] = new_agent_config

child_indent = base_indent + tab

matching_keys = [key for key in annotations.keys() if key.endswith(key_name)]
matching_keys = [key for key in annotations.keys() if key.split(":")[-2] == key_name.split("_")[-3] and key.split(":")[-1] == key_name.split("_")[-1]]
Copy link
Member

Choose a reason for hiding this comment

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

I think this will be more readable if we define the following with variables first:

  • key_name.split("_")[-3]
  • key_name.split("_")[-1]

@GersonEsquivel
Copy link
Contributor Author

Done! I reduced the repetition (very nice structure), and added variables to improve readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants