%load_ext autotime
%load_ext autoreload
%autoreload 2
time: 10.3 ms (started: 2021-12-05 00:23:10 +00:00)
# External depences
import pandas as pd
import numpy as np
import plotly.express as px
# Move path to parent folder
import sys
sys.path.insert(1, '../')
# Internal dependences
from filecoin_metrics.connection import get_connection, get_connection_string
from filecoin_metrics.metrics import *
time: 506 ms (started: 2021-12-05 00:23:10 +00:00)
conn_string = get_connection_string('../config/sentinel-conn-string.txt')
connection = get_connection(conn_string)
time: 137 ms (started: 2021-12-05 00:23:11 +00:00)
df = sector_activation_and_expiration_by_week(connection)
time: 11min 29s (started: 2021-12-05 00:23:11 +00:00)
fig_df = (df.reset_index()
.assign(sqrt_sector_count=lambda df: df.sector_count ** (1 / 3))
.assign(log_sector_count=lambda df: np.log(df.sector_count))
.assign(sector_lifetime_days=lambda df: (df.expiration_week - df.activation_week).dt.days)
)
time: 17.8 ms (started: 2021-12-05 00:34:41 +00:00)
fig = px.scatter(fig_df,
x='activation_week',
y='expiration_week',
size='sqrt_sector_count',
color='sector_count',
title='Sector ount / Expiration Week grouped by Activation Week')
fig.show()
time: 513 ms (started: 2021-12-05 00:34:41 +00:00)
s = fig_df.groupby('activation_week').apply(lambda df: df.sector_count / df.sector_count.sum())
s.name = 'count_share'
z_df = fig_df.assign(count_share=s.values)
fig = px.scatter(z_df,
x='activation_week',
y='sector_lifetime_days',
size='count_share',
color='count_share',
title='Activated Sectors Lifetime across Time (weekly)')
fig.show()
time: 146 ms (started: 2021-12-05 00:34:41 +00:00)
s = fig_df.groupby('activation_week').apply(lambda df: df.sector_count / df.sector_count.sum())
s.name = 'count_share'
z_df = fig_df.assign(count_share=s.values)
fig = px.scatter(z_df,
x='activation_week',
y='expiration_week',
size='count_share',
color='count_share',
title='Share of Expiring Sectors grouped per Activation Week')
fig.show()
time: 174 ms (started: 2021-12-05 00:34:41 +00:00)
categories = pd.cut(fig_df.sector_lifetime_days, bins=3, labels=False)
z_df = fig_df.assign(lifetime_cat=categories)
z_df = z_df.groupby(['lifetime_cat', 'activation_week']).sector_count.sum().reset_index()
px.scatter(z_df,
x='activation_week',
y='lifetime_cat',
size='sector_count',
color='sector_count',
title='Count of Sectors Lifetime Category grouped by Activation Week')
time: 90.6 ms (started: 2021-12-05 00:34:42 +00:00)
fig_df.head()
activation_week | expiration_week | sector_count | sqrt_sector_count | log_sector_count | sector_lifetime_days | |
---|---|---|---|---|---|---|
0 | 2020-08-24 00:00:00+00:00 | 2022-02-14 00:00:00+00:00 | 162741 | 54.596608 | 11.999915 | 539 |
1 | 2020-08-24 00:00:00+00:00 | 2022-02-21 00:00:00+00:00 | 19783 | 27.045648 | 9.892578 | 546 |
2 | 2020-08-31 00:00:00+00:00 | 2022-02-14 00:00:00+00:00 | 14905 | 24.609946 | 9.609452 | 532 |
3 | 2020-08-31 00:00:00+00:00 | 2022-02-21 00:00:00+00:00 | 198284 | 58.312620 | 12.197456 | 539 |
4 | 2020-08-31 00:00:00+00:00 | 2022-02-28 00:00:00+00:00 | 21053 | 27.612432 | 9.954798 | 546 |
time: 32.3 ms (started: 2021-12-05 00:34:42 +00:00)
# categories = pd.cut(fig_df.sector_lifetime_days, bins=3, labels=False)
# z_df = fig_df.assign(lifetime_cat=categories)
# z_df = z_df.groupby(['lifetime_cat', 'activation_week']).sector_count.sum().reset_index()
# z_df = z_df.set_index('lifetime_cat').groupby(['activation_week']).apply(lambda x: x.sector_count / x.sector_count.sum()).unstack().reset_index().rename(columns={0: 'sector_count_share'})
# fig = px.scatter(z_df,
# x='activation_week',
# y='lifetime_cat',
# size='sector_count_share',
# color='sector_count_share',
# title='Share of Sectors Lifetime Category grouped by Activation Week')
# fig.show()
time: 20.2 ms (started: 2021-12-05 00:34:42 +00:00)
z_df = fig_df.groupby('expiration_week').sector_count.sum()
z_df = z_df.resample('1m').sum().reset_index()
px.bar(z_df,
x='expiration_week',
y='sector_count',
title='Expiring Sectors per Month',
log_y=True,
labels={'value': 'Sectors',
'time': 'Timestamp'})
time: 92.1 ms (started: 2021-12-05 00:34:42 +00:00)
z_df = fig_df.groupby('activation_week').sector_count.sum()
z_df = z_df.resample('1m').sum().reset_index()
px.bar(z_df,
x='activation_week',
y='sector_count',
title='Activated Sectors per Month',
log_y=True,
labels={'value': 'Sectors',
'time': 'Timestamp'})
time: 85.4 ms (started: 2021-12-05 00:34:42 +00:00)