diff --git a/tank_design/src/tube_and_wing/empirical/tank_design_tu_berlin/general/methodxmlexport.py b/tank_design/src/tube_and_wing/empirical/tank_design_tu_berlin/general/methodxmlexport.py index 1324da748583265344535c180124a2f038e3a044..b1cc6763f16e728d50832ffee74a75e58fa4713a 100644 --- a/tank_design/src/tube_and_wing/empirical/tank_design_tu_berlin/general/methodxmlexport.py +++ b/tank_design/src/tube_and_wing/empirical/tank_design_tu_berlin/general/methodxmlexport.py @@ -53,69 +53,5 @@ def method_xml_export(paths_and_names, routing_dict, data_dict, method_specific_ :raises OSError: Raised if writing to aircraft exchange file failed :return: None """ - runtime_output.print("Method-specific data are written to '" + routing_dict['module_name'] + "_results.xml'...") + runtime_output.print("XML report was generated, but no method-specific data was written.") - # Function to write data to 'cost_estimation_results.xml' - # xml_export_tree = ET.parse(path_to_results_file) - root_of_results_file = xml_export_tree.getroot() - parent = root_of_results_file.find('calculation_results') - # Add method node. - root_of_module_config_tree = paths_and_names['root_of_module_config_tree'] - method_name = root_of_module_config_tree.find('./program_settings/configuration/method_name/value').text - method_description = "Empirical method to calculate the tanks of an aircraft." - child = ET.SubElement(parent, method_name) - child.set("description", method_description) - - # Extract design mission data from 'method_specific_output_dict' and prepare ElementTree for export to - # module-specific XML. - for key, value in method_specific_output_dict.items(): - value[0] = value[0].replace('component_design', "") - - prepare_element_tree_for_module_specific_export(root_of_results_file, method_specific_output_dict, data_dict) - - # Write all parameters to export file. - try: - # Ensure proper indentation. - ET.indent(root_of_results_file, space=" ", level=0) - # Write data to file. - xml_export_tree.write(path_to_results_file) - # Exception handling for operating system error. - except OSError: - runtime_output.error('Error: Writing to aircraft exchange file failed. Program aborted!') - - -def prepare_element_tree_for_module_specific_export(root_of_results_file, specific_output_dict, data_dict): - """ Prepare ElementTree for module-specific results export. - - This function is responsible for preparing the ElementTree of the module-specific export file. - In summary, the code dynamically updates an XML structure based on a list of paths and a dictionary - ('specific_output_dict'). It ensures that the specified paths exist in the XML structure and creates the necessary - sub-elements along the way, setting attributes and text values as specified in 'specific_output_dict'. - - :param ElementTree root_of_results_file: Root of method-specific export ElementTree - :param dict specific_output_dict: Dictionary containing method-specific output data - :return: None - """ - # Call function to convert the module key parameter dict to a module dependent element tree. - module_dependent_tree = convert_dictionary_to_element_tree(data_dict['module_key_parameters_dict']) - - # Call function to create a module specific output element tree - root_of_specific_tree = create_element_tree_from_paths(specific_output_dict) - - # Iterate over all nodes in module dependent tree - for node1 in ET.ElementTree(module_dependent_tree).iter(): - # Check if the node has the 'description' attribute - if 'description' in node1.attrib: - # Iterate over all nodes in root of specific tree - for node2 in ET.ElementTree(root_of_specific_tree).iter(): - # Check if the tags match (assuming corresponding nodes have the same structure) - if node1.tag == node2.tag: - # Set the 'description' attribute in tree2 to the value from tree1 - node2.set('description', node1.get('description')) - - # Set root element of results tree to append module specific output data - calculation_results = root_of_results_file.find('calculation_results') - - # Iterate over the children of the second tree's root and append them to the first tree's <calculation_results> - for elem in root_of_specific_tree: - calculation_results.append(elem)