nodes: 0, module; 1, function_definition; 2, function_name:preProcessForComparison; 3, parameters; 4, block; 5, identifier:results; 6, identifier:target_size; 7, identifier:size_tolerance_prct; 8, expression_statement; 9, comment:# find reference (=image most likely to match target cover ignoring factors like size and format); 10, expression_statement; 11, for_statement; 12, comment:# remove results that are only refs; 13, expression_statement; 14, comment:# remove duplicates; 15, expression_statement; 16, for_statement; 17, expression_statement; 18, if_statement; 19, if_statement; 20, return_statement; 21, comment:""" Process results to prepare them for future comparison and sorting. """; 22, assignment; 23, identifier:result; 24, identifier:results; 25, block; 26, assignment; 27, assignment; 28, identifier:result; 29, identifier:results; 30, block; 31, assignment; 32, comparison_operator:dup_count > 0; 33, block; 34, comparison_operator:reference is not None; 35, block; 36, else_clause; 37, identifier:results; 38, identifier:reference; 39, None; 40, if_statement; 41, identifier:results; 42, call; 43, identifier:no_dup_results; 44, list; 45, expression_statement; 46, for_statement; 47, if_statement; 48, identifier:dup_count; 49, binary_operator:len(results) - len(no_dup_results); 50, identifier:dup_count; 51, integer:0; 52, expression_statement; 53, expression_statement; 54, identifier:reference; 55, None; 56, expression_statement; 57, expression_statement; 58, comment:# calculate sigs; 59, expression_statement; 60, for_statement; 61, if_statement; 62, if_statement; 63, for_statement; 64, comment:# compare other results to reference; 65, for_statement; 66, block; 67, comparison_operator:result.source_quality is CoverSourceQuality.REFERENCE; 68, block; 69, identifier:list; 70, argument_list; 71, assignment; 72, identifier:result_comp; 73, identifier:results; 74, block; 75, not_operator; 76, block; 77, call; 78, call; 79, call; 80, assignment; 81, call; 82, assignment; 83, assignment; 84, identifier:result; 85, identifier:results; 86, block; 87, attribute; 88, block; 89, identifier:futures; 90, block; 91, identifier:future; 92, identifier:futures; 93, block; 94, identifier:result; 95, identifier:results; 96, block; 97, expression_statement; 98, attribute; 99, attribute; 100, if_statement; 101, call; 102, identifier:is_dup; 103, False; 104, if_statement; 105, identifier:is_dup; 106, expression_statement; 107, identifier:len; 108, argument_list; 109, identifier:len; 110, argument_list; 111, attribute; 112, argument_list; 113, identifier:results; 114, identifier:no_dup_results; 115, attribute; 116, argument_list; 117, attribute; 118, True; 119, identifier:futures; 120, list; 121, expression_statement; 122, expression_statement; 123, expression_statement; 124, identifier:reference; 125, identifier:is_only_reference; 126, assert_statement; 127, expression_statement; 128, expression_statement; 129, expression_statement; 130, expression_statement; 131, expression_statement; 132, comment:# raise pending exception if any; 133, if_statement; 134, call; 135, identifier:result; 136, identifier:source_quality; 137, identifier:CoverSourceQuality; 138, identifier:REFERENCE; 139, parenthesized_expression; 140, block; 141, attribute; 142, argument_list; 143, parenthesized_expression; 144, block; 145, call; 146, identifier:results; 147, identifier:no_dup_results; 148, call; 149, identifier:info; 150, binary_operator:"Removed %u duplicate results" % (dup_count); 151, call; 152, identifier:info; 153, binary_operator:"Reference is: %s" % (reference); 154, identifier:reference; 155, identifier:is_similar_to_reference; 156, assignment; 157, assignment; 158, call; 159, parenthesized_expression; 160, assignment; 161, assignment; 162, call; 163, await; 164, call; 165, parenthesized_expression; 166, block; 167, attribute; 168, argument_list; 169, boolean_operator; 170, expression_statement; 171, identifier:itertools; 172, identifier:filterfalse; 173, call; 174, identifier:results; 175, boolean_operator; 176, expression_statement; 177, break_statement; 178, attribute; 179, argument_list; 180, attribute; 181, argument_list; 182, string:"Removed %u duplicate results"; 183, parenthesized_expression; 184, attribute; 185, argument_list; 186, string:"Reference is: %s"; 187, parenthesized_expression; 188, identifier:coroutine; 189, call; 190, identifier:future; 191, call; 192, attribute; 193, argument_list; 194, comparison_operator:reference not in results; 195, identifier:coroutine; 196, call; 197, identifier:future; 198, call; 199, attribute; 200, argument_list; 201, call; 202, attribute; 203, argument_list; 204, boolean_operator; 205, expression_statement; 206, if_statement; 207, call; 208, identifier:warning; 209, string:"No reference result found"; 210, parenthesized_expression; 211, parenthesized_expression; 212, assignment; 213, attribute; 214, argument_list; 215, boolean_operator; 216, parenthesized_expression; 217, assignment; 218, identifier:no_dup_results; 219, identifier:append; 220, identifier:result; 221, identifier:logging; 222, identifier:getLogger; 223, string:"Cover"; 224, identifier:dup_count; 225, identifier:logging; 226, identifier:getLogger; 227, string:"Cover"; 228, identifier:reference; 229, attribute; 230, argument_list; 231, attribute; 232, argument_list; 233, identifier:futures; 234, identifier:append; 235, identifier:future; 236, identifier:reference; 237, identifier:results; 238, attribute; 239, argument_list; 240, attribute; 241, argument_list; 242, identifier:futures; 243, identifier:append; 244, identifier:future; 245, attribute; 246, argument_list; 247, identifier:future; 248, identifier:result; 249, boolean_operator; 250, parenthesized_expression; 251, assignment; 252, attribute; 253, block; 254, else_clause; 255, attribute; 256, argument_list; 257, comparison_operator:reference is None; 258, comparison_operator:CoverSourceResult.compare(result,
                                         reference,
                                         target_size=target_size,
                                         size_tolerance_prct=size_tolerance_prct) > 0; 259, identifier:reference; 260, identifier:result; 261, identifier:operator; 262, identifier:attrgetter; 263, string:"is_only_reference"; 264, parenthesized_expression; 265, parenthesized_expression; 266, comparison_operator:__class__.compare(result,
                                 result_comp,
                                 target_size=target_size,
                                 size_tolerance_prct=size_tolerance_prct) < 0; 267, identifier:is_dup; 268, True; 269, identifier:result; 270, identifier:updateSignature; 271, identifier:asyncio; 272, identifier:ensure_future; 273, identifier:coroutine; 274, identifier:reference; 275, identifier:updateSignature; 276, identifier:asyncio; 277, identifier:ensure_future; 278, identifier:coroutine; 279, identifier:asyncio; 280, identifier:wait; 281, identifier:futures; 282, parenthesized_expression; 283, parenthesized_expression; 284, comparison_operator:reference.thumbnail_sig is not None; 285, attribute; 286, call; 287, identifier:result; 288, identifier:is_similar_to_reference; 289, expression_statement; 290, block; 291, identifier:logging; 292, identifier:getLogger; 293, string:"Cover"; 294, identifier:reference; 295, None; 296, call; 297, integer:0; 298, comparison_operator:result_comp is not result; 299, comparison_operator:result_comp.urls == result.urls; 300, call; 301, integer:0; 302, comparison_operator:result is not reference; 303, comparison_operator:result.thumbnail_sig is not None; 304, attribute; 305, None; 306, identifier:result; 307, identifier:is_similar_to_reference; 308, attribute; 309, argument_list; 310, call; 311, expression_statement; 312, attribute; 313, argument_list; 314, identifier:result_comp; 315, identifier:result; 316, attribute; 317, attribute; 318, attribute; 319, argument_list; 320, identifier:result; 321, identifier:reference; 322, attribute; 323, None; 324, identifier:reference; 325, identifier:thumbnail_sig; 326, identifier:__class__; 327, identifier:areImageSigsSimilar; 328, attribute; 329, attribute; 330, attribute; 331, argument_list; 332, call; 333, identifier:CoverSourceResult; 334, identifier:compare; 335, identifier:result; 336, identifier:reference; 337, keyword_argument; 338, keyword_argument; 339, identifier:result_comp; 340, identifier:urls; 341, identifier:result; 342, identifier:urls; 343, identifier:__class__; 344, identifier:compare; 345, identifier:result; 346, identifier:result_comp; 347, keyword_argument; 348, keyword_argument; 349, identifier:result; 350, identifier:thumbnail_sig; 351, identifier:result; 352, identifier:thumbnail_sig; 353, identifier:reference; 354, identifier:thumbnail_sig; 355, call; 356, identifier:debug; 357, binary_operator:"%s is similar to reference" % (result); 358, attribute; 359, argument_list; 360, identifier:target_size; 361, identifier:target_size; 362, identifier:size_tolerance_prct; 363, identifier:size_tolerance_prct; 364, identifier:target_size; 365, identifier:target_size; 366, identifier:size_tolerance_prct; 367, identifier:size_tolerance_prct; 368, attribute; 369, argument_list; 370, string:"%s is similar to reference"; 371, parenthesized_expression; 372, call; 373, identifier:debug; 374, binary_operator:"%s is NOT similar to reference" % (result); 375, identifier:logging; 376, identifier:getLogger; 377, string:"Cover"; 378, identifier:result; 379, attribute; 380, argument_list; 381, string:"%s is NOT similar to reference"; 382, parenthesized_expression; 383, identifier:logging; 384, identifier:getLogger; 385, string:"Cover"; 386, identifier:result
