-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelayRecord.py
59 lines (55 loc) · 1.82 KB
/
DelayRecord.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
import os
import matplotlib.pyplot as plt
import copy
import numpy as np
import math
from matplotlib.ticker import FuncFormatter
path0 = "./data/delay/newWithMove"
path1 = "./data/delay/oriWithMove"
def drawItem(data, name):
plt.title(name)
plt.ylim(bottom=25e-6, top=4e-5)
plt.xticks(np.arange(0, 1201, 50))
plt.yticks(np.arange(28e-6, 4e-5, 1e-6, dtype=float))
plt.xlabel("Simulation time")
plt.ylabel("Forwarded Packets Count")
for item in data:
print(item[2])
plt.plot(item[0], item[1], label=item[2])
plt.legend()
plt.savefig(fname=name+".png")
plt.show()
def readTC(filePath):
data = []
for iPath in filePath:
files = os.listdir(iPath)
files = list(filter(lambda x:x[-4:] == '.txt', files))
times = []
delayAverage = []
count = []
for i in range(240):
times.append(i)
delayAverage.append(0)
count.append(0);
# print(files)
for item in files:
with open(iPath + '/' + item, 'r') as f:
while True:
line = f.readline()
if not line:
break
linePair = line.split()
number = math.floor(round(float(linePair[0]))/5)
# print(number)
delayAverage[number] += float(linePair[1])
count[number] += 1;
times = np.array(times)
times *= 5
for i, item in enumerate(delayAverage):
delayAverage[i] = delayAverage[i] / count[i]
# print(delayAverage)
data.append((times, delayAverage, iPath[13:16]))
# print(times)
drawItem(data, "delay with Move")
if __name__ == "__main__":
readTC((path0, path1))