91 lines
3.8 KiB
Python
91 lines
3.8 KiB
Python
import csv
|
|
import os
|
|
import sys
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
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
|
|
count = 0
|
|
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:
|
|
if count % 1 == 0: # 这边修改采样间隔
|
|
x.append(float(item[0]))
|
|
if len(y) == 0:
|
|
# 第一次添加
|
|
y.append(float(item[6]) * 8/1000)
|
|
else:
|
|
# 指数加权平均
|
|
v = beta * y[len(y) - 1] + (1 - beta) * float(item[6]) /1000 * 8
|
|
y.append(v)
|
|
count += 1
|
|
return x, y
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) != 3:
|
|
print("Usage: python throughput_2.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])
|
|
|
|
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"Total: mean->{np.mean(totalY).round(2)}, std->{np.std(totalY).round(2)}")
|
|
|
|
plt.rc('font', family='Times New Roman')
|
|
plt.rcParams['xtick.direction'] = 'in'
|
|
plt.rcParams['ytick.direction'] = 'in'
|
|
|
|
# 画实验2专用下面四行:
|
|
l1 = plt.plot(x1, y1, 'tab:red', linewidth =1.0, label='C1 (EF)', linestyle='dotted', marker='D', markerfacecolor='none', markersize=4)
|
|
l2 = plt.plot(x2, y2, 'tab:purple', linewidth =1.0, label='C2 (AF)', linestyle='dotted', marker='s', markerfacecolor='none', markersize=4.5)
|
|
l3 = plt.plot(x3, y3, 'tab:blue', linewidth =1.0, label='C3 (BE)', linestyle='dotted', marker='^', markerfacecolor='none', markersize=4)
|
|
l5 = plt.plot(totalX, totalY, 'k', linewidth =1.0, label='Total', linestyle='dotted', marker='o', markerfacecolor='none', markersize=4)
|
|
|
|
# # 画实验3专用下面四行:
|
|
# l1 = plt.plot(x1, y1, 'tab:red', linewidth=1.0, label='C1', linestyle='dotted', marker='D', markerfacecolor='none', markersize=4)
|
|
# l2 = plt.plot(x2, y2, 'tab:purple', linewidth=1.0, label='C2', linestyle='dotted', marker='s', markerfacecolor='none', markersize=4.5)
|
|
# l3 = plt.plot(x3, y3, 'tab:blue', linewidth=1.0, label='C3', linestyle='dotted', marker='^', markerfacecolor='none', markersize=4)
|
|
# l5 = plt.plot(totalX, totalY, 'k', linewidth=1.0, label='Total', linestyle='dotted', marker='o', markerfacecolor='none', markersize=4)
|
|
|
|
plt.xlim(0)
|
|
my_x_ticks = np.arange(0, 61, 10)
|
|
plt.xticks(my_x_ticks)
|
|
plt.ylim(0)
|
|
my_y_ticks = np.arange(0, 101, 10)
|
|
plt.yticks(my_y_ticks)
|
|
|
|
plt.title(sys.argv[2])
|
|
plt.xlabel('Time (s)')
|
|
plt.ylabel('Rate (Mbps)')
|
|
plt.legend(loc=1, bbox_to_anchor=(1, 0.91))
|
|
#plt.savefig(f"{filename}.svg", format='svg')
|
|
|
|
# save pictures
|
|
full_path = os.getcwd() + "/pictures_throughput/" + filename + ".pdf" # 将图片保存到当前目录,记得斜杠;可更改文件格式(.tif),不写的话默认“.png ”
|
|
plt.savefig(full_path, dpi=960) # 存储路径+设置图片分辨率dpi=960
|