-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfacebook_plot_cdfs.py
73 lines (55 loc) · 1.47 KB
/
facebook_plot_cdfs.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
from __future__ import division
import pdb
#import sys
#def hello(variable):
# print variable.split()
#data = sys.stdin.read()
#url_list = data.split()
#hello(data)
import sys
from csv import reader
from collections import defaultdict
import math
import numpy as np
import os
import matplotlib.pyplot as plt
def cdf_plot(url, a, country):
#a = np.loadtxt("tempfile.txt", usecols = [1])
#print a
a = np.array(map(float, a))
max_val = int(math.ceil(np.amax(a, axis = 0)))
z = max_val + 1
cum = [0]*z
for i in xrange(max_val + 1):
for j in xrange(len(a)):
if a[j] <= i:
cum[i] = cum[i] + 1
max_cum = np.amax(cum, axis = 0)
#pdb.set_trace()
cum2 = [float(x/max_cum) for x in cum]
x = [i for i in xrange(z)]
plt.style.use('ggplot')
plt.title('CDF for ' + url + ' on Exit Nodes in ' + country)
plt.ylabel('Response Times')
plt.xlabel('CDF')
plt.legend()
plt.grid(True,color='k')
plt.plot(x,cum2, linewidth = 3)
plt.show()
def get_delays(filename, country):
d = defaultdict(list)
cmd = "awk '{print $3,$2}' " + filename + " > tempfile.txt"
os.system(cmd)
#pdb.set_trace()
with open('tempfile.txt') as f:
for k, v in reader(f, delimiter =" "):
d[k].append(v)
for fingerprint, delays in d.iteritems():
print fingerprint, delays
cdf_plot(fingerprint, delays, country)
def main():
filename = sys.argv[1]
country = sys.argv[2]
get_delays(filename, country)
if __name__ == "__main__":
main()