-
Notifications
You must be signed in to change notification settings - Fork 35
/
post_processing.py
93 lines (73 loc) · 5.23 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
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'
])
# 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]]
# 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 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['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')
# Drop the initial state for plotting
if drop_timestep_zero:
df = df.drop(df.query('timestep == 0').index)
return df