-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualization.py
More file actions
192 lines (152 loc) · 7.19 KB
/
Visualization.py
File metadata and controls
192 lines (152 loc) · 7.19 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import numpy as np
import matplotlib.pyplot as plt
import sys
def revenue_cost_time(nb_simulations: int, strat: str, revenue: list, cost: list, alpha: float, gamma: float, window_size: int = 2016) -> None:
# Derive the list of epochs
block_periods = [window_size for x in range(0, nb_simulations // window_size)] \
+ [nb_simulations % window_size]
# Make the list of epoch to be strings
for i in range(len(block_periods)):
if block_periods[i] == 2016:
block_periods[i] = "epoch" + str(i+1) + ": complete"
else:
block_periods[i] = "epoch" + str(i+1) + ": incomplete"
plt.figure(figsize=[6.4, 15.8])
if len(block_periods) != len(revenue):
sys.exit(
"ERROR: The number of simulations(nb_simulations) does not match with the revenue")
# Revenue v.s. Epoch
plt.bar(block_periods, revenue, color="red", width=0.4,
label="alpha: " + str(alpha) + " gamma: " + str(gamma))
for i in range(len(block_periods)):
plt.text(i, revenue[i], revenue[i], ha="center", va="bottom")
plt.xlabel(f"Epochs ({window_size} blocks / epoch)")
plt.xticks(rotation=15)
plt.ylabel("Revenue")
plt.title(f"Revenue of {strat} v.s. Time")
plt.legend()
plt.show()
if len(block_periods) != len(cost):
sys.exit(
"ERROR: The number of simulations(nb_simulations) does not match with the cost")
# Cost v.s. Epoch
plt.bar(block_periods, cost, color="green", width=0.4,
label="alpha: " + str(alpha) + " gamma: " + str(gamma))
for i in range(len(block_periods)):
plt.text(i, cost[i], cost[i], ha="center", va="bottom")
plt.xlabel(f"Epochs ({window_size} blocks / epoch)")
plt.xticks(rotation=15)
plt.ylabel("Cost")
plt.title(f"Cost of {strat} v.s. Time")
plt.legend()
plt.show()
gross = [revenue[i] - cost[i] for i in range(len(revenue))]
# Gross v.s. Epoch
gross_pos = [gross[i] if gross[i] > 0 else 0 for i in range(len(gross))]
gross_neg = [gross[i] if gross[i] < 0 else 0 for i in range(len(gross))]
if len(block_periods) != len(gross):
sys.exit(
"ERROR: The number of simulations(nb_simulations) does not match with the revenue or cost")
plt.bar(block_periods, gross_pos, color='red', width=0.4,
label="Positive Profit with " + "alpha: " + str(alpha) + " gamma: " + str(gamma))
plt.bar(block_periods, gross_neg, color='green', width=0.4,
label="Negative Profit with "+"alpha: " + str(alpha) + " gamma: " + str(gamma))
for i in range(len(block_periods)):
plt.text(i, gross[i], gross[i], ha="center", va="bottom")
plt.xlabel(f"Epochs ({window_size} blocks / epoch)")
plt.axhline(y=0, color='black', linestyle='-')
plt.xticks(rotation=15)
plt.ylabel("Gross Profit")
plt.title(f"Gross Profit of {strat} v.s. Time")
plt.legend()
plt.show()
def difficulty_time(nb_simulations: int, strat: str, difficulty_list: list, alpha: float, gamma: float, window_size: int = 2016) -> None:
# Derive the list of epochs
block_periods = [window_size for x in range(0, nb_simulations // window_size)] \
+ [nb_simulations % window_size]
# Make the list of epoch to be strings
for i in range(len(block_periods)):
if block_periods[i] == 2016:
block_periods[i] = "epoch" + str(i) + ": complete"
else:
block_periods[i] = "epoch" + str(i) + ": incomplete"
# print(block_periods)
# print(difficulty_list)
if len(block_periods) != len(difficulty_list):
sys.exit(
"ERROR: The number of simulations(nb_simulations) does not match with the difficulty_list")
# Difficulty v.s. Epochs
plt.figure(figsize=[6.4, 15.8])
plt.plot(block_periods, difficulty_list, color='maroon', label="Difficulty Level with alpha: " +
str(alpha) + " gamma: " + str(gamma))
for i in range(len(block_periods)):
plt.text(i, difficulty_list[i],
difficulty_list[i], ha="right", va="center")
plt.xlabel(f"Epochs ({window_size} blocks / epoch)")
plt.xticks(rotation=15)
plt.axhline(y=1, color='red', linestyle='-')
plt.ylabel("Mining Difficulty Level")
plt.title(f"Difficulty Level of {strat} v.s. Time")
plt.legend()
plt.show()
def alpha_revenue(strat: str, revenue_mean_list: list, cost_mean_list: list, alpha_list: list, gamma: float) -> None:
if len(revenue_mean_list) != len(cost_mean_list):
sys.exit(
"ERROR: The length revenue_mean_list doesn't match with the length of cost_mean_list")
if len(revenue_mean_list) != len(alpha_list):
sys.exit(
"ERROR: The length revenue_mean_list doesn't match with the length of alpha_list")
if len(cost_mean_list) != len(alpha_list):
sys.exit(
"ERROR: The length cost_mean_list doesn't match with the length of alpha_list")
plt.figure(figsize=[6.4, 15.8])
# Revenue v.s. Alpha
plt.plot(alpha_list, revenue_mean_list, color="red",
label="Revenue with "" gamma: " + str(gamma))
for i in range(len(alpha_list)):
plt.text(alpha_list[i], revenue_mean_list[i],
revenue_mean_list[i], ha="right", va="center")
plt.xlabel("Alpha level (Percentage)")
plt.xticks(np.arange(min(alpha_list), max(alpha_list)+0.1, 0.1))
plt.ylabel("Revenue (Blocks)")
plt.title(f"Revenue of {strat} v.s. Alpha Level")
plt.legend()
plt.show()
# Cost v.s. Alpha
plt.plot(alpha_list, cost_mean_list, color="green",
label="Cost with "" gamma: " + str(gamma))
for i in range(len(alpha_list)):
plt.text(alpha_list[i], cost_mean_list[i],
cost_mean_list[i], ha="right", va="center")
plt.xlabel("Alpha level (Percentage)")
plt.xticks(np.arange(min(alpha_list), max(alpha_list)+0.1, 0.1))
plt.ylabel("Cost (Blocks)")
plt.title(f"Cost of {strat} v.s. Alpha Level")
plt.legend()
plt.show()
# Gross Profit v.s. Alpha
gross_mean_list = [revenue_mean_list[i] - cost_mean_list[i]
for i in range(len(revenue_mean_list))]
plt.plot(alpha_list, gross_mean_list,
color="blue", label="Gross Profit with " + "gamma" + str(gamma))
for i in range(len(alpha_list)):
plt.text(alpha_list[i], gross_mean_list[i],
gross_mean_list[i], ha="right", va="center")
plt.xlabel("Alpha level (Percentage)")
plt.ylabel("Gross Profit (Blocks)")
plt.title(f"Gross Profit of {strat} v.s. Alpha Level")
plt.legend()
plt.show()
# Gross Profit/TH v.s Alpha
gross_mean_list = [round((revenue_mean_list[i] - cost_mean_list[i])/alpha_list[i], 2) if alpha_list[i] != 0 else 0
for i in range(len(revenue_mean_list))]
plt.plot(alpha_list, gross_mean_list,
color="blue", label="Gross Profit/TH with " + "gamma" + str(gamma))
for i in range(len(alpha_list)):
plt.text(alpha_list[i], gross_mean_list[i],
gross_mean_list[i], ha="right", va="center")
plt.xlabel("Alpha level (Percentage)")
plt.ylabel("Gross Profit/TH (Blocks/Total Hash)")
plt.title(f"Gross Profit/Total Hash Power of {strat} v.s. Alpha Level")
plt.legend()
plt.show()