-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
99 lines (65 loc) · 1.55 KB
/
utils.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
91
92
93
94
95
96
97
98
import os
import config
from functools import reduce
from datatable import f
from operator import and_, or_, xor, eq
def name_to_dict(
file_name,
col_names = config.FNAME_COLS,
):
name = (file_name
.split('.')[1]
.split('_')
)
return {
col_names[0] : file_name,
col_names[1] : name[1],
col_names[2] : int(name[2]),
col_names[3] : int(name[3]),
}
def name_to_dir(
file_name,
):
path_dir = '/'.join(
file_name.split('_')[:3]
)
return f'{config.PATH_SIHSUS}/{path_dir}/'
def get_path(
file_name,
path_db = config.PATH_DB,
col_names = config.FNAME_COLS,
):
d = name_to_dict(file_name)
data_dir = path_db.split('/')[0]
path_list = [
data_dir,
'sihsus',
f'{d[col_names[1]]}',
f'{d[col_names[2]]}',
f'{d[col_names[3]]:02d}',
]
path_dir = '/'.join(path_list) + '/'
if not os.path.exists(path_dir):
os.makedirs(path_dir)
file_path = (
path_dir + '_'.join(path_list[2:])
)
return file_path
def get_files(
path_dir = 'data/sihsus'
):
fs = []
for (dirpath, dirnames, filenames) in os.walk(path_dir):
fs.extend(filenames)
return fs
def isin(
column,
sequence_of_labels,
):
func = lambda x: f[column] == x
return reduce(or_, map(func, sequence_of_labels))
# Main
def main():
fs = get_files()
print(fs[:24])
__name__ == '__main__' and main()