forked from dirtyharrycallahan/pystrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetSelfDistance.py
More file actions
56 lines (50 loc) · 1.63 KB
/
Copy pathgetSelfDistance.py
File metadata and controls
56 lines (50 loc) · 1.63 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
'''
get distance among strings of self
usage: python getSelfDistance.py stand/ c
stand/: the sub folder of the str files
c: the cth line of the str file as the reference [0-9)
output disdir/stand/test-case.dis (contains str for 10 tests)
'''
import sys
import os
import editdistance
import numpy as np
import pickle
def Start(subdir, c):
str_list = "/home/ruimin/pystrace/strdir/" + subdir + "/"
for root, dirs, strfiles in os.walk(str_list):
for strfile in strfiles:
if strfile[-4:] == ".str":
with open(os.path.join(root,strfile), 'r') as str_fd:
lines = str_fd.readlines()
ref = lines[int(c)]
res = list()
res_rt = list()
for line in lines:
dis = editdistance.eval(ref,line)
ratio = 1- dis/float(max(len(ref),len(line)))
res.append(dis)
res_rt.append(ratio)
mean = np.mean(res)
std = np.std(res)
mean_rt = np.mean(res_rt)
std_rt = np.std(res_rt)
dest_file = "/home/ruimin/pystrace/disdir/" + subdir + "/" + strfile[:-4] + ".dis"
dest_file_rt = "/home/ruimin/pystrace/ratiodir/" + subdir + "/" + strfile[:-4] + ".rt"
# os.system("echo " + res_str + " >> " + dest_file)
with open(dest_file,'ab') as f, open(dest_file_rt,'ab') as f_rt:
#pickle.dump(res,f)
pickle.dump(res_rt,f_rt)
line1 = "MEAN:" + str(mean) + "\n"
line2 = "STD:" + str(std) + "\n"
line1_rt = "MEAN:" + str(mean_rt) + "\n"
line2_rt = "STD:" + str(std_rt) + "\n"
#f.write(line1)
#f.write(line2)
f_rt.write(line1_rt)
f_rt.write(line2_rt)
#
# Entry point to the application
#
if __name__ == '__main__':
Start(sys.argv[1], sys.argv[2])