def dummy_preproc_spam(depc, *args, **kwargs): config = kwargs.get('config', None) if config is None: config = {} print('[preproc] Computing spam') ut.writeto('tmp.txt', ut.lorium_ipsum()) for x in zip(*args): size = (42, 21) uuid = ut.get_zero_uuid() vector = np.ones(3) yield ('spam', 3665, size, uuid, vector, 'tmp.txt')
def dummy_preproc_spam(depc, *args, **kwargs): config = kwargs.get('config', None) if config is None: config = {} print('Computing notch') ut.writeto('tmp.txt', ut.lorium_ipsum()) for x in zip(*args): size = (42, 21) uuid = ut.get_zero_uuid() vector = np.ones(3) yield ('spam', 3665, size, uuid, vector, 'tmp.txt')
def test_augment_uuid(): # TODO: This is still divergent between python2 and python3 uuid_ = utool.get_zero_uuid() #uuid_ = uuid.uuid1() #uuidhex_data = uuid_.get_bytes() uuidhex_data = uuid_.bytes print('uuidhex_data = %r' % uuidhex_data) hashable_text1 = '[0, 0, 100, 100]' hashable_text2 = '' if six.PY3: hashable_data1 = hashable_text1.encode('utf-8') hashable_data2 = hashable_text2.encode('utf-8') else: hashable_data1 = hashable_text1 hashable_data2 = hashable_text2 augmented_data1 = uuidhex_data + hashable_data1 augmented_data2 = uuidhex_data + hashable_data2 augmented_uuid1_ = utool.hashable_to_uuid(augmented_data1) augmented_uuid2_ = utool.hashable_to_uuid(augmented_data2) print('augmented_data1 =%r' % augmented_data1) print('augmented_data2 =%r' % augmented_data2) struuid_ = utool.hashable_to_uuid(str(uuid_)) print(' uuid_=%r' % (uuid_, )) print('augmented_uuid1_=%r' % (augmented_uuid1_, )) print('augmented_uuid2_=%r' % (augmented_uuid2_, )) print('hash2uuid(uuid_)=%r' % (struuid_, )) # Test what is capable of being augmented import numpy as np augmented_uuid_T1 = utool.augment_uuid(uuid_, hashable_data1) augmented_uuid_T2 = utool.augment_uuid(uuid_, hashable_data2) augmented_uuid_T3 = utool.augment_uuid(uuid_, hashable_data2, hashable_data1) augmented_uuid_T4 = utool.augment_uuid(uuid_, hashable_data1, hashable_data2) augmented_uuid_T5 = utool.augment_uuid(uuid_, [1, 2, 3]) augmented_uuid_T5 = utool.augment_uuid(uuid_, (1, 2, 3)) augmented_uuid_T6 = utool.augment_uuid(uuid_, np.array((1, 2, 3))) print('augmented_uuid_T1=%r' % (augmented_uuid_T1, )) print('augmented_uuid_T2=%r' % (augmented_uuid_T2, )) print('augmented_uuid_T3=%r' % (augmented_uuid_T3, )) print('augmented_uuid_T4=%r' % (augmented_uuid_T4, )) print('augmented_uuid_T5=%r' % (augmented_uuid_T5, )) print('augmented_uuid_T6=%r' % (augmented_uuid_T6, ))
def test_augment_uuid(): # TODO: This is still divergent between python2 and python3 uuid_ = utool.get_zero_uuid() #uuid_ = uuid.uuid1() #uuidhex_data = uuid_.get_bytes() uuidhex_data = uuid_.bytes print('uuidhex_data = %r' % uuidhex_data) hashable_text1 = '[0, 0, 100, 100]' hashable_text2 = '' if six.PY3: hashable_data1 = hashable_text1.encode('utf-8') hashable_data2 = hashable_text2.encode('utf-8') else: hashable_data1 = hashable_text1 hashable_data2 = hashable_text2 augmented_data1 = uuidhex_data + hashable_data1 augmented_data2 = uuidhex_data + hashable_data2 augmented_uuid1_ = utool.hashable_to_uuid(augmented_data1) augmented_uuid2_ = utool.hashable_to_uuid(augmented_data2) print('augmented_data1 =%r' % augmented_data1) print('augmented_data2 =%r' % augmented_data2) struuid_ = utool.hashable_to_uuid(str(uuid_)) print(' uuid_=%r' % (uuid_,)) print('augmented_uuid1_=%r' % (augmented_uuid1_,)) print('augmented_uuid2_=%r' % (augmented_uuid2_,)) print('hash2uuid(uuid_)=%r' % (struuid_,)) # Test what is capable of being augmented import numpy as np augmented_uuid_T1 = utool.augment_uuid(uuid_, hashable_data1) augmented_uuid_T2 = utool.augment_uuid(uuid_, hashable_data2) augmented_uuid_T3 = utool.augment_uuid(uuid_, hashable_data2, hashable_data1) augmented_uuid_T4 = utool.augment_uuid(uuid_, hashable_data1, hashable_data2) augmented_uuid_T5 = utool.augment_uuid(uuid_, [1, 2, 3]) augmented_uuid_T5 = utool.augment_uuid(uuid_, (1, 2, 3)) augmented_uuid_T6 = utool.augment_uuid(uuid_, np.array((1, 2, 3))) print('augmented_uuid_T1=%r' % (augmented_uuid_T1,)) print('augmented_uuid_T2=%r' % (augmented_uuid_T2,)) print('augmented_uuid_T3=%r' % (augmented_uuid_T3,)) print('augmented_uuid_T4=%r' % (augmented_uuid_T4,)) print('augmented_uuid_T5=%r' % (augmented_uuid_T5,)) print('augmented_uuid_T6=%r' % (augmented_uuid_T6,))
def add_contributors(ibs, tag_list, uuid_list=None, name_first_list=None, name_last_list=None, loc_city_list=None, loc_state_list=None, loc_country_list=None, loc_zip_list=None, notes_list=None): r""" Adds a list of contributors. Returns: contrib_id_list (list): contributor rowids RESTful: Method: POST URL: /api/contributor/ """ import datetime def _valid_zip(_zip, default='00000'): _zip = str(_zip) if len(_zip) == 5 and _zip.isdigit(): return _zip return default if ut.VERBOSE: print('[ibs] adding %d encounters' % len(tag_list)) # Add contributors to database if name_first_list is None: name_first_list = [''] * len(tag_list) if name_last_list is None: name_last_list = [''] * len(tag_list) if loc_city_list is None: loc_city_list = [''] * len(tag_list) if loc_state_list is None: loc_state_list = [''] * len(tag_list) if loc_country_list is None: loc_country_list = [''] * len(tag_list) if loc_zip_list is None: loc_zip_list = [''] * len(tag_list) if notes_list is None: notes_list = [ "Created %s" % (datetime.datetime.now(),) for _ in range(len(tag_list))] loc_zip_list = [ _valid_zip(_zip) for _zip in loc_zip_list] if uuid_list is None: #contrib_rowid_list = ibs.get_contributor_rowid_from_tag(tag_list) #uuid_list = ibs.get_contributor_uuid(contrib_rowid_list) #uuid_list = ibs.get_contributor_uuid(contrib_rowid_list) #uuid_list = [ uuid.uuid4() if uuid_ is None else uuid_ for uuid_ in uuid_list ] # DETERMENISTIC UUIDS zero_uuid = ut.get_zero_uuid() uuid_list = [ut.augment_uuid(zero_uuid, tag) for tag in tag_list] colnames = ['contributor_uuid', 'contributor_tag', 'contributor_name_first', 'contributor_name_last', 'contributor_location_city', 'contributor_location_state', 'contributor_location_country', 'contributor_location_zip', 'contributor_note'] params_iter = zip(uuid_list, tag_list, name_first_list, name_last_list, loc_city_list, loc_state_list, loc_country_list, loc_zip_list, notes_list) get_rowid_from_superkey = ibs.get_contributor_rowid_from_uuid #get_rowid_from_superkey = ibs.get_contributor_rowid_from_tag # ?? is tag a superkey? contrib_id_list = ibs.db.add_cleanly(const.CONTRIBUTOR_TABLE, colnames, params_iter, get_rowid_from_superkey) return contrib_id_list
def add_contributors(ibs, tag_list, uuid_list=None, name_first_list=None, name_last_list=None, loc_city_list=None, loc_state_list=None, loc_country_list=None, loc_zip_list=None, notes_list=None): r""" Adds a list of contributors. Returns: contributor_id_list (list): contributor rowids RESTful: Method: POST URL: /api/contributor/ """ import datetime def _valid_zip(_zip, default='00000'): _zip = str(_zip) if len(_zip) == 5 and _zip.isdigit(): return _zip return default if ut.VERBOSE: print('[ibs] adding %d imagesets' % len(tag_list)) # Add contributors to database if name_first_list is None: name_first_list = [''] * len(tag_list) if name_last_list is None: name_last_list = [''] * len(tag_list) if loc_city_list is None: loc_city_list = [''] * len(tag_list) if loc_state_list is None: loc_state_list = [''] * len(tag_list) if loc_country_list is None: loc_country_list = [''] * len(tag_list) if loc_zip_list is None: loc_zip_list = [''] * len(tag_list) if notes_list is None: notes_list = [ "Created %s" % (datetime.datetime.now(), ) for _ in range(len(tag_list)) ] loc_zip_list = [_valid_zip(_zip) for _zip in loc_zip_list] if uuid_list is None: #contributor_rowid_list = ibs.get_contributor_rowid_from_tag(tag_list) #uuid_list = ibs.get_contributor_uuid(contributor_rowid_list) #uuid_list = ibs.get_contributor_uuid(contributor_rowid_list) #uuid_list = [ uuid.uuid4() if uuid_ is None else uuid_ for uuid_ in uuid_list ] # DETERMENISTIC UUIDS zero_uuid = ut.get_zero_uuid() uuid_list = [ut.augment_uuid(zero_uuid, tag) for tag in tag_list] colnames = [ 'contributor_uuid', 'contributor_tag', 'contributor_name_first', 'contributor_name_last', 'contributor_location_city', 'contributor_location_state', 'contributor_location_country', 'contributor_location_zip', 'contributor_note' ] params_iter = zip(uuid_list, tag_list, name_first_list, name_last_list, loc_city_list, loc_state_list, loc_country_list, loc_zip_list, notes_list) get_rowid_from_superkey = ibs.get_contributor_rowid_from_uuid #get_rowid_from_superkey = ibs.get_contributor_rowid_from_tag # ?? is tag a superkey? contributor_id_list = ibs.db.add_cleanly(const.CONTRIBUTOR_TABLE, colnames, params_iter, get_rowid_from_superkey) return contributor_id_list