Changeset d5eb96d
 Timestamp:
 11/20/18 11:20:15 (2 years ago)
 Branches:
 develop
 Children:
 7395b09
 Parents:
 d83b5e72
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

examples/stats/ipdistgenplot.py
r0d451ef rd5eb96d 4 4 import subprocess 5 5 import os 6 7 def normalise(min, max, value): 8 return ((value  min) / float((max  min))) 9 6 10 7 11 # Ensure a data directory was supplied … … 74 78 count_src[k][int(lines[x+2].split()[(k*4)+2])] = int(lines[x+2].split()[(k*4)+3]) 75 79 count_dst[k][int(lines[x+2].split()[(k*4)+4])] = int(lines[x+2].split()[(k*4)+5]) 76 # output the results to the timeseries file 80 # output the results to the timeseries files 77 81 tmp_src = [] 78 82 tmp_dst = [] … … 102 106 tmp_dst[x].close() 103 107 108 # create tmp file for cdf plots 109 with open(dir + "/ipdist" + tick + ".tmp", "w") as tmp: 110 for x in range(4): 111 total_src = 0 112 total_dst = 0 113 min_src = 0 114 min_dst = 0 115 max_src = 0 116 max_dst = 0 117 118 # work out min and max needed to normalise the data for CDF 119 for i in range(256): 120 curr_src = count_src[x][i] 121 curr_dst = count_dst[x][i] 122 if curr_src < min_src or i == 0: 123 min_src = 0 124 if curr_dst < min_dst or i == 0: 125 min_dst = 0 126 # cumulative count 127 max_src = max_src + curr_src 128 max_dst = max_dst + curr_dst 129 130 for i in range(256): 131 total_src = total_src + count_src[x][i] 132 total_dst = total_dst + count_dst[x][i] 133 tmp.write(str(normalise(min_src, max_src, total_src)) + "\t" + str(i) + "\t" + str(normalise(min_dst, max_dst, total_dst)) + "\t" + str(i) + "\n") 134 tmp.write("\n\n") 104 135 105 136 # create interval plots … … 111 142 plot.stdin.write("set term pngcairo enhanced size 1280,960\n") 112 143 plot.stdin.write("set output '" + dir + "/" + filename + "octet" + str(x+1) + ".png'\n") 113 plot.stdin.write("set multiplot layout 2,1\n")144 plot.stdin.write("set multiplot layout 3,1\n") 114 145 plot.stdin.write("set title 'IP Distribution  " + tick + "'\n") 115 146 plot.stdin.write("set xrange[0:255]\n") … … 132 163 plot.stdin.write("SOURCESKEW_min title 'Source Skewness' axes x1y2,") 133 164 plot.stdin.write("DESTSKEW_min title 'Destination Skewness' axes x1y2\n") 165 plot.stdin.write("unset xrange\n") 166 plot.stdin.write("unset y2range\n") 134 167 plot.stdin.write("unset y2tics\n") 135 168 plot.stdin.write("unset y2label\n") 169 plot.stdin.write("unset ylabel\n") 136 170 plot.stdin.write("unset arrow\n") 137 171 plot.stdin.write("unset label 1\nunset label 2\nunset label 3\nunset label 4\nunset label 5\nunset label 6\n") 172 plot.stdin.write("set title 'CDF distribution'\n") 173 plot.stdin.write("set ylabel 'Cumulative %'\n") 174 plot.stdin.write("set xlabel 'Prefix'\n") 175 plot.stdin.write("set key right bottom\n") 176 plot.stdin.write("plot '" + dir + "/ipdist" + tick + ".tmp' using 2:1 index " + str(x) + " with lines title 'Source octet " + str(x+1) + "',") 177 plot.stdin.write("'" + dir + "/ipdist" + tick + ".tmp' using 4:3 index " + str(x) + " with lines title 'Destination octet " + str(x+1) + "'\n") 138 178 plot.stdin.write("set title 'Zipf Distribution'\n") 139 179 plot.stdin.write("set xlabel 'Rank'\n") 180 plot.stdin.write("set xrange [1:255]\n") 140 181 plot.stdin.write("set ylabel 'Frequency'\n") 141 182 plot.stdin.write("set logscale xy 10\n") 142 plot.stdin.write("set xrange[1:255]\n") 143 plot.stdin.write("set xtics 0,10,255\n") 183 plot.stdin.write("set key top right\n") 144 184 plot.stdin.write("plot '" + dir + "/" + dataFile + "' using 2:" + str((x*4)+4) + " index 0 title 'Source octet " + str(x+1) + "',") 145 185 plot.stdin.write("'' using 2:" + str((x*4)+6) + " index 0 title 'Destination octet " + str(x+1) + "'\n") … … 147 187 plot.communicate() 148 188 189 # cleanup the temp file 190 os.remove(dir + "/ipdist" + tick + ".tmp") 149 191 150 192 # Generate plots for the timeseries data captured over the entire trace … … 179 221 plot.stdin.flush() 180 222 plot.communicate() 181
Note: See TracChangeset
for help on using the changeset viewer.