| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Use of this source code is governed by a BSD-style license | 4 # Use of this source code is governed by a BSD-style license |
| 5 # that can be found in the LICENSE file in the root of the source | 5 # that can be found in the LICENSE file in the root of the source |
| 6 # tree. An additional intellectual property rights grant can be found | 6 # tree. An additional intellectual property rights grant can be found |
| 7 # in the file PATENTS. All contributing project authors may | 7 # in the file PATENTS. All contributing project authors may |
| 8 # be found in the AUTHORS file in the root of the source tree. | 8 # be found in the AUTHORS file in the root of the source tree. |
| 9 | 9 |
| 10 # This script is used to plot simulation dynamics. | 10 # This script is used to plot simulation dynamics. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return self._subplot | 41 return self._subplot |
| 42 | 42 |
| 43 def getYMax(self): | 43 def getYMax(self): |
| 44 return self._y_max | 44 return self._y_max |
| 45 | 45 |
| 46 def getNumberOfFlows(self): | 46 def getNumberOfFlows(self): |
| 47 return len(self._samples) | 47 return len(self._samples) |
| 48 | 48 |
| 49 | 49 |
| 50 def addSample(self, line): | 50 def addSample(self, line): |
| 51 groups = re.search(r'/\d_(\w+)#\d@(\w*)', line) | 51 groups = re.search(r'_(((\d)+((,(\d)+)*))_(\D+))#\d@(\S+)', line) |
| 52 |
| 53 # Each variable will be plotted in a separated box. |
| 52 var_name = groups.group(1) | 54 var_name = groups.group(1) |
| 53 alg_name = groups.group(2) | 55 alg_name = groups.group(8) |
| 56 |
| 57 alg_name = alg_name.replace('_', ' ') |
| 54 | 58 |
| 55 if alg_name not in self._samples.keys(): | 59 if alg_name not in self._samples.keys(): |
| 56 self._samples[alg_name] = {} | 60 self._samples[alg_name] = {} |
| 57 | 61 |
| 58 if var_name not in self._samples[alg_name].keys(): | 62 if var_name not in self._samples[alg_name].keys(): |
| 59 self._samples[alg_name][var_name] = [] | 63 self._samples[alg_name][var_name] = [] |
| 60 | 64 |
| 61 sample = re.search(r'(\d+\.\d+)\t([-]?\d+\.\d+)', line) | 65 sample = re.search(r'(\d+\.\d+)\t([-]?\d+\.\d+)', line) |
| 66 |
| 62 s = (sample.group(1),sample.group(2)) | 67 s = (sample.group(1),sample.group(2)) |
| 63 self._samples[alg_name][var_name].append(s) | 68 self._samples[alg_name][var_name].append(s) |
| 64 | 69 |
| 65 def plotVar(v, ax, show_legend, show_x_label): | 70 def plotVar(v, ax, show_legend, show_x_label): |
| 66 if show_x_label: | 71 if show_x_label: |
| 67 ax.set_xlabel(v.getXLabel(), fontsize='large') | 72 ax.set_xlabel(v.getXLabel(), fontsize='large') |
| 68 ax.set_ylabel(v.getYLabel(), fontsize='large') | 73 ax.set_ylabel(v.getYLabel(), fontsize='large') |
| 69 | 74 |
| 70 for alg in v._samples.keys(): | 75 for alg in v._samples.keys(): |
| 71 i = 1 | 76 i = 1 |
| 72 for series in v._samples[alg].keys(): | 77 for series in v._samples[alg].keys(): |
| 73 x = [sample[0] for sample in v._samples[alg][series]] | 78 x = [sample[0] for sample in v._samples[alg][series]] |
| 74 y = [sample[1] for sample in v._samples[alg][series]] | 79 y = [sample[1] for sample in v._samples[alg][series]] |
| 75 x = numpy.array(x) | 80 x = numpy.array(x) |
| 76 y = numpy.array(y) | 81 y = numpy.array(y) |
| 77 line = plt.plot(x, y, label=alg, linewidth=4.0) | 82 line = plt.plot(x, y, label=alg, linewidth=4.0) |
| 78 colormap = {'Available1':'#AAAAAA', | 83 colormap = {'Available1':'#AAAAAA', |
| 79 'Available2':'#AAAAAA', | 84 'Available2':'#AAAAAA', |
| 80 'GCC1':'#80D000', | 85 'GCC1':'#80D000', |
| 81 'GCC2':'#008000', | 86 'GCC2':'#008000', |
| 82 'GCC3':'#00F000', | 87 'GCC3':'#00F000', |
| 83 'GCC4':'#00B000', | 88 'GCC4':'#00B000', |
| 84 'GCC5':'#70B020', | 89 'GCC5':'#70B020', |
| 85 'NADA1':'#0000AA', | 90 'NADA1':'#0000AA', |
| 86 'NADA2':'#A0A0FF', | 91 'NADA2':'#A0A0FF', |
| 87 'NADA3':'#0000FF', | 92 'NADA3':'#0000FF', |
| 88 'NADA4':'#C0A0FF', | 93 'NADA4':'#C0A0FF', |
| 89 'NADA5':'#9060B0', | 94 'NADA5':'#9060B0',} |
| 90 'TCP1':'#AAAAAA', | |
| 91 'TCP2':'#AAAAAA', | |
| 92 'TCP3':'#AAAAAA', | |
| 93 'TCP4':'#AAAAAA', | |
| 94 'TCP5':'#AAAAAA', | |
| 95 'TCP6':'#AAAAAA', | |
| 96 'TCP7':'#AAAAAA', | |
| 97 'TCP8':'#AAAAAA', | |
| 98 'TCP9':'#AAAAAA', | |
| 99 'TCP10':'#AAAAAA',} | |
| 100 | 95 |
| 101 plt.setp(line, color=colormap[alg + str(i)]) | 96 key = alg + str(i) |
| 97 if key in colormap: |
| 98 plt.setp(line, color=colormap[key]) |
| 99 elif alg == 'TCP': |
| 100 plt.setp(line, color='#AAAAAA') |
| 101 else: |
| 102 plt.setp(line, color='#654321') |
| 103 |
| 102 if alg.startswith('Available'): | 104 if alg.startswith('Available'): |
| 103 plt.setp(line, linestyle='--') | 105 plt.setp(line, linestyle='--') |
| 104 plt.grid(True) | 106 plt.grid(True) |
| 105 | 107 |
| 106 x1, x2, y1, y2 = plt.axis() | 108 x1, x2, y1, y2 = plt.axis() |
| 107 if v.getYMax() >= 0: | 109 if v.getYMax() >= 0: |
| 108 y2 = v.getYMax() | 110 y2 = v.getYMax() |
| 109 plt.axis((0, x2, 0, y2)) | 111 plt.axis((0, x2, 0, y2)) |
| 110 i += 1 | 112 i += 1 |
| 111 | 113 |
| 112 if show_legend: | 114 if show_legend: |
| 113 legend = plt.legend(loc='upper right', shadow=True, | 115 legend = plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.40), |
| 114 fontsize='large', ncol=len(v._samples)) | 116 shadow=True, fontsize='medium', ncol=len(v._samples)) |
| 115 | 117 |
| 116 if __name__ == '__main__': | 118 if __name__ == '__main__': |
| 117 | 119 |
| 118 variables = [ | 120 variables = [ |
| 119 ('Throughput_kbps', "Time (s)", "Throughput (kbps)", 1, 4000), | 121 ('Throughput_kbps', "Time (s)", "Throughput (kbps)", 1, 4000), |
| 120 ('Delay_ms', "Time (s)", "One-way Delay (ms)", 2, 500), | 122 ('Delay_ms', "Time (s)", "One-way Delay (ms)", 2, 500), |
| 121 ('Packet_Loss', "Time (s)", "Packet Loss Ratio", 3, 1.0), | 123 ('Packet_Loss', "Time (s)", "Packet Loss Ratio", 3, 1.0), |
| 122 ] | 124 ] |
| 123 | 125 |
| 124 var = [] | 126 var = [] |
| (...skipping 20 matching lines...) Expand all Loading... |
| 145 n = var[-1].getSubplot() | 147 n = var[-1].getSubplot() |
| 146 i = 0 | 148 i = 0 |
| 147 for v in var: | 149 for v in var: |
| 148 ax = fig.add_subplot(n, 1, v.getSubplot()) | 150 ax = fig.add_subplot(n, 1, v.getSubplot()) |
| 149 plotVar(v, ax, i == 0, i == n - 1) | 151 plotVar(v, ax, i == 0, i == n - 1) |
| 150 i += 1 | 152 i += 1 |
| 151 | 153 |
| 152 #fig.savefig(test_name+".jpg") | 154 #fig.savefig(test_name+".jpg") |
| 153 plt.show() | 155 plt.show() |
| 154 | 156 |
| OLD | NEW |