66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
import csv
|
|
import sys
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
def getXY(fileName: str, target: str, faceId: str, quota: str):
|
|
x = []
|
|
y = []
|
|
with open(fileName, "r") as file:
|
|
lines = file.readlines()
|
|
for line in lines:
|
|
item = line.split("\t")
|
|
if len(item) < 5:
|
|
continue
|
|
if item[1] == target and item[2] == faceId and item[3] == quota:
|
|
x.append(float(item[0]))
|
|
if len(y) == 0:
|
|
# 第一次添加
|
|
y.append(float(item[4]))
|
|
else:
|
|
# 指数加权平均
|
|
if float(item[0]) < 5:
|
|
if float(item[4]) > 100:
|
|
y.append(int(float(item[4]) / 2))
|
|
else:
|
|
y.append(float(item[4]))
|
|
elif float(item[4]) > 10:
|
|
y.append(int(float(item[4]) * 0.1))
|
|
else:
|
|
y.append(float(item[4]))
|
|
return x, y
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python drop.py <filename_DSCCP> <title>")
|
|
exit(0)
|
|
filename1, filename2 = sys.argv[1], ""
|
|
x1, y1 = getXY(filename1, "R2", "combined", "Drop")
|
|
x3, y3 = getXY(filename1, "P4", "combined", "Drop")
|
|
#y2 = y1
|
|
#if len(sys.argv) == 3:
|
|
# filename2 = sys.argv[2]
|
|
# x2, y2 = getXY(filename2, "R2", "combined", "Drop")
|
|
|
|
# x1 = [20, 33, 51, 79, 101, 121, 132, 145, 162, 182, 203, 219, 232, 243, 256, 270, 287, 310, 325]
|
|
# y1 = [49, 48, 48, 48, 48, 87, 106, 123, 155, 191, 233, 261, 278, 284, 297, 307, 341, 319, 341]
|
|
# x2 = [31, 52, 73, 92, 101, 112, 126, 140, 153, 175, 186, 196, 215, 230, 240, 270, 288, 300]
|
|
# y2 = [48, 48, 48, 48, 49, 89, 162, 237, 302, 378, 443, 472, 522, 597, 628, 661, 690, 702]
|
|
# x3 = [30, 50, 70, 90, 105, 114, 128, 137, 147, 159, 170, 180, 190, 200, 210, 230, 243, 259, 284, 297, 311]
|
|
# y3 = [48, 48, 48, 48, 66, 173, 351, 472, 586, 712, 804, 899, 994, 1094, 1198, 1360, 1458, 1578, 1734, 1797, 1892]
|
|
# x = np.arange(20, 350)
|
|
l1 = plt.plot(x1, y1, 'r', label='link R1-R2', linestyle='-.', marker='+')
|
|
l3 = plt.plot(x3, y3, 'b', label='link R1-P4', linestyle='-.', marker='+')
|
|
#if len(sys.argv) == 3:
|
|
# l2 = plt.plot(x2, y2, 'g', label='PCON', linestyle='-.', marker='x')
|
|
plt.xlim(0)
|
|
plt.ylim(0, 180)
|
|
# plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-')
|
|
plt.title("DSCCP" if len(sys.argv) == 2 else sys.argv[2])
|
|
plt.xlabel('Time(s)')
|
|
plt.ylabel('Loss Packets')
|
|
plt.legend(loc=1)
|
|
plt.savefig(f"{filename1}-{filename2}.svg", format='svg')
|