def build_dataset2(): games = sorted([ o for o in os.listdir(dataset_path) if os.path.isdir(os.path.join(dataset_path, o)) ]) games.append(games.pop(1)) for game in games: clips = sorted([ o for o in os.listdir(dataset_path + game) if os.path.isdir(os.path.join(dataset_path + game, o)) ]) for clip in clips: label_file = open( dataset_path + game + '/' + clip + '/' + 'Label.csv', 'r') label_list = list(csv.reader(label_file)) single_clip2(label_list, test=game == 'game9' or game == 'game8') rotem_helpers.save_obj( x_train, '/Users/rotemisraeli/Documents/python/tennis/dataset2/x_train.np') rotem_helpers.save_obj( y_train, '/Users/rotemisraeli/Documents/python/tennis/dataset2/y_train.np') rotem_helpers.save_obj( x_test, '/Users/rotemisraeli/Documents/python/tennis/dataset2/x_test.np') rotem_helpers.save_obj( y_test, '/Users/rotemisraeli/Documents/python/tennis/dataset2/y_test.np')
def new_follow(thread_num,thread_q): global users_follow print(len(thread_q),len(users_follow)) i = 0 pop_first = True count_first = 0 if thread_num == 0: while True: time.sleep(60*20) exp.metric('laptop_battery', rotem_helpers.get_battery()) users_follow2 = users_follow.copy() exp.metric('num_users', len(users_follow2)) file_name = str(version) + '-' + strftime("%m-%d-%H-%M", gmtime()) + '.pkl' rotem_helpers.save_obj(users_follow2, vars_dir + 'uf/' + file_name) while i < nums: try: current_user = thread_q.pop(0) if current_user in users_follow: if pop_first: count_first = 0 else: if pop_first: count_first+=1 if count_first > 5: thread_q.pop(0) pop_first = False else: exp.metric(str(thread_num), float(i)) i+=1 try: followers = user_friends(current_user, 'followers') users_follow[current_user] = {'followers': followers} except: print('******************** ' + current_user) pass # if time.time() - last_time > 10*60: # last_time = time.time() # file_name = str(version)+'-'+str(thread_num)+'-'+strftime("%m-%d-%H-%M", gmtime()) + '.pkl' # rotem_helpers.save_obj(thread_q, vars_dir+'q/' + file_name) except: i+=1 thread_q.pop(0)
def new_q(q): file_name = str(version) + '-' + strftime("%m-%d-%H-%M", gmtime()) + '.pkl' rotem_helpers.save_obj(q, vars_dir + 'q2/' + file_name)
def new_follow(thread_num, thread_q): global users_follow, q_in_use, lock, last_time # print(len(thread_q),len(users_follow)) i = 0 pop_first = True count = 0 qs_ezer = [] for qs in thread_q: qs_ezer.append(qs[0]) while i < nums: while q_in_use: time.sleep(10) try: current_user, dist = thread_q.pop(0) # print(current_user,dist) i += 1 if dist == layer_download: if True or not current_user in users_follow: exp.metric(str(thread_num), count) count += 1 followers = user_friends(current_user, 'followers') followers2 = [] for folo in followers: while q_in_use: time.sleep(10) if folo in users_follow: users_follow[folo]['followers'].append( current_user) else: # followers2.append([folo,dist+1]) users_follow[folo] = { 'followers': [], 'layer': dist + 1 } # thread_q.extend(followers2) users_follow[current_user] = { 'followers': followers, 'layer': dist } # file_name = 'final' + str(version) + '-' + strftime("%m-%d-%H-%M", gmtime()) + '.pkl' # rotem_helpers.save_obj(q, vars_dir + 'q/' + file_name) while q_in_use: time.sleep(10) # if thread_num == 0: # print(time.time()-last_time) if time.time() - last_time > 15 * 60: with lock: q_in_use = True worked = False file_name = str(version) + '-' + strftime( "%m-%d-%H-%M", gmtime()) + '.pkl' while not worked: try: last_time = time.time() # q_to_save = [] # qs_ezer = [] # q_in_use = True # for qs_mini in all_qs: # qs_ezer.append(qs_mini.copy()) # q_in_use = False # for qs_mini in qs_ezer: # q_to_save.extend(qs_mini) # # rotem_helpers.save_obj(q_to_save, vars_dir + 'q2/' + file_name) rotem_helpers.save_obj( users_follow, vars_dir + 'uf/' + file_name) q_in_use = False worked = True except: time.sleep(5) except Exception as e: if str(e) == 'pop from empty list': print(thread_q) rotem_helpers.save_obj(q, vars_dir + 'q/' + str(len(q)) + '.pkl') rotem_helpers.save_obj( users_follow, vars_dir + 'uf/' + str(len(users_follow)) + '.pkl') sys.exit(0) time.sleep(10) print('ooo', thread_num, e)