-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCrecord.py
53 lines (49 loc) · 1.57 KB
/
TCrecord.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
import os
import matplotlib.pyplot as plt
import copy
import numpy as np
import math
from matplotlib.ticker import FuncFormatter
path0 = "./data/TC/newWithMove"
path1 = "./data/TC/oriWithMove"
def drawItem(data, name):
plt.title(name)
plt.ylim(bottom=0, top=280)
plt.xticks(np.arange(0, 1201, 50))
plt.yticks(np.arange(0, 251, 25))
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 = []
forwardCount = []
for i in range(240):
times.append(i)
forwardCount.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)
forwardCount[number] += int(linePair[1])
times = np.array(times)
times *= 5
data.append((times, forwardCount, iPath[10:13]))
# print(times)
drawItem(data, "TCForward with Move")
if __name__ == "__main__":
readTC((path0, path1))