-
Notifications
You must be signed in to change notification settings - Fork 8
/
average.py
executable file
·82 lines (71 loc) · 2.89 KB
/
average.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
# -*- coding: utf-8 -*-
"""
This script averages diferent instances of the same test. By default, each test is run five times.
Run this script after script.py and preprocess.py
"""
import os
import collections
import numpy as np
means = ['10', '50']
variances = ['0']
losses = ['0.0', '5.0']
bandwidths = ['100', '40', '5']
methods = ['quic', 'tcp']
spikes = ['0', '1']
testnumber = ['1', '2', '3', '4', '5']
pathfile = os.path.normpath('./processed/')
for method in methods:
for bandwidth in bandwidths:
for loss in losses:
for mean in means:
for variance in variances:
for spike in spikes:
avg_overhead, avg_delay, avg_bandwidth = 0, 0, 0
dic = collections.OrderedDict()
err = False
listbw, listoh, listde = [], [], []
for number in testnumber:
fichero = os.path.normpath(pathfile+'/DATA'+method+'_'+bandwidth+'_'+loss+'_'+mean+'_'+variance+'_'+spike+'_'+ number+'.txt')
try:
with open(fichero, 'r') as f:
line = f.readline()
parts = line.split()
avg_overhead += float(parts[0])
listoh.append(float(parts[0]))
avg_delay += (float(parts[2]) - float(parts[1]))
listde.append(float(parts[2]) - float(parts[1]))
avg_bandwidth += float(parts[3])
listbw.append(float(parts[3]))
except:
err = True
print 'File '+method+'_'+bandwidth+'_'+loss+'_'+mean+'_'+variance+'_'+spike+'_'+number+'.txt not found'
fichero = os.path.normpath(pathfile+'/SUM'+method+'_'+bandwidth+'_'+loss+'_'+mean+'_'+variance+'_'+spike+'_'+number+'.txt')
try:
with open(fichero, 'r') as f:
for line in f:
parts = line.split()
if parts[0] in dic:
dic[float(parts[0])] += int(parts[1])
else:
dic[float(parts[0])] = int(parts[1])
except:
err = True
print 'File '+method+'_'+bandwidth+'_'+loss+'_'+mean+'_'+variance+'_'+spike+'_'+number+'.txt not found'
if not err:
avg_overhead /= len(testnumber)
avg_delay /= len(testnumber)
avg_bandwidth /= len(testnumber)
avg_bandwidth /= 1000000
listbw[:] = [x/1000000 for x in listbw]
fichero = os.path.normpath(pathfile+'/AVGDATA'+method+'_'+bandwidth+'_'+loss+'_'+mean+'_'+variance+'_'+spike+'.txt')
f = open(fichero, 'w')
f.write(str(avg_overhead)+' '+str(avg_delay)+' '+str(avg_bandwidth)+'\n')
print np.std(listbw)
f.write(str(np.std(listoh))+' '+str(np.std(listde))+' '+str(np.std(listbw))+'\n')
f.close()
fichero = os.path.normpath(pathfile+'/AVGSUM'+method+'_'+bandwidth+'_'+loss+'_'+mean+'_'+variance+'_'+spike+'.txt')
f = open(fichero, 'w')
for key in sorted(dic.keys()):
f.write(str(key)+' '+str(float(float(dic[key])/len(testnumber)))+'\n')
f.close()
print 'SUCCESS '+method+'_'+bandwidth+'_'+loss+'_'+mean+'_'+variance+'_'+spike+'.txt'