-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_bss_eval.py
executable file
·70 lines (53 loc) · 1.73 KB
/
parse_bss_eval.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
#! /usr/bin/python3
import os
import subprocess as sub
def p(arg): print("<",arg,">",sep="")
def error(msg):
print(msg)
exit(1)
def check(test, msg):
if not (test):
error(msg)
DEVNULL = open(os.devnull, 'w')
def mcli_call_bss_eval_static(logpath):
sub.check_call(["rm","-f",logpath])
sub.check_call(["mcli", "bss_eval_static", "\'"+logpath+"\'"], stderr=DEVNULL, stdout=DEVNULL)
def parse_bss_eval_static(logpath):
"""
Parses the logfile and returns the original and estimated lists with entries:
[ (matching_source_index,SDR,SIR,SAR) , ... ] sorted by the original/estimated source index.
"""
diary_file = open(logpath, 'r')
diary_lines = diary_file.readlines()
diary_file.close()
lines = [ line.strip() for line in diary_lines if line.strip() ]
o = []
e = []
# State machine
NONE = 0
ORIGINAL = 1
ESTIMATED = 2
# state
line_is = NONE
for line in lines:
if line[:7] == "e_match":
line_is = ORIGINAL
continue
elif line[:7] == "o_match":
line_is = ESTIMATED
continue
elif line_is != NONE: # If the file obeys the specs at least we must be in some state by now.
l = line.split("\t")
# (match, SDR,SIR,SAR)
values = (int(l[0])-1, float(l[2]),float(l[5]),float(l[8]))
if line_is == ORIGINAL:
o.append(values)
else:
e.append(values)
else:
error("Unrecognized line precedes the original and estimated lines: <"+line+">")
return (o, e)
if __name__ == "__main__":
mcli_call_bss_eval_static("bss_eval.log")
bss = parse_bss_eval_static("bss_eval.log")
p(bss)