-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreprocessing.py
53 lines (44 loc) · 1.57 KB
/
preprocessing.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
def remove_outliers():
count=0
c=0
# filenames = ['lib_(1,1).csv','lib_(1,2).csv','lib_(2,1).csv','lib_(2,2).csv']
filenames = ['data.csv']
same_mac_sig = []
seen_mac = set()
d=[]
for file in filenames:
u=open(file)
print(file)
for line in u:
mac,sig=line.split(",")
if mac not in seen_mac:
seen_mac.add(mac)
#same_mac_sig.append(sig)
u2 = open(file)
for line2 in u2: #looking for same mac
mac1,sig1=line2.split(",")
if mac1==mac:
same_mac_sig.append(int(sig1)) #creating list of all sig with same mac
u2.close()
same_mac_sig.sort(reverse=True) #sorting
i = 0
while i < len(same_mac_sig) - 1:
#print(same_mac_sig[i])
if (int(same_mac_sig[i]) - int(same_mac_sig[i + 1])) > 5:
same_mac_sig.pop(i + 1)
count+=1
i = i - 1
i = i + 1
#print(count)
if count>0:
d.append(count)
count = 0
ro = open(file, "a")
for j in same_mac_sig:
ro.write(mac+","+str(j)+"\n")
ro.close()
same_mac_sig.clear()
u.close()
seen_mac.clear()
print(d)
remove_outliers()