forked from wevertoncordeiro/TraceCollection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze5_plot_scatter_peers_over_time.py
147 lines (120 loc) · 3.66 KB
/
analyze5_plot_scatter_peers_over_time.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python
'''
'''
import sys, time, getopt, urllib, random, struct, commands, os, string, numpy, datetime
import subprocess
from analyze0_main import *
def print_usage():
print " Scatter Plot of Peers "
print ""
print "USAGE: [OPTIONS] file_name_1 file_name_2 ... "
print "\nOptions:"
print "-h --help show this usage help message"
print "-d --debug show some debug messages"
print ""
def plot_header():
return "# File generated by %s on %s" % (os.path.basename(__file__), datetime.datetime.now())
if __name__ == '__main__':
# HEADER
print "\n"
script_name = os.path.basename(__file__)
print script_name.upper()
print "-" * len(script_name)
# INITIALIZE VARIABLES
debug = False
file_name_input = ""
outputFileName = ""
count = 1
try:
optlist, args = getopt.gnu_getopt(sys.argv[count:], 'hdt:', ['--help', '--debug'])
for o, a in optlist:
if o in ["-h", "--help"]:
print_usage()
sys.exit(0)
elif o in ["-d", "--debug"]:
count += 1
debug = True
except getopt.GetoptError, e:
print "Exception:", e
print "Please, use -h or --help for instructions on how to use this script."
sys.exit(-1)
print ""
print "OPTIONS"
print "-------"
print "\tDebug :", debug
print ""
print "INPUT"
print "-----"
print "\tFiles:", sys.argv[count:]
print ""
print "MAKING DIRS"
print "-----------"
dir_data = Dirs().plots + "02_scatter/00_data/"
dir_plot = Dirs().plots + "02_scatter/01_plot/"
dir_eps = Dirs().plots + "02_scatter/02_eps/"
dir_png = Dirs().plots + "02_scatter/03_png/"
for dir in [dir_plot, dir_eps, dir_data, dir_png]:
cmd = "mkdir -p " + dir
run_cmd(cmd, 1, True)
print "PLOTTING"
print "--------"
x_begin = 0
x_end = 2000
y_begin = 0
y_end = 10
count_file = 1
for file_name_input in sys.argv[count:]:
header = "FILE (%d/%d)" %(count_file, len(sys.argv[count:]))
print "\t%s"% header
print "\t%s" % ("-"*len(header))
count_file += 1
print ""
#file_name_base = file_name_input.split(".txt")[0]
print "\t\tfile_name_input :", file_name_input,
if not os.path.isfile(file_name_input):
print "[ERROR]"
print ""
print "\t\tFILE NOT FOUND! :", file_name_input
print "\n\n"
else:
print "[OK]"
file_name_base = os.path.basename(file_name_input)
print "\t\tfile_name_base :", file_name_base
file_data_name = "%s%s.txt" % (dir_data, file_name_base)
print "\t\tfile_data_name :", file_data_name
file_name_plot = "%s%s.plot" % (dir_plot, file_name_base)
print "\t\tfile_name_plot :", file_name_plot
file_name_eps = "%s%s.eps" % (dir_eps, file_name_base)
print "\t\tfile_name_eps :", file_name_eps
file_name_png = "%s%s.png" % (dir_png, file_name_base)
print "\t\tfile_name_png :", file_name_png
print ""
# window time_min IP:port peerId
cmd = "cat %s | cut -d ' ' -f 1,4 | sort -u > %s" % (file_name_input, file_data_name)
run_cmd(cmd, 2, True)
cmd = 'head -n 2 %s | grep -v "#"' % file_name_input
cmd_out = commands.getoutput(cmd).split("\t")
plot = plot_header()
plot += '''
unset grid
unset key
set xlabel "Sampling No."
set ylabel "Peer IP (anonymized)"
set xrange [0:]
set yrange [0:]
set term postscript eps enhanced color "Helvetica" 24 lw 2
set output "%s"
plot '%s' using 1:2 title "sampling" with points lc 1 pt 1 ps 1
''' % (file_name_eps, file_data_name)
plot += "\n"
plot += 'set output "%s"\n' % file_name_png
plot += "set term png\n"
plot += "replot\n"
file_plot = open(file_name_plot, 'w', 1)
file_plot.write(plot)
file_plot.close()
cmd = "gnuplot %s" % file_name_plot
run_cmd(cmd, 2, True)
print ""
print "%s %s finished!" % (now_str(), script_name)
print ""