-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_marp.py
69 lines (62 loc) · 2.21 KB
/
parse_marp.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
import sys
def main():
file = "marp.txt"
if len(sys.argv) < 2:
raise RuntimeError('Usage: python3 parse_marp.py [file_name]')
file = str(sys.argv[1])
avg_fidelity = {}
avg_sdrp_time = {}
avg_marp_time = {}
trial_count = {}
with open(file, 'r') as in_file:
depth = 0
fidelity = 0
time = 0
while True:
line = in_file.readline()
if not line:
# Last sample
if depth > 0:
if depth in avg_fidelity.keys():
avg_fidelity[depth] = avg_fidelity[depth] + fidelity
avg_sdrp_time[depth] = avg_sdrp_time[depth] + time
else:
avg_fidelity[depth] = fidelity
avg_sdrp_time[depth] = time
break
d = eval(line)
if d['sdrp'] == 1:
# Update count
dpth = d['depth']
if dpth in trial_count.keys():
trial_count[dpth] = trial_count[dpth] + 1
else:
trial_count[dpth] = 1
# Finalize last samples
if depth > 0:
if depth in avg_fidelity.keys():
avg_fidelity[depth] = avg_fidelity[depth] + fidelity
avg_sdrp_time[depth] = avg_sdrp_time[depth] + time
else:
avg_fidelity[depth] = fidelity
avg_sdrp_time[depth] = time
depth = d['depth']
fidelity = d['fidelity']
time = d['time']
if depth in avg_marp_time.keys():
avg_marp_time[depth] = avg_marp_time[depth] + time
else:
avg_marp_time[depth] = time
for key in avg_fidelity.keys():
depth = int(key)
trials = trial_count[key]
print({
'depth': int(key),
'successful_trials': trials,
'avg_fidelity': avg_fidelity[key] / 100,
'avg_sdrp_seconds': avg_sdrp_time[key] / trials,
'avg_marp_seconds': avg_marp_time[key] / trials
})
return 0
if __name__ == '__main__':
sys.exit(main())