Repository navigation
Expand file tree
/
Copy pathpre_processing.py
More file actions
64 lines (54 loc) · 2.06 KB
/
Copy pathpre_processing.py
File metadata and controls
64 lines (54 loc) · 2.06 KB
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
import numpy as np
def main():
with open("data/one_hot_abnormal_ground_truth.csv", "w") as w:
# with open("data/hdfs_train") as f:
# with open("data/hdfs_test_normal") as f:
with open("data/hdfs_test_abnormal") as f:
lines = f.readlines()
# get max_id
max_id = 0
for line in lines:
ids = line.split(" ")
for id in ids:
if id == "\n" or id == "":
continue
idi = int(id)
max_id = max(idi, max_id)
# generate one hot
for line in lines:
one_hot_line = np.zeros(max_id)
ids = line.split(" ")
for id in ids:
if id == "\n" or id == "":
continue
idi = int(id)
one_hot_line[idi-1]=1
# one-hot to str
one_hot_str = ",".join([str(int(i)) for i in one_hot_line])
# write file
w.write(one_hot_str+"\n")
def filter_by_mask(line: str):
mask = "0. 1. 1. 1. 0. 0. 1. 1. 1. 1. 0. 1. 1. 0. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. 0. 1. 1"
mask = [int(i) for i in mask.split(".")]
line_list = line.split()
for i in range(len(mask)):
if mask[i] == 0:
target = str(int(i+1))
for j in range(len(line_list)):
if line_list[j] == target:
line_list[j] = ""
return " ".join(line_list)
def filter_data():
# with open("data/hdfs_test_abnormal_filtered", "w") as w:
# with open("data/hdfs_test_normal_filtered", "w") as w:
with open("data/hdfs_train_filtered", "w") as w:
# with open("data/hdfs_test_abnormal") as f:
# with open("data/hdfs_test_normal") as f:
with open("data/hdfs_train") as f:
lines = f.readlines()
for line in lines:
alt_line = filter_by_mask(line)
w.write(alt_line+"\n")
if __name__ == '__main__':
# main()
filter_data()