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

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

Issue 1237903003: Modified histogram shell plot script, added python dynamics plot script (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 5 years, 5 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 #
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
6 # tree. An additional intellectual property rights grant can be found
7 # in the file PATENTS. All contributing project authors may
8 # be found in the AUTHORS file in the root of the source tree.
9
10 # This script is used to plot simulation dynamics.
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.
13
14 import matplotlib
15 import matplotlib.pyplot as plt
16 import math
17 import numpy
18 import re
19 import sys
20
21
22 class Variable:
23 def __init__(self, variable):
24 self._ID = variable[0]
25 self._xlabel = variable[1]
26 self._ylabel = variable[2]
27 self._subplot = variable[3]
28 self._y_max = variable[4]
29 self._samples = dict()
30
31 def getID(self):
32 return self._ID
33
34 def getXLabel(self):
35 return self._xlabel
36
37 def getYLabel(self):
38 return self._ylabel
39
40 def getSubplot(self):
41 return self._subplot
42
43 def getYMax(self):
44 return self._y_max
45
46 def getNumberOfFlows(self):
47 return len(self._samples)
48
49
50 def addSample(self, line):
51 groups = re.search(r'/\d_(\w+)#\d@(\w*)', line)
52 var_name = groups.group(1)
53 alg_name = groups.group(2)
54
55 if alg_name not in self._samples.keys():
56 self._samples[alg_name] = {}
57
58 if var_name not in self._samples[alg_name].keys():
59 self._samples[alg_name][var_name] = []
60
61 sample = re.search(r'(\d+\.\d+)\t([-]?\d+\.\d+)', line)
62 s = (sample.group(1),sample.group(2))
63 self._samples[alg_name][var_name].append(s)
64
65 def plotVar(v, ax, show_legend, show_x_label):
66 if show_x_label:
67 ax.set_xlabel(v.getXLabel(), fontsize='large')
68 ax.set_ylabel(v.getYLabel(), fontsize='large')
69
70 for alg in v._samples.keys():
71 i = 1
72 for series in v._samples[alg].keys():
73 x = [sample[0] for sample in v._samples[alg][series]]
74 y = [sample[1] for sample in v._samples[alg][series]]
75 x = numpy.array(x)
76 y = numpy.array(y)
77 line = plt.plot(x, y, label=alg, linewidth=4.0)
78 colormap = {'Available1':'#AAAAAA',
79 'Available2':'#AAAAAA',
80 'GCC1':'#80D000',
81 'GCC2':'#008000',
82 'GCC3':'#00F000',
83 'GCC4':'#00B000',
84 'GCC5':'#70B020',
85 'NADA1':'#0000AA',
86 'NADA2':'#A0A0FF',
87 'NADA3':'#0000FF',
88 'NADA4':'#C0A0FF',
89 '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
101 plt.setp(line, color=colormap[alg + str(i)])
102 if alg.startswith('Available'):
103 plt.setp(line, linestyle='--')
104 plt.grid(True)
105
106 x1, x2, y1, y2 = plt.axis()
107 if v.getYMax() >= 0:
108 y2 = v.getYMax()
109 plt.axis((0, x2, 0, y2))
110 i += 1
111
112 if show_legend:
113 legend = plt.legend(loc='upper right', shadow=True,
114 fontsize='large', ncol=len(v._samples))
115
116 if __name__ == '__main__':
117
118 variables = [
119 ('Throughput_kbps', "Time (s)", "Throughput (kbps)", 1, 4000),
120 ('Delay_ms', "Time (s)", "One-way Delay (ms)", 2, 500),
121 ('Packet_Loss', "Time (s)", "Packet Loss Ratio", 3, 1.0),
122 ]
123
124 var = []
125
126 # Create objects.
127 for variable in variables:
128 var.append(Variable(variable))
129
130 # Add samples to the objects.
131 for line in sys.stdin:
132 if line.startswith("[ RUN ]"):
133 test_name = re.search('\.(\w+)', line).group(1)
134 if line.startswith("PLOT"):
135 for v in var:
136 if v.getID() in line:
137 v.addSample(line)
138
139 matplotlib.rcParams.update({'font.size': 20})
140
141 # Plot variables.
142 fig = plt.figure()
143
144 # Offest and threshold on the same plot.
145 n = var[-1].getSubplot()
146 i = 0
147 for v in var:
148 ax = fig.add_subplot(n, 1, v.getSubplot())
149 plotVar(v, ax, i == 0, i == n - 1)
150 i += 1
151
152 #fig.savefig(test_name+".jpg")
153 plt.show()
154
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698