-
Notifications
You must be signed in to change notification settings - Fork 35
/
post_processing.py
125 lines (93 loc) · 8.53 KB
/
post_processing.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
114
115
116
117
118
119
120
121
122
123
124
125
import pandas as pd
from radcad.core import generate_parameter_sweep
import model.constants as constants
from model.system_parameters import parameters, Parameters, validator_environments
def assign_parameters(df: pd.DataFrame, parameters: Parameters, set_params=[]):
if set_params:
parameter_sweep = generate_parameter_sweep(parameters)
parameter_sweep = [{param: subset[param] for param in set_params} for subset in parameter_sweep]
for subset_index in df['subset'].unique():
for (key, value) in parameter_sweep[subset_index].items():
df.loc[df.eval(f'subset == {subset_index}'), key] = value
return df
def post_process(df: pd.DataFrame, drop_timestep_zero=True, parameters=parameters):
# Assign parameters to DataFrame
assign_parameters(df, parameters, [
# Parameters to assign to DataFrame
'dt',
'avg_pool_size'
])
df[[validator.type + '_eth_staked' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_eth_staked), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_pool_eth_staked' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_pool_eth_staked), axis=1, result_type='expand').astype('float32')
# Dissagregate validator count
df[[validator.type + '_validator_count' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_count_distribution), axis=1, result_type='expand').astype('float32')
# Dissagregate validator costs
df[[validator.type + '_costs' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_costs), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_hardware_costs' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_hardware_costs), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_cloud_costs' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_cloud_costs), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_third_party_costs' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_third_party_costs), axis=1, result_type='expand').astype('float32')
# Dissagregate individual validator costs
_mapping = dict(zip(
[validator.type + '_costs' for validator in validator_environments],
[validator.type + '_validator_count' for validator in validator_environments]
))
df[['individual_validator_' + validator.type + '_costs' for validator in validator_environments]] = \
df[[validator.type + '_costs' for validator in validator_environments]].rename(columns=_mapping) / \
df[[validator.type + '_validator_count' for validator in validator_environments]]
df[[validator.type + '_shared_validators' for validator in validator_environments]] = df.apply(lambda row: list(row.number_of_shared_validators), axis=1, result_type='expand').astype('float32')
# Dissagregate revenue and profit
df[[validator.type + '_revenue' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_revenue), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_profit' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_profit), axis=1, result_type='expand').astype('float32')
# Dissagregate pool metrics
df[[validator.type + '_pool_profit' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_pool_profit), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_pool_profit_yields' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_pool_profit_yields), axis=1, result_type='expand').astype('float32')
# df[[validator.type + '_pool_cumulative_yields' for validator in validator_environments]] = df.apply(lambda row: list(row.pool_cumulative_yields), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_stakers_per_pool' for validator in validator_environments]] = df.apply(lambda row: list(row.stakers_per_pool), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_shared_validators_per_pool' for validator in validator_environments]] = df.apply(lambda row: list(row.shared_validators_per_pool), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_pool_size' for validator in validator_environments]] = df.apply(lambda row: list(row.pool_size), axis=1, result_type='expand').astype('float32')
# Dissagregate yields
df[[validator.type + '_revenue_yields' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_revenue_yields), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_profit_yields' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_profit_yields), axis=1, result_type='expand').astype('float32')
# Convert decimals to percentages
df[[validator.type + '_revenue_yields_pct' for validator in validator_environments]] = df[[validator.type + '_revenue_yields' for validator in validator_environments]] * 100
df[[validator.type + '_profit_yields_pct' for validator in validator_environments]] = df[[validator.type + '_profit_yields' for validator in validator_environments]] * 100
df[[validator.type + '_pool_profit_yields_pct' for validator in validator_environments]] = df[[validator.type + '_pool_profit_yields' for validator in validator_environments]] * 100
# df[[validator.type + '_pool_cumulative_yields_pct' for validator in validator_environments]] = df[[validator.type + '_pool_cumulative_yields' for validator in validator_environments]] * 100
df['supply_inflation_pct'] = df['supply_inflation'] * 100
df['total_revenue_yields_pct'] = df['total_revenue_yields'] * 100
df['total_profit_yields_pct'] = df['total_profit_yields'] * 100
# Calculate revenue-profit yield spread
df['revenue_profit_yield_spread_pct'] = df['total_revenue_yields_pct'] - df['total_profit_yields_pct']
# Convert validator rewards from Gwei to ETH
validator_rewards = [
'validating_rewards',
'validating_penalties',
'total_online_validator_rewards',
'total_priority_fee_to_validators',
'source_reward',
'target_reward',
'head_reward',
'block_proposer_reward',
'sync_reward',
'whistleblower_rewards'
]
df[[reward + '_eth' for reward in validator_rewards]] = df[validator_rewards] / constants.gwei
# Convert validator penalties from Gwei to ETH
validator_penalties = ['validating_penalties', 'amount_slashed']
df[[penalty + '_eth' for penalty in validator_penalties]] = df[validator_penalties] / constants.gwei
# Calculate cumulative revenue and profit yields
df["daily_revenue_yields_pct"] = df["total_revenue_yields_pct"] / (constants.epochs_per_year / df['dt'])
df["cumulative_revenue_yields_pct"] = df.groupby('subset')["daily_revenue_yields_pct"].transform('cumsum')
df["daily_profit_yields_pct"] = df["total_profit_yields_pct"] / (constants.epochs_per_year / df['dt'])
df["cumulative_profit_yields_pct"] = df.groupby('subset')["daily_profit_yields_pct"].transform('cumsum')
df['validator_daily_profit_yield_pct'] = df['validator_profit_yields'] / (constants.epochs_per_year / df['dt']) * 100
df[[validator.type + '_daily_profit_yields_pct' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_daily_profit_yield_pct), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_cumulative_profit_yields_pct' for validator in validator_environments]] = df.groupby('subset')[[validator.type + '_daily_profit_yields_pct' for validator in validator_environments]].transform('cumsum')
# AVG Cumulative yields per pool
df['validator_pool_daily_profit_yield_pct'] = df['validator_pool_profit_yields'] / (constants.epochs_per_year / df['dt']) * 100
df[[validator.type + '_pool_daily_profit_yields_pct' for validator in validator_environments]] = df.apply(lambda row: list(row.validator_pool_daily_profit_yield_pct), axis=1, result_type='expand').astype('float32')
df[[validator.type + '_pool_cumulative_profit_yields_pct' for validator in validator_environments]] = df.groupby('subset')[[validator.type + '_pool_daily_profit_yields_pct' for validator in validator_environments]].transform('cumsum')
# Drop the initial state for plotting
if drop_timestep_zero:
df = df.drop(df.query('timestep == 0').index)
return df