-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc_dbl.py
65 lines (60 loc) · 1.51 KB
/
calc_dbl.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
#This .py script is process the output file of pre_dbl.py and print out the probability of dbl
from __future__ import division
from collections import Counter
import subprocess
import os
import sys
import collections
import re
import operator
if len(sys.argv)<2:
print "Usage: pass pre_dbl.py output file as a parameter to get probaibilty of dbl"
sys.exit(0)
current = 0
curpair=[]
pairs=[]
f = open(sys.argv[1], 'r')
lines = f.readlines()
for line in lines:
split1 = line.split()
fid = int(re.search("\d+",split1[1]).group())
status = str(re.search("\w+",split1[2]).group())
t = (fid, status)
pairs.append(t)
#print pairs
output = {} # (f,t) -> [dbl, dbl, ...] (f:from t: to)
last = {} # (f,t) -> [dropped/received]
for (fid, s) in pairs:
#ft = (f,t)
if fid in output: # if a pair exists in the output dict
if s == 'Dropped': # D->D or R->D
output[fid][-1] += 1
elif last[fid] == 'Dropped': # D->R
output[fid].append(0)
else:
output[fid] = [0]
if s == 'Dropped':
output[fid]=[1]
last[fid] = s
alldbls = []
for x in output:
if output[x][-1] == 0:
del output[x][-1]
#print x,"---", output[x]
alldbls = alldbls + output[x]
#sys.exit(0)
#print sorted(alldbls), len(alldbls)
a = Counter(alldbls)
DD=[]
DD = sorted(a.items())
A=0
#print DD
L1=0
for L in DD:
L1 =L[1]+L1
#print L1
for k in DD: #calculate the probability
K=k[1]/L1
print '{0} {1:.5f}'.format(k[0], K)
A = A+K
#print A