134 lines
4.5 KiB
Python
134 lines
4.5 KiB
Python
import csv
|
|
import os
|
|
import sys
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
# 之前绘制delay曲线的代码:用于绘制实验0和实验1(包括五个实验场景)的曲线
|
|
# @author=qjm253
|
|
# 折线图
|
|
|
|
def getXY(fileName: str, target: str, faceId: str, quota: str):
|
|
x = []
|
|
y = []
|
|
with open(fileName, "r") as file:
|
|
lines = file.readlines()
|
|
lastCount = 0
|
|
beta = 0
|
|
for line in lines[1:]:
|
|
item = line.split("\t")
|
|
if len(item) < 5:
|
|
continue
|
|
if item[1] == target and item[2] == faceId and item[4] == quota:
|
|
capTime = float(item[0])
|
|
if int(capTime / 0.1) != lastCount:
|
|
lastCount = int(capTime / 0.1)
|
|
else:
|
|
continue
|
|
x.append(lastCount * 0.1)
|
|
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
|
|
|
|
|
|
def doDraw(filename: str, title: str, experiment0: bool):
|
|
print("\n")
|
|
print(f"{filename}->{title}")
|
|
|
|
delayType = "LastDelay"
|
|
x1, y1 = getXY(filename, "C1", "0", delayType)
|
|
x2, y2 = getXY(filename, "C2", "0", delayType)
|
|
x3, y3 = getXY(filename, "C3", "0", delayType)
|
|
x4, y4 = getXY(filename, "C4", "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)}")
|
|
print(f"C4: mean->{np.mean(y4).round(2)}, std->{np.std(y4).round(2)}")
|
|
|
|
res = [
|
|
np.mean(y1).round(2), np.std(y1).round(2),
|
|
np.mean(y2).round(2), np.std(y2).round(2),
|
|
np.mean(y3).round(2), np.std(y3).round(2),
|
|
np.mean(y4).round(2), np.std(y4).round(2),
|
|
]
|
|
res_str = ""
|
|
for num in res:
|
|
res_str += f"& {num} "
|
|
print(res)
|
|
|
|
# # 箱线图代码
|
|
# plt.boxplot([y1, y2, y3, y4], labels=('C1', 'C2', 'C3', 'C4'), showfliers=False) # 箱线图 by qjm
|
|
# plt.title(sys.argv[2])
|
|
# plt.ylim(62,66)
|
|
# 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)
|
|
l4 = plt.plot(x4, y4, 'aqua', label='C4', linestyle='-.', marker='*', alpha=0.7)
|
|
|
|
plt.title(title)
|
|
plt.xlabel('Time(s)')
|
|
plt.ylabel('Delay(ms)')
|
|
plt.xlim(0)
|
|
# plt.ylim(60) # 1.1
|
|
# plt.ylim(50,120) # 1.2
|
|
# plt.ylim(60,74) # 1.3
|
|
# plt.ylim(60, 100) # 1.4
|
|
if experiment0:
|
|
plt.ylim(60, 80) # 1.5
|
|
else:
|
|
plt.ylim(60)
|
|
plt.legend(loc=0)
|
|
|
|
# save pictures
|
|
full_path = os.getcwd() + "/pictures_delay/" + filename[filename.rfind(
|
|
'/') + 1:] + ".png" # 将图片保存到当前目录,记得斜杠;可更改文件格式(.tif),不写的话默认“.png ”
|
|
plt.savefig(full_path, dpi=960) # 存储路径+设置图片分辨率dpi=960
|
|
plt.close()
|
|
return res
|
|
|
|
|
|
if __name__ == '__main__':
|
|
doDraw("data/delay_experiment0.txt", "DSCCP", True)
|
|
|
|
res = [
|
|
doDraw("data/delay_experiment1.2.txt", "DSCCP", False),
|
|
doDraw("data/delay_experiment1.3.txt", "DSCCP", False),
|
|
doDraw("data/delay_experiment1.4.txt", "DSCCP", False),
|
|
doDraw("data/delay_experiment1.5.txt", "DSCCP", False),
|
|
]
|
|
|
|
a = np.array(
|
|
[res[0][::2], res[0][1::2], res[1][::2], res[1][1::2], res[2][::2], res[2][1::2], res[3][::2], res[3][1::2]]).T
|
|
[rows, cols] = a.shape
|
|
print(a.shape)
|
|
for i in range(rows):
|
|
res_str = ""
|
|
for j in range(cols):
|
|
res_str += f"& {a[i, j]} "
|
|
print(res_str)
|
|
|
|
print("\n\n")
|
|
res = [
|
|
doDraw("data_pcon/pcon_delay_experiment1.2.txt", "PCON", False),
|
|
doDraw("data_pcon/pcon_delay_experiment1.3.txt", "PCON", False),
|
|
doDraw("data_pcon/pcon_delay_experiment1.4.txt", "PCON", False),
|
|
doDraw("data_pcon/pcon_delay_experiment1.5.txt", "PCON", False)
|
|
]
|
|
a = np.array(
|
|
[res[0][::2], res[0][1::2], res[1][::2], res[1][1::2], res[2][::2], res[2][1::2], res[3][::2], res[3][1::2]]).T
|
|
[rows, cols] = a.shape
|
|
print(a.shape)
|
|
for i in range(rows):
|
|
res_str = ""
|
|
for j in range(cols):
|
|
res_str += f"& {a[i, j]} "
|
|
print(res_str)
|