code: async def preProcessForComparison(results, target_size, size_tolerance_prct):
      """ Process results to prepare them for future comparison and sorting. """
      # find reference (=image most likely to match target cover ignoring factors like size and format)
      reference = None
      for result in results:
        if result.source_quality is CoverSourceQuality.REFERENCE:
          if ((reference is None) or
              (CoverSourceResult.compare(result,
                                         reference,
                                         target_size=target_size,
                                         size_tolerance_prct=size_tolerance_prct) > 0)):
            reference = result
  
      # remove results that are only refs
      results = list(itertools.filterfalse(operator.attrgetter("is_only_reference"), results))
  
      # remove duplicates
      no_dup_results = []
      for result in results:
        is_dup = False
        for result_comp in results:
          if ((result_comp is not result) and
              (result_comp.urls == result.urls) and
              (__class__.compare(result,
                                 result_comp,
                                 target_size=target_size,
                                 size_tolerance_prct=size_tolerance_prct) < 0)):
            is_dup = True
            break
        if not is_dup:
          no_dup_results.append(result)
      dup_count = len(results) - len(no_dup_results)
      if dup_count > 0:
        logging.getLogger("Cover").info("Removed %u duplicate results" % (dup_count))
        results = no_dup_results
  
      if reference is not None:
        logging.getLogger("Cover").info("Reference is: %s" % (reference))
        reference.is_similar_to_reference = True
  
        # calculate sigs
        futures = []
        for result in results:
          coroutine = result.updateSignature()
          future = asyncio.ensure_future(coroutine)
          futures.append(future)
        if reference.is_only_reference:
          assert(reference not in results)
          coroutine = reference.updateSignature()
          future = asyncio.ensure_future(coroutine)
          futures.append(future)
        if futures:
          await asyncio.wait(futures)
        for future in futures:
          future.result()  # raise pending exception if any
  
        # compare other results to reference
        for result in results:
          if ((result is not reference) and
                  (result.thumbnail_sig is not None) and
                  (reference.thumbnail_sig is not None)):
            result.is_similar_to_reference = __class__.areImageSigsSimilar(result.thumbnail_sig,
                                                                           reference.thumbnail_sig)
            if result.is_similar_to_reference:
              logging.getLogger("Cover").debug("%s is similar to reference" % (result))
            else:
              logging.getLogger("Cover").debug("%s is NOT similar to reference" % (result))
      else:
        logging.getLogger("Cover").warning("No reference result found")
  
      return results