-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
executable file
·53 lines (47 loc) · 1.51 KB
/
plot.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
#!/usr/bin/env python
import matplotlib as mpl
import matplotlib.pyplot as plt
def mkdir_p(mypath):
'''Creates a directory. equivalent to using mkdir -p on the command line'''
from errno import EEXIST
from os import makedirs,path
try:
makedirs(mypath)
except OSError as exc: # Python >2.5
if exc.errno == EEXIST and path.isdir(mypath):
pass
else: raise
def plot_graphs(history,tit,label,episode):
plt.plot(range(len(history)),history,marker="",linestyle="-")
plt.title(tit)
plt.xlabel('Steps')
plt.ylabel(label)
output_dir = f"./Plots/Episode-{episode}"
mkdir_p(output_dir)
file_name=f'{tit}.png'
plt.savefig(f"{output_dir}/{file_name}")
plt.show()
cwnd=[]
tp=[]
rtt=[]
searchfile=open("run.log","r")
for line in searchfile:
if "\t[$] Congestion Window: " in line:
for z in line.split():
if z.isdigit():
cwnd.append(int(z))
if "\t[!] RTT :" in line:
for z in line.split():
if z.isdigit():
rtt.append(int(z)*1e-6)
if "\t[!] Throughput: " in line:
for z in line.split():
if z.isdigit():
tp.append(int(z)*8)
mpl.rcdefaults()
mpl.rcParams.update({'font.size': 16})
plot_graphs(cwnd,'Congestion Windows','CWND (segments)',1)
plot_graphs(tp,'Throughput over time','Throughput (Mbits/s)',1)
plot_graphs(rtt,'RTT over time','RTT (seconds)',1)
# plot_graphs(rew_history,'Reward sum plot','Accumulated reward',e)
searchfile.close()