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

79 lines
2.4 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
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
def getJain(filename: str):
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
jainX1, jainY1 = [], []
for i in range(len(x1)):
flowNum = 3
#flowNum += (1 if y1[i] > 0 else 0)
#flowNum += (1 if y2[i] > 0 else 0)
#flowNum += (1 if y3[i] > 0 else 0)
#flowNum += (1 if y4[i] > 0 else 0)
# cal jain
jain = pow((y1[i] + y2[i] + y3[i]), 2) / (
flowNum * (pow(y1[i], 2) + pow(y2[i], 2) + pow(y3[i], 2)))
jainX1.append(x1[i])
jainY1.append(jain)
return jainX1, jainY1
if __name__ == '__main__':
if len(sys.argv) != 3:
print("Usage: python main.py <filename1> <filename2>")
exit(0)
jainX1, jainY1 = getJain(sys.argv[1])
jainX2, jainY2 = getJain(sys.argv[2])
l1 = plt.plot(jainX1, jainY1, 'g', label="DSCCP", linestyle='-.', marker='2')
l2 = plt.plot(jainX2, jainY2, 'peru', label="PCON", linestyle='-.', marker='*')
plt.xlim(0)
plt.ylim(0)
# plt.plot(x1, y1, 'ro-', x2, y2, 'g+-', x3, y3, 'b^-')
plt.title("")
plt.xlabel('Time(s)')
plt.ylabel("Jain's Fairness Index")
plt.legend(loc=4)
#plt.savefig(f"jain-{sys.argv[1]}-{sys.argv[2]}.svg", format='svg')
# save pictures
full_path = os.getcwd() + "/pictures_jain/" + "jain-" + sys.argv[1] + '-' + sys.argv[
2] + ".png"
plt.savefig(full_path, dpi=960)