示例#1
0
    def test_duplicates(self):

        self._dupe_hashes = [HydrusData.GenerateKey() for i in range(16)]
        self._second_group_dupe_hashes = [
            HydrusData.GenerateKey() for i in range(4)
        ]
        self._similar_looking_alternate_hashes = [
            HydrusData.GenerateKey() for i in range(5)
        ]
        self._similar_looking_false_positive_hashes = [
            HydrusData.GenerateKey() for i in range(5)
        ]

        self._all_hashes = set()

        self._all_hashes.update(self._dupe_hashes)
        self._all_hashes.update(self._second_group_dupe_hashes)
        self._all_hashes.update(self._similar_looking_alternate_hashes)
        self._all_hashes.update(self._similar_looking_false_positive_hashes)

        self._king_hash = self._dupe_hashes[0]
        self._second_group_king_hash = self._second_group_dupe_hashes[0]
        self._false_positive_king_hash = self._similar_looking_false_positive_hashes[
            0]
        self._alternate_king_hash = self._similar_looking_alternate_hashes[0]

        self._our_main_dupe_group_hashes = set([self._king_hash])
        self._our_second_dupe_group_hashes = set(
            [self._second_group_king_hash])
        self._our_alt_dupe_group_hashes = set([self._alternate_king_hash])
        self._our_fp_dupe_group_hashes = set([self._false_positive_king_hash])

        n = len(self._all_hashes)

        self._num_free_agents = n

        # initial number pair combinations is (n(n-1))/2
        self._expected_num_potentials = int(n * (n - 1) / 2)

        size_pred = ClientSearch.Predicate(
            ClientSearch.PREDICATE_TYPE_SYSTEM_SIZE,
            ('=', 65535, HydrusData.ConvertUnitToInt('B')))

        location_search_context = ClientSearch.LocationSearchContext(
            current_service_keys=[CC.LOCAL_FILE_SERVICE_KEY])

        self._file_search_context = ClientSearch.FileSearchContext(
            location_search_context=location_search_context,
            predicates=[size_pred])

        self._import_and_find_dupes()

        self._test_initial_state()

        self._test_initial_better_worse()
        self._test_initial_king_usurp()
        self._test_initial_same_quality()

        self._test_explicit_set_new_king()

        self._test_establish_second_group()
        self._test_poach_better()
        self._test_poach_same()
        self._test_group_merge()

        self._test_establish_false_positive_group()
        self._test_false_positive()

        self._test_establish_alt_group()
        self._test_alt()

        self._test_expand_false_positive()
        self._test_expand_alt()

        self._test_dissolve()
 SystemPredicateParser.Predicate.NOT_BEST_QUALITY_OF_GROUP : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS_KING, False ),
 SystemPredicateParser.Predicate.HAS_AUDIO : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HAS_AUDIO, True ),
 SystemPredicateParser.Predicate.NO_AUDIO : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HAS_AUDIO, False ),
 SystemPredicateParser.Predicate.HAS_ICC_PROFILE : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HAS_ICC_PROFILE, True ),
 SystemPredicateParser.Predicate.NO_ICC_PROFILE : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HAS_ICC_PROFILE, False ),
 SystemPredicateParser.Predicate.LIMIT : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_LIMIT, v ),
 SystemPredicateParser.Predicate.FILETYPE : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_MIME, tuple( v ) ),
 SystemPredicateParser.Predicate.HAS_DURATION : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_DURATION, ( '>', 0 ) ),
 SystemPredicateParser.Predicate.NO_DURATION : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_DURATION, ( '=', 0 ) ),
 SystemPredicateParser.Predicate.HAS_TAGS : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_TAGS, ( None, '>', 0 ) ),
 SystemPredicateParser.Predicate.UNTAGGED : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_TAGS, ( None, '=', 0 ) ),
 SystemPredicateParser.Predicate.NUM_OF_TAGS : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_TAGS, ( None, o, v ) ),
 SystemPredicateParser.Predicate.NUM_OF_WORDS : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_WORDS, ( o, v ) ),
 SystemPredicateParser.Predicate.HEIGHT : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HEIGHT, ( o, v ) ),
 SystemPredicateParser.Predicate.WIDTH : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_WIDTH, ( o, v ) ),
 SystemPredicateParser.Predicate.FILESIZE : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_SIZE, ( o, v, HydrusData.ConvertUnitToInt( u ) ) ),
 SystemPredicateParser.Predicate.SIMILAR_TO : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_SIMILAR_TO, convert_hex_hashlist_and_other_to_bytes_and_other( v ) ),
 SystemPredicateParser.Predicate.HASH : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HASH, convert_hex_hashlist_and_other_to_bytes_and_other( v ), inclusive = o == '=' ),
 SystemPredicateParser.Predicate.DURATION : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_DURATION, ( o, v[0] * 1000 + v[1] ) ),
 SystemPredicateParser.Predicate.NUM_PIXELS : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_PIXELS, ( o, v, HydrusData.ConvertPixelsToInt( u ) ) ),
 SystemPredicateParser.Predicate.RATIO : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_RATIO, ( o, v[0], v[1] ) ),
 SystemPredicateParser.Predicate.TAG_AS_NUMBER : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_TAG_AS_NUMBER, ( o[0], o[1], v ) ),
 SystemPredicateParser.Predicate.MEDIA_VIEWS : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS, ( 'views', ( 'media', ), o, v ) ),
 SystemPredicateParser.Predicate.PREVIEW_VIEWS : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS, ( 'views', ( 'preview', ), o, v ) ),
 SystemPredicateParser.Predicate.ALL_VIEWS : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS, ( 'views', ( 'media', 'preview' ), o, v ) ),
 SystemPredicateParser.Predicate.MEDIA_VIEWTIME : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS, ( 'viewtime', ( 'media', ), o, convert_timetuple_to_seconds( v ) ) ),
 SystemPredicateParser.Predicate.PREVIEW_VIEWTIME : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS, ( 'viewtime', ( 'preview', ), o, convert_timetuple_to_seconds( v ) ) ),
 SystemPredicateParser.Predicate.ALL_VIEWTIME : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS, ( 'viewtime', ( 'media', 'preview' ), o, convert_timetuple_to_seconds( v ) ) ),
 SystemPredicateParser.Predicate.URL_REGEX : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_KNOWN_URLS, ( True, 'regex', v, 'has a url matching regex: {}'.format( v ) ) ),
 SystemPredicateParser.Predicate.NO_URL_REGEX : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_KNOWN_URLS, ( False, 'regex', v, 'does not have a url matching regex: {}'.format( v ) ) ),
 SystemPredicateParser.Predicate.URL : lambda o, v, u: ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_KNOWN_URLS, ( True, 'exact_match', v, 'has url: {}'.format( v ) ) ),
示例#3
0
 SystemPredicateParser.Predicate.NUM_OF_TAGS:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_TAGS, (None, o, v)),
 SystemPredicateParser.Predicate.NUM_OF_WORDS:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_WORDS, (o, v)),
 SystemPredicateParser.Predicate.HEIGHT:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_HEIGHT, (o, v)),
 SystemPredicateParser.Predicate.WIDTH:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_WIDTH, (o, v)),
 SystemPredicateParser.Predicate.FILESIZE:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_SIZE,
     (o, v, HydrusData.ConvertUnitToInt(u))),
 SystemPredicateParser.Predicate.SIMILAR_TO:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_SIMILAR_TO,
     convert_hex_hashlist_and_other_to_bytes_and_other(v)),
 SystemPredicateParser.Predicate.HASH:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_HASH,
     convert_hex_hashlist_and_other_to_bytes_and_other(v)),
 SystemPredicateParser.Predicate.DURATION:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_DURATION, (o, v[0] * 1000 + v[1])),
 SystemPredicateParser.Predicate.NUM_PIXELS:
 lambda o, v, u: ClientSearch.Predicate(
     ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_PIXELS,
     (o, v, HydrusData.ConvertPixelsToInt(u))),