-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
113 lines (82 loc) · 3.2 KB
/
graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import sys
import pandas as pd
import matplotlib.pyplot as plt
class Category:
def __init__(self, stake, start):
self.stake = stake
self.start = start
self.end = 0
self.accumulated_rewards = 0
self.validators = []
self.rewards = []
def num_validator(self):
return self.end - self.start + 1
def expected_reward(self, number_of_days: float, online_stake: float):
return number_of_days * 8640 * self.stake / online_stake
def average_reward(self):
return self.accumulated_rewards / (self.num_validator())
def draw(filename, committee_size, offline, number_of_days):
df = pd.read_csv(filename)
stakes = df['Stake']
rewards = df['Reward']
online_stake = df['Stake'].sum()
# total_stake = online_stake + (online_stake * offline/100)
categories = []
category = Category(stakes[0], 0)
for num, stake in enumerate(stakes):
if category.stake != stake:
categories.append(category)
category = Category(stake, num)
category.validators.append(num+1)
category.rewards.append(rewards[num])
category.accumulated_rewards += rewards[num]
category.end = num
categories.append(category)
# print(categories)
colors = ['red', 'blue', 'green', 'orange', 'purple',
'cyan', 'magenta', 'yellow', 'brown', 'gray']
legend_text = []
for i, cat in enumerate(categories):
color = colors[i % len(colors)]
x = cat.validators
y = cat.rewards
plt.scatter(x, y, color=color, label='Validators')
legend_text.append(f'Rewards per {cat.stake} PAC Coin')
# Uncomment this to see the sortitions
#
# x = df['Validator']
# y = df['Sortition']
# plt.scatter(x, y, color="black", label='Validators', marker="+")
# legend_text.append(f'Number of evaluated Sortition')
for i, cat in enumerate(categories):
average = cat.average_reward()
plt.hlines(y=average, xmin=cat.start, xmax=cat.end +
1, color="grey", linestyles="--")
x = cat.start
y = average
plt.text(x, y, f'{y}', va='bottom', color="grey")
if i== 0:
legend_text.append(f'Average rewards')
expected = cat.expected_reward(number_of_days, online_stake)
plt.hlines(y=expected, xmin=cat.start, xmax=cat.end +
1, color="black", linestyles="-")
x = cat.start
y = expected
plt.text(x, y, f'{y}', va='top', color="black")
if i== 0:
legend_text.append(f'Expected rewards')
plt.legend(legend_text)
plt.figtext(0.15, 0.15, f'Committee size: {committee_size}\nNumber of days: {number_of_days}\nOffline: {offline}%')
plt.xlabel('Validator')
plt.ylabel('Rewards')
plt.tight_layout()
plt.show()
if __name__ == '__main__':
if len(sys.argv) < 5:
print("Please provide CSV filename, committee size, offline percentage and number of days")
else:
filename = sys.argv[1]
committee_size = float(sys.argv[2])
offline = float(sys.argv[3])
number_of_days = float(sys.argv[4])
draw(filename, committee_size, offline, number_of_days)