67 lines
2.6 KiB
Python
67 lines
2.6 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()
|
|
beta = 0.6
|
|
for line in lines:
|
|
item = line.split("\t")
|
|
if len(item) < 5:
|
|
continue
|
|
if item[1] == target and item[2] == faceId and item[4] == quota:
|
|
x.append(float(item[0]))
|
|
if len(y) == 0:
|
|
# 第一次添加
|
|
y.append(float(item[6]) * 8)
|
|
else:
|
|
# 指数加权平均
|
|
y.append(beta * y[len(y) - 1] + (1 - beta) * float(item[6]) * 8)
|
|
return x, y
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) != 3:
|
|
print("Usage: python main.py <filename> <title>")
|
|
exit(0)
|
|
filename = sys.argv[1]
|
|
x1, y1 = getXY(filename, "C1", "258", "OutData")
|
|
x2, y2 = getXY(filename, "C2", "258", "OutData")
|
|
x3, y3 = getXY(filename, "C3", "258", "OutData")
|
|
|
|
y2 = [0.0 for _ in range(len(y1) - len(y2))] + y2
|
|
y3 = [0.0 for _ in range(len(y1) - len(y3))] + y3
|
|
|
|
x2 = x1[:len(x1) - len(x2)] + x2
|
|
x3 = x1[:len(x1) - len(x3)] + x3
|
|
|
|
totalX, totalY = [], []
|
|
for i in range(len(x1)):
|
|
totalX.append(x1[i])
|
|
totalY.append(y1[i] + y2[i] + y3[i])
|
|
|
|
# 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='C1', linestyle='-.', marker='+')
|
|
l2 = plt.plot(x2, y2, 'g', label='C2', linestyle='-.', marker='x')
|
|
l3 = plt.plot(x3, y3, 'b', label='C3', linestyle='-.', marker='d')
|
|
l5 = plt.plot(totalX, totalY, 'peru', label='total', linestyle='-.', marker='2')
|
|
plt.xlim(0)
|
|
plt.ylim(0, 10000)
|
|
# plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-')
|
|
plt.title(sys.argv[2])
|
|
plt.xlabel('Time(s)')
|
|
plt.ylabel('Rate(kbps)')
|
|
plt.legend(loc=1)
|
|
plt.savefig(f"{filename}.svg", format='svg')
|