-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_gruop_label.py
91 lines (69 loc) · 2.6 KB
/
2_gruop_label.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import sys
import os
import time
#****************************************************************
#*
#* This program will group folders that have common single-label into a new single-label folder by analysing their folder name
#* ex: the folder label-8, label-8-12, label-8-15, label-8-12-15 will be put in a new folder namaing label-8
#*
#*
#****************************************************************
def find_folder_list_from(path):
folder_list=[]
for f in os.listdir(path):
folder_list.append(f)
return folder_list
def collected_label_type_under(path):
folder_li = find_folder_list_from(path)
label_vs_folder = { }
label_li = [ ]
for fold in folder_li:
label = fold.split('_')[0]
label_li.append(label)
if label not in label_vs_folder:
label_vs_folder[label] = fold
else:
print('EEEEEEEEEEEEEEEEEEEEEEEEEEEEE')
time.sleep(10)
print(label_vs_folder)
print(label_li)
return label_li, label_vs_folder
def creat_folder_foe_signal_label_by(li, path):
if not path.endswith('/'):
path = path +'/'
all_conbination = path + 'all_combinations'
if not os.path.exists(all_conbination):
os.mkdir(all_conbination)
conbination_dict = {}
for fold_name in li:
fold_setting = get_folder_setting(fold_name)
if len(fold_setting) == 1:
print(fold_name, fold_setting[0])
new_fold = all_conbination+'/'+fold_name
if not os.path.exists(new_fold):
os.mkdir(new_fold)
conbination_dict[fold_setting[0]]=new_fold
print(conbination_dict)
return conbination_dict
def get_folder_setting(fold_name):
fold_setting = fold_name.split('-')[1:]
return fold_setting
def move_folder_to_conbunation(li_dict, fold_dict, path):
if not path.endswith('/'):
path = path +'/'
for label in li_dict:
moveing_file = path +li_dict[label]
for xxx in fold_dict:
print(xxx)
print(moveing_file)
print( get_folder_setting(label) )
moveing_file = moveing_file +'/'
if xxx in get_folder_setting( label ):
print(fold_dict[xxx]+'/')
os.system('cp -r %s %s'%(moveing_file, (fold_dict[xxx]+'/')))
if __name__ == "__main__":
folder = sys.argv[1]
#! ./ex/advertising/test/best/combination/
la_list, la_dict = collected_label_type_under(folder)
conbin_dcit = creat_folder_foe_signal_label_by(la_list, folder)
move_folder_to_conbunation(la_dict, conbin_dcit, folder)