Files
zoeyyyzou ae654e1dc8 update
2021-09-23 16:10:08 +08:00

74 lines
2.7 KiB
Python

import csv
import os
import sys
import numpy as np
import matplotlib.pyplot as plt
# 之前绘制delay曲线的代码:用于绘制实验2和实验3的曲线
# @author=qjm253
# 折线图
def getXY(fileName: str, target: str, faceId: str, quota: str):
x = []
y = []
fileName = os.getcwd() + '/data/' + fileName
with open(fileName, "r") as file:
lines = file.readlines()
beta = 0.2
for line in lines[:455067]:
item = line.split("\t")
if len(item) < 5:
continue
if item[1] == target and item[2] == faceId and item[4] == quota:
lastTime = float(item[0])
x.append(float(item[0]))
if len(y) == 0:
# 第一次添加
y.append(float(item[5]) * 1000)
else:
# 指数加权平均
y.append(beta * y[len(y) - 1] + (1 - beta) * float(item[5]) * 1000)
return x, y
if __name__ == '__main__':
if len(sys.argv) != 3:
print("Usage: python delay.py <filename> <title>")
exit(0)
filename, filename1 = sys.argv[1], sys.argv[2]
delayType = "LastDelay"
x1, y1 = getXY(filename, "C1", "0", delayType)
x2, y2 = getXY(filename, "C2", "0", delayType)
x3, y3 = getXY(filename, "C3", "0", delayType)
print(f"C1: mean->{np.mean(y1).round(2)}, std->{np.std(y1).round(2)}")
print(f"C2: mean->{np.mean(y2).round(2)}, std->{np.std(y2).round(2)}")
print(f"C3: mean->{np.mean(y3).round(2)}, std->{np.std(y3).round(2)}")
# plt.boxplot([y1, y2, y3], labels=('C1', 'C2', 'C3'), showfliers=False) # 箱线图 by qjm
# plt.title(sys.argv[2])
# # plt.ylim(40, 61.50) # 实验2
# plt.ylim(60, 61.50) # 实验
# plt.ylabel('Delay(ms)')
#l1 = plt.plot(x1, y1, 'r', label='C1', linestyle='-.', marker='+', alpha=0.7)
#l2 = plt.plot(x2, y2, 'g', label='C2', linestyle='-.', marker='x', alpha=0.7)
#l3 = plt.plot(x3, y3, 'b', label='C3', linestyle='-.', marker='d', alpha=0.7)
l1 = plt.scatter(x1, y1, c='r', label='C1', marker='+', alpha=0.5)
l2 = plt.scatter(x2, y2, c='g', label='C2', marker='x', alpha=0.3)
l3 = plt.scatter(x3, y3, c='b', label='C3', marker='d', alpha=0.1)
plt.title(sys.argv[2])
plt.xlabel('Time(s)')
plt.ylabel('Delay(ms)')
plt.xlim(0)
# plt.ylim(0)
plt.ylim(40,75)
plt.legend(loc=0)
# plt.savefig(f"{filename}.svg", format="svg")
# save pictures
full_path = os.getcwd() + "/pictures_delay/" + filename + ".png" # 将图片保存到当前目录,记得斜杠;可更改文件格式(.tif),不写的话默认“.png ”
plt.savefig(full_path, dpi=960) # 存储路径+设置图片分辨率dpi=960