parameters: (self, dir_path)
docstring: Parse and save communication info.
docstring_summary: Parse and save communication info.
docstring_tokens: Parse and save communication info .
function: def _parse_and_save(self, dir_path):
          """Parse and save communication info."""
          communication_info_cache = list()
          operators_cost_info = self._get_communication_operators_cost_info(dir_path)
          for key, value in operators_cost_info.items():
              for item in value:
                  communication_info_cache.append(item)
          communication_info_cache = self._merge_communication_info_by_step_num(communication_info_cache)
          for info in communication_info_cache:
              operators_dict = dict()
              self._parse_communication_cost(operators_cost_info, info, operators_dict)
              info.append(operators_dict)
          # Calculate device communication average.
          device_communication_average_value = self._calculate_communication_average_value(communication_info_cache)
          # Calculate operator communication average.
          operators_average_value = dict()
          for key, value in operators_cost_info.items():
              average_value = self._calculate_communication_average_value(value)
              # The symbol '-' is used to indicate that the line is average information.
              average_value.insert(0, '-')
              operators_average_value[key] = average_value
          device_communication_average_value.append(operators_average_value)
          # The symbol '-' is used to indicate that the line is average information.
          device_communication_average_value.insert(0, '-')
          with open(self._save_path, 'w', newline='') as save_file:
              csv_writer = csv.writer(save_file)
              csv_writer.writerow(self._col_names)
              for item in communication_info_cache:
                  # item[3]:link_info which is a dictionary that needs to be encoded before it is written to a CSV file.
                  # item[4]:it is a dictionary that needs to be encoded before it is written to a CSV file.
                  item[3] = json.dumps(item[3])
                  item[4] = json.dumps(item[4])
                  csv_writer.writerow(item)
              # device_communication_average_value[3]: average value for link info
              # device_communication_average_value[4]: average value for operator info
              device_communication_average_value[3] = json.dumps(device_communication_average_value[3])
              device_communication_average_value[4] = json.dumps(device_communication_average_value[4])
  
              csv_writer.writerow(device_communication_average_value)
          os.chmod(self._save_path, stat.S_IREAD | stat.S_IWRITE)
function_tokens: def _parse_and_save ( self , dir_path ) : communication_info_cache = list ( ) operators_cost_info = self . _get_communication_operators_cost_info ( dir_path ) for key , value in operators_cost_info . items ( ) : for item in value : communication_info_cache . append ( item ) communication_info_cache = self . _merge_communication_info_by_step_num ( communication_info_cache ) for info in communication_info_cache : operators_dict = dict ( ) self . _parse_communication_cost ( operators_cost_info , info , operators_dict ) info . append ( operators_dict ) # Calculate device communication average. device_communication_average_value = self . _calculate_communication_average_value ( communication_info_cache ) # Calculate operator communication average. operators_average_value = dict ( ) for key , value in operators_cost_info . items ( ) : average_value = self . _calculate_communication_average_value ( value ) # The symbol '-' is used to indicate that the line is average information. average_value . insert ( 0 , '-' ) operators_average_value [ key ] = average_value device_communication_average_value . append ( operators_average_value ) # The symbol '-' is used to indicate that the line is average information. device_communication_average_value . insert ( 0 , '-' ) with open ( self . _save_path , 'w' , newline = '' ) as save_file : csv_writer = csv . writer ( save_file ) csv_writer . writerow ( self . _col_names ) for item in communication_info_cache : # item[3]:link_info which is a dictionary that needs to be encoded before it is written to a CSV file. # item[4]:it is a dictionary that needs to be encoded before it is written to a CSV file. item [ 3 ] = json . dumps ( item [ 3 ] ) item [ 4 ] = json . dumps ( item [ 4 ] ) csv_writer . writerow ( item ) # device_communication_average_value[3]: average value for link info # device_communication_average_value[4]: average value for operator info device_communication_average_value [ 3 ] = json . dumps ( device_communication_average_value [ 3 ] ) device_communication_average_value [ 4 ] = json . dumps ( device_communication_average_value [ 4 ] ) csv_writer . writerow ( device_communication_average_value ) os . chmod ( self . _save_path , stat . S_IREAD | stat . S_IWRITE )