forked from Sonnbc/modelCheckingNobi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
111 lines (90 loc) · 2.74 KB
/
plot.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import matplotlib.pyplot as plt
plt.rcParams['backend'] = "template"
import sys
import re
import numpy as np
from collections import namedtuple
import hashlib
def drop_outliers(data):
mean_duration = np.mean(data)
std_dev_one_test = np.std(data)
filtered = [ e for e in data if (abs(e - mean_duration) <= std_dev_one_test)]
return filtered
def getbins(latency, count_bins):
minv = min(latency)
maxv = max(latency)
diff = maxv - minv
bins = []
tmp = 0
while( tmp < count_bins):
bins.append( minv + (diff/count_bins)*tmp)
tmp = tmp + 1
# print bins
return bins
def getallreads(filename):
content = []
with open(filename) as f:
content = f.readlines()
return content
def getreadsforbin(all_reads, b, prev_bin):
count = 0
for r in all_reads:
if ( int(r) <= b and int(r) >= prev_bin):
count = count + 1
return count
def getreadsperBin(all_reads, bins):
read_per_bin = {}
prev_bin = 0
for b in bins:
reads_in_bin = getreadsforbin(all_reads, b, prev_bin)
prev_bin = b
read_per_bin[b] = reads_in_bin
return read_per_bin
def main():
filename = sys.argv[1]
filename_all_reads = sys.argv[2]
with open(filename) as f:
content = f.readlines()
# Note that the latency values are already sorted
latency = []
for l in content:
latency.append(int(l))
# Remove the outliers
#latency = drop_outliers(latency)
# Find bins
count_bins = 20
bins = getbins(latency, count_bins)
all_reads = getallreads(filename_all_reads)
#print "Size of all reads is = " + str(int(len(all_reads)))
# Find good probability in each bin
reads_per_bin = getreadsperBin(all_reads, bins)
#print reads_per_bin
good_reads_per_bin = getreadsperBin(latency, bins)
#print good_reads_per_bin
# Get percentage of good per bin
result = {}
prev_key = 0;
for k in good_reads_per_bin.keys():
if (reads_per_bin[k] == 0):
if (prev_key != 0):
result[k] = result[prev_key]
continue
result[k] = good_reads_per_bin[k] / float(reads_per_bin[k])
if (result[k] <= 0.2 and prev_key != 0):
result[k] = result[prev_key]
prev_key = k
#print "--------------------------"
#print result
f = open("result.txt", "w+")
for k in result.keys():
f.write(str(result[k]) + "," + str(k))
f.write('\n')
f.close
D = result
plt.bar(range(len(D)), D.values(), align='center')
#plt.hist(latency, bins=bins)
plt.title('Read your write consistency')
plt.xlabel('Issuing Latency L(time unit)')
plt.ylabel('Prob. of satisfying RYW')
plt.show()
if __name__ == "__main__": main()