Spaces:
Sleeping
Sleeping
| import time | |
| import pandas as pd | |
| import streamlit as st | |
| import plotly.express as px | |
| import requests | |
| import utils | |
| _ = """ | |
| Proteins folded (delta 24hr) | |
| Current proteins folding (24hr) | |
| Average time to fold trend | |
| Refolded proteins (group by run id and pdb id and get unique) | |
| Simulation duration distribution | |
| """ | |
| UPDATE_INTERVAL = 3600 | |
| BASE_URL = 'API_URL' | |
| st.title('Folding Subnet Dashboard') | |
| st.markdown('<br>', unsafe_allow_html=True) | |
| #### ------ PRODUCTIVITY ------ | |
| # Overview of productivity | |
| st.subheader('Productivity overview') | |
| st.info('Productivity metrics show how many proteins have been folded, which is the primary goal of the subnet. Metrics are estimated using weights and biases data combined with heuristics.') | |
| productivity_all = requests.get(f'{BASE_URL}/productivity').json() | |
| productivity = productivity_all['all_time'] | |
| productivity_24h = productivity_all['last_24h'] | |
| m1, m2 = st.columns(2) | |
| m1.metric('Unique proteins folded', f'{productivity["unique_folded"]:,.0f}', delta=f'{productivity_24h["unique_folded"]:,.0f} (24h)') | |
| m2.metric('Total jobs completed', f'{productivity["total_completed_jobs"]:,.0f}', delta=f'{productivity_24h["total_completed_jobs"]:,.0f} (24h)') | |
| # m3.metric('Total simulation steps', f'{productivity.get("total_md_steps"):,.0f}', delta=f'{productivity_24h.get("total_md_steps"):,.0f} (24h)') | |
| # st.markdown('<br>', unsafe_allow_html=True) | |
| # time_binned_data = df.set_index('last_event_at').groupby(pd.Grouper(freq='12h')) | |
| # PROD_CHOICES = { | |
| # 'Unique proteins folded': 'unique_pdbs', | |
| # 'Total simulations': 'total_pdbs', | |
| # 'Total simulation steps': 'total_md_steps', | |
| # } | |
| # prod_choice_label = st.radio('Select productivity metric', list(PROD_CHOICES.keys()), index=0, horizontal=True) | |
| # prod_choice = PROD_CHOICES[prod_choice_label] | |
| # steps_running_total = time_binned_data[prod_choice].sum().cumsum() | |
| # st.plotly_chart( | |
| # # add fillgradient to make it easier to see the trend | |
| # px.area(steps_running_total, y=prod_choice, | |
| # labels={'last_event_at':'', prod_choice: prod_choice_label}, | |
| # ).update_traces(fill='tozeroy'), | |
| # use_container_width=True, | |
| # ) | |
| st.markdown('<br>', unsafe_allow_html=True) | |
| #### ------ THROUGHPUT ------ | |
| st.subheader('Throughput overview') | |
| st.info('Throughput metrics show the total amount of data sent and received by the validators. This is a measure of the network activity and the amount of data that is being processed by the subnet.') | |
| MEM_UNIT = 'GB' #st.radio('Select memory unit', ['TB','GB', 'MB'], index=0, horizontal=True) | |
| throughput = requests.get(f'{BASE_URL}/throughput').json() | |
| data_transferred = throughput['all_time'] | |
| data_transferred_24h = throughput['last_24h'] | |
| m1, m2, m3 = st.columns(3) | |
| m1.metric(f'Total validator data sent ({MEM_UNIT})', f'{data_transferred["validator_sent"]:,.0f}', delta=f'{data_transferred_24h["validator_sent"]:,.0f} (24h)') | |
| m2.metric(f'Total received data ({MEM_UNIT})', f'{data_transferred["miner_sent"]:,.0f}', delta=f'{data_transferred_24h["miner_sent"]:,.0f} (24h)') | |
| m3.metric(f'Total transferred data ({MEM_UNIT})', f'{data_transferred["validator_sent"]+data_transferred["miner_sent"]:,.0f}', delta=f'{data_transferred_24h["validator_sent"]+data_transferred_24h["miner_sent"]:,.0f} (24h)') | |
| # IO_CHOICES = {'total_data_sent':'Sent', 'total_data_received':'Received'} | |
| # io_running_total = time_binned_data[list(IO_CHOICES.keys())].sum().rename(columns=IO_CHOICES).cumsum().melt(ignore_index=False) | |
| # io_running_total['value'] = io_running_total['value'].apply(utils.convert_unit, args=(utils.BASE_UNITS, MEM_UNIT)) | |
| # st.plotly_chart( | |
| # px.area(io_running_total, y='value', color='variable', | |
| # labels={'last_event_at':'', 'value': f'Data transferred ({MEM_UNIT})', 'variable':'Direction'}, | |
| # ), | |
| # use_container_width=True, | |
| # ) | |
| st.markdown('<br>', unsafe_allow_html=True) | |
| #### ------ LEADERBOARD ------ | |
| st.subheader('Leaderboard') | |
| st.info('The leaderboard shows the top miners by incentive.') | |
| m1, m2 = st.columns(2) | |
| ntop = m1.slider('Number of top miners to display', value=10, min_value=3, max_value=50, step=1) | |
| entity_choice = m2.radio('Select entity', utils.ENTITY_CHOICES, index=0, horizontal=True) | |
| df_m = utils.get_metagraph(time.time()//UPDATE_INTERVAL) | |
| df_miners = utils.get_leaderboard(df_m, ntop=ntop, entity_choice=entity_choice) | |
| # hide colorbar and don't show y axis | |
| st.plotly_chart( | |
| px.bar(df_miners, x='I', color='I', hover_name=entity_choice, text=entity_choice if ntop < 20 else None, | |
| labels={'I':'Incentive', 'trust':'Trust', 'stake':'Stake', '_index':'Rank'}, | |
| ).update_layout(coloraxis_showscale=False, yaxis_visible=False), | |
| use_container_width=True, | |
| ) | |
| with st.expander('Show raw metagraph data'): | |
| st.dataframe(df_m) | |
| st.markdown('<br>', unsafe_allow_html=True) | |
| #### ------ LOGGED RUNS ------ | |
| # st.subheader('Logged runs') | |
| # st.info('The timeline shows the creation and last event time of each run.') | |
| # st.plotly_chart( | |
| # px.timeline(df, x_start='created_at', x_end='last_event_at', y='username', color='state', | |
| # labels={'created_at':'Created at', 'last_event_at':'Last event at', 'username':''}, | |
| # ), | |
| # use_container_width=True | |
| # ) | |
| # with st.expander('Show raw run data'): | |
| # st.dataframe(df) |