Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/plot_dynamics.py

Issue 1296793004: Fixing Pylint errors for plot_dynamics.py (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
11 # Able to plot each flow separately. Other plot boxes can be added, 11 # Able to plot each flow separately. Other plot boxes can be added,
12 # currently one for Throughput, one for Latency and one for Packet Loss. 12 # currently one for Throughput, one for Latency and one for Packet Loss.
13 13
14 import matplotlib 14 import matplotlib
15 import matplotlib.pyplot as plt 15 import matplotlib.pyplot as plt
16 import math
17 import numpy 16 import numpy
18 import re 17 import re
19 import sys 18 import sys
20 19
21 20
22 class Variable: 21 class Variable(object):
23 def __init__(self, variable): 22 def __init__(self, variable):
24 self._ID = variable[0] 23 self._ID = variable[0]
25 self._xlabel = variable[1] 24 self._xlabel = variable[1]
26 self._ylabel = variable[2] 25 self._ylabel = variable[2]
27 self._subplot = variable[3] 26 self._subplot = variable[3]
28 self._y_max = variable[4] 27 self._y_max = variable[4]
29 self._samples = dict() 28 self.samples = dict()
30 29
31 def getID(self): 30 def getID(self):
32 return self._ID 31 return self._ID
33 32
34 def getXLabel(self): 33 def getXLabel(self):
35 return self._xlabel 34 return self._xlabel
36 35
37 def getYLabel(self): 36 def getYLabel(self):
38 return self._ylabel 37 return self._ylabel
39 38
40 def getSubplot(self): 39 def getSubplot(self):
41 return self._subplot 40 return self._subplot
42 41
43 def getYMax(self): 42 def getYMax(self):
44 return self._y_max 43 return self._y_max
45 44
46 def getNumberOfFlows(self): 45 def getNumberOfFlows(self):
47 return len(self._samples) 46 return len(self.samples)
48 47
49 48
50 def addSample(self, line): 49 def addSample(self, line):
51 groups = re.search(r'_(((\d)+((,(\d)+)*))_(\D+))#\d@(\S+)', line) 50 groups = re.search(r'_(((\d)+((,(\d)+)*))_(\D+))#\d@(\S+)', line)
52 51
53 # Each variable will be plotted in a separated box. 52 # Each variable will be plotted in a separated box.
54 var_name = groups.group(1) 53 var_name = groups.group(1)
55 alg_name = groups.group(8) 54 alg_name = groups.group(8)
56 55
57 alg_name = alg_name.replace('_', ' ') 56 alg_name = alg_name.replace('_', ' ')
58 57
59 if alg_name not in self._samples.keys(): 58 if alg_name not in self.samples.keys():
60 self._samples[alg_name] = {} 59 self.samples[alg_name] = {}
61 60
62 if var_name not in self._samples[alg_name].keys(): 61 if var_name not in self.samples[alg_name].keys():
63 self._samples[alg_name][var_name] = [] 62 self.samples[alg_name][var_name] = []
64 63
65 sample = re.search(r'(\d+\.\d+)\t([-]?\d+\.\d+)', line) 64 sample = re.search(r'(\d+\.\d+)\t([-]?\d+\.\d+)', line)
66 65
67 s = (sample.group(1),sample.group(2)) 66 s = (sample.group(1), sample.group(2))
68 self._samples[alg_name][var_name].append(s) 67 self.samples[alg_name][var_name].append(s)
69 68
70 def plotVar(v, ax, show_legend, show_x_label): 69 def plotVar(v, ax, show_legend, show_x_label):
71 if show_x_label: 70 if show_x_label:
72 ax.set_xlabel(v.getXLabel(), fontsize='large') 71 ax.set_xlabel(v.getXLabel(), fontsize='large')
73 ax.set_ylabel(v.getYLabel(), fontsize='large') 72 ax.set_ylabel(v.getYLabel(), fontsize='large')
74 73
75 for alg in v._samples.keys(): 74 for alg in v.samples.keys():
76 75
77 for series in v._samples[alg].keys(): 76 for series in v.samples[alg].keys():
78 77
79 x = [sample[0] for sample in v._samples[alg][series]] 78 x = [sample[0] for sample in v.samples[alg][series]]
80 y = [sample[1] for sample in v._samples[alg][series]] 79 y = [sample[1] for sample in v.samples[alg][series]]
81 x = numpy.array(x) 80 x = numpy.array(x)
82 y = numpy.array(y) 81 y = numpy.array(y)
83 82
84 line = plt.plot(x, y, label=alg, linewidth=4.0) 83 line = plt.plot(x, y, label=alg, linewidth=4.0)
85 84
86 colormap = {'Available0':'#AAAAAA', 85 colormap = {'Available0':'#AAAAAA',
87 'Available1':'#AAAAAA', 86 'Available1':'#AAAAAA',
88 'GCC0':'#80D000', 87 'GCC0':'#80D000',
89 'GCC1':'#008000', 88 'GCC1':'#008000',
90 'GCC2':'#00F000', 89 'GCC2':'#00F000',
(...skipping 12 matching lines...) Expand all
103 plt.setp(line, color=colormap[key]) 102 plt.setp(line, color=colormap[key])
104 elif alg == 'TCP': 103 elif alg == 'TCP':
105 plt.setp(line, color='#AAAAAA') 104 plt.setp(line, color='#AAAAAA')
106 else: 105 else:
107 plt.setp(line, color='#654321') 106 plt.setp(line, color='#654321')
108 107
109 if alg.startswith('Available'): 108 if alg.startswith('Available'):
110 plt.setp(line, linestyle='--') 109 plt.setp(line, linestyle='--')
111 plt.grid(True) 110 plt.grid(True)
112 111
113 x1, x2, y1, y2 = plt.axis() 112 # x1, x2, y1, y2
113 _, x2, _, y2 = plt.axis()
114 if v.getYMax() >= 0: 114 if v.getYMax() >= 0:
115 y2 = v.getYMax() 115 y2 = v.getYMax()
116 plt.axis((0, x2, 0, y2)) 116 plt.axis((0, x2, 0, y2))
117 117
118 if show_legend: 118 if show_legend:
119 legend = plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.40), 119 plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.40),
120 shadow=True, fontsize='large', ncol=len(v._samples)) 120 shadow=True, fontsize='large', ncol=len(v.samples))
121 121
122 if __name__ == '__main__': 122 def main():
123
124 variables = [ 123 variables = [
125 ('Throughput_kbps', "Time (s)", "Throughput (kbps)", 1, 4000), 124 ('Throughput_kbps', "Time (s)", "Throughput (kbps)", 1, 4000),
126 ('Delay_ms', "Time (s)", "One-way Delay (ms)", 2, 500), 125 ('Delay_ms', "Time (s)", "One-way Delay (ms)", 2, 500),
127 ('Packet_Loss', "Time (s)", "Packet Loss Ratio", 3, 1.0), 126 ('Packet_Loss', "Time (s)", "Packet Loss Ratio", 3, 1.0),
128 # ('Sending_Estimate_kbps', "Time (s)", "Sending Estimate (kbps)", 127 # ('Sending_Estimate_kbps', "Time (s)", "Sending Estimate (kbps)",
129 # 4, 4000), 128 # 4, 4000),
130 ] 129 ]
131 130
132 var = [] 131 var = []
133 132
134 # Create objects. 133 # Create objects.
135 for variable in variables: 134 for variable in variables:
136 var.append(Variable(variable)) 135 var.append(Variable(variable))
137 136
138 # Add samples to the objects. 137 # Add samples to the objects.
139 for line in sys.stdin: 138 for line in sys.stdin:
140 if line.startswith("[ RUN ]"): 139 # if line.startswith("[ RUN ]"):
pbos-webrtc 2015/08/25 08:43:55 Don't comment these out, since the fig.savefig bel
141 test_name = re.search('\.(\w+)', line).group(1) 140 # test_name = re.search(r'\.(\w+)', line).group(1)
142 if line.startswith("PLOT"): 141 if line.startswith("PLOT"):
143 for v in var: 142 for v in var:
144 if v.getID() in line: 143 if v.getID() in line:
145 v.addSample(line) 144 v.addSample(line)
146 145
147 matplotlib.rcParams.update({'font.size': 48/len(variables)}) 146 matplotlib.rcParams.update({'font.size': 48/len(variables)})
148 147
149 # Plot variables. 148 # Plot variables.
150 fig = plt.figure() 149 fig = plt.figure()
151 150
152 # Offest and threshold on the same plot. 151 # Offest and threshold on the same plot.
153 n = var[-1].getSubplot() 152 n = var[-1].getSubplot()
154 i = 0 153 i = 0
155 for v in var: 154 for v in var:
156 ax = fig.add_subplot(n, 1, v.getSubplot()) 155 ax = fig.add_subplot(n, 1, v.getSubplot())
157 plotVar(v, ax, i == 0, i == n - 1) 156 plotVar(v, ax, i == 0, i == n - 1)
158 i += 1 157 i += 1
159 158
160 #fig.savefig(test_name+".jpg") 159 # fig.savefig(test_name+".jpg")
161 plt.show() 160 plt.show()
162 161
162 if __name__ == '__main__':
163 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698