-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotter.py
123 lines (94 loc) · 3.45 KB
/
plotter.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
import os
import sys
import matplotlib.pyplot as plt
import re
NUM_CHUNKS = 65
class Plotter:
def __init__(self):
self.QOEs = []
self.lambd = 1
self.mu = 3000
self.mu_s = 3000
self.numPlots = 0
def clearQOEs(self):
self.QOEs = []
def addQOE(self, filename):
bitrates, downloadTimes, bufferSizes, startupTime = self.parseRun(filename)
numChunks = len(downloadTimes)
quality = variation = rebuffering = 0
for k in range(numChunks):
quality += bitrates[k]
rebuffering += downloadTimes[k] - bufferSizes[k]
if k == 0:
continue
variation += bitrates[k] - bitrates[k-1]
qoe = quality - self.lambd * variation - self.mu * rebuffering \
- self.mu_s * startupTime
self.QOEs.append(qoe)
def parseRun(self, filename):
bitrates = [0] * NUM_CHUNKS
downloadTimes = [0] * NUM_CHUNKS
bufferSizes = [0] * NUM_CHUNKS
startupTime = None
with open(filename) as f:
for line in f:
if re.match('Buffer size', line):
idx, val = line.split()[-2:]
bufferSizes[int(idx)-1] = int(val)
if re.match('Chunk bitrate', line):
idx, val = line.split()[-2:]
bitrates[int(idx)-1] = int(val)
if re.match('Download time', line):
time = int(line.split(':')[1].strip())
downloadTimes.append(time)
if re.match('Startup', line):
time = int(line.split(':')[1].strip())
startupTime = time
return bitrates, downloadTimes, bufferSizes, startupTime
def normalize(self, data, opt=None):
if not opt:
opt = max(data)
return map(lambda d: float(d) / opt, data)
def startPlot(self):
plt.rcParams["figure.figsize"] = [20, 8]
def plotOne(self, title):
filteredQOEs = sorted(self.QOEs)[5:-5]
plt.subplot(1, 3, self.numPlots)
plt.plot(filteredQOEs, 'o')
plt.tick_params(
axis='x',
which='both',
bottom='off',
top='off',
labelbottom='off')
plt.ylabel('QOE value')
plt.title(title)
self.numPlots += 1
def savePlot(self, plotname):
plt.savefig(plotname)
plt.close()
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'Usage: plotter.py <directory-name>'
exit(0)
topDir = sys.argv[1].replace('/', '')
dirs = ['output-fcc-traces', 'output-hsdpa-traces', 'output-synthetic-traces']
titles = ['FCC', 'HSDPA', 'Synthetic']
plotter = Plotter()
plotter.startPlot()
for dirname, title in zip(dirs, titles):
fullDir = topDir + '/' + dirname
for filename in os.listdir(fullDir):
plotter.addQOE(os.path.join(fullDir, filename))
plotter.plotOne(title)
plotter.clearQOEs()
plotter.savePlot(topDir + '/VLC_QOE_Outputs.png')
'''if __name__ == '__main__':
if len(sys.argv) != 3:
print 'Usage: plotter.py <directory name> <output name>'
exit(0)
dirname, outname = sys.argv[1:3]
plotter = Plotter()
for filename in os.listdir(dirname):
plotter.addQOE(os.path.join(dirname, filename))
plotter.plot(outname)'''