-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcleanData.py
85 lines (74 loc) · 2.53 KB
/
cleanData.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
# Average data points and get rid of error messages
# and plot
# Makes 2 plots in the graphs/ directory
# One plot uses the average throughput, and the other uses the min throughpu
import glob
import os
import plot_normalized_throughput
import re
import shutil
from helper import *
def clean_data(args):
path = 'output/*'
graphDir = "graphs"
outDir = "cleanOutput"
files = glob.glob(path)
for file in files:
dict = {}
f = open(file, 'r')
lines = f.readlines()
for line in lines:
splitLine = line.split()
key = splitLine[0]
val = splitLine[1]
if "error" in val:
continue
if dict.has_key(key):
dict[key].append(val)
else:
dict[key] = [val]
f.close()
queueSize = re.search('[0-9]+', file).group(0)
outfileName = outDir + "/" + args.cong + "_" + queueSize + ".txt"
minOutfileName = outDir + "/" + args.cong + "_min" + queueSize + ".txt"
# Right now, plots min and avg on 2 separate graphs
# To plot on the same graph, set minOutfileName to outfileName
# and then remove the rest of the code pertaining to minOutfile
outfile = open(outfileName, 'w')
minOutfile = open(minOutfileName, 'w')
baseline_avg = 1.0
baseline_min = 1.0
for key in dict:
# Average the values and output to the file
val = dict[key]
if key != '0.0':
outfile.write(key)
outfile.write(" ")
minOutfile.write(key)
minOutfile.write(" ")
val_floats = [float(x) for x in val]
minVal = min(val_floats)
avg = sum(val_floats)/len(val_floats)
if key != '0.0':
outfile.write(str(avg))
outfile.write("\n")
minOutfile.write(str(minVal))
minOutfile.write("\n")
else:
baseline_avg = avg
baseline_min = minVal
outfile.close()
minOutfile.close()
# Find the queue size
# TODO: remove code below (about queueing) later for final submission?
# That is, we would have decided on a queue size then
# so we wouldn't need to create separate plots by queue size
plot_normalized_throughput.plot(outfileName, baseline_avg, graphDir + "/" + args.cong + "_" + queueSize)
plot_normalized_throughput.plot(minOutfileName, baseline_min, graphDir + "/" + args.cong + "_min" + queueSize)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--cong',
help="TCP variant",
default="reno") # Will show the plot
args = parser.parse_args()
clean_data(args)