Spaces:
Sleeping
Sleeping
File size: 5,190 Bytes
1a57d8f |
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 |
#-------------------------------------libraries ----------------------------------
import os
import pandas as pd
import streamlit as st
import plotly.graph_objs as go
import numpy as np
import plotly.express as px
import logging
# Set up logging basic configuration
logging.basicConfig(level=logging.INFO)
# Example of logging
logging.info("Streamlit app has started")
#-------------------------------------back ----------------------------------
# etherscan
## Load the data from the CSV files
dataframes = []
for filename in os.listdir('output'):
if filename.endswith('.csv'):
df_temp = pd.read_csv(os.path.join('output', filename), sep=';')
dataframes.append(df_temp)
df_etherscan = pd.concat(dataframes)
del df_temp
# CMC
## Load cmc data
df_temp = pd.read_csv("output/top_100_update.csv", sep=',')
df_cmc = df_temp[df_temp["last_updated"] == df_temp["last_updated"].max()]
del df_temp
#-------------------------------------streamlit ----------------------------------
# Set the title and other page configurations
st.title('Crypto Analysis')
# Create two columns for the two plots
col1, col2 = st.columns(2)
with st.container():
with col1:
# etherscan
selected_token = st.selectbox('Select Token', df_etherscan['tokenSymbol'].unique(), index=0)
# Filter the data based on the selected token
filtered_df = df_etherscan[df_etherscan['tokenSymbol'] == selected_token]
# Plot the token value over time
st.plotly_chart(
go.Figure(
data=[
go.Scatter(
x=filtered_df['timeStamp'],
y=filtered_df['value'],
mode='lines',
name='Value over time'
)
],
layout=go.Layout(
title='Token Value Over Time',
yaxis=dict(
title=f'Value ({selected_token})',
),
showlegend=True,
legend=go.layout.Legend(x=0, y=1.0),
margin=go.layout.Margin(l=40, r=0, t=40, b=30),
width=500,
height=500
)
)
)
with col2:
# cmc
selected_var = st.selectbox('Select Token', ["percent_change_24h","percent_change_7d","percent_change_90d"], index=0)
# Sort the DataFrame by the 'percent_change_24h' column in ascending order
df_sorted = df_cmc.sort_values(by=selected_var, ascending=False)
# Select the top 10 and worst 10 rows
top_10 = df_sorted.head(10)
worst_10 = df_sorted.tail(10)
# Combine the top and worst dataframes for plotting
combined_df = pd.concat([top_10, worst_10], axis=0)
max_abs_val = max(abs(combined_df[selected_var].min()), abs(combined_df[selected_var].max()))
# Create a bar plot for the top 10 with a green color scale
fig = go.Figure(data=[
go.Bar(
x=top_10["symbol"],
y=top_10[selected_var],
marker_color='rgb(0,100,0)', # Green color for top 10
hovertext= "Name : "+top_10["name"].astype(str)+ '<br>' +
selected_var + " : " + top_10["percent_tokens_circulation"].astype(str) + '<br>' +
'Market Cap: ' + top_10["market_cap"].astype(str) + '<br>' +
'Fully Diluted Market Cap: ' + top_10["fully_diluted_market_cap"].astype(str) + '<br>' +
'Last Updated: ' + top_10["last_updated"].astype(str),
name="top_10"
)
])
# Add the worst 10 to the same plot with a red color scale
fig.add_traces(go.Bar(
x=worst_10["symbol"],
y=worst_10[selected_var],
marker_color='rgb(255,0,0)', # Red color for worst 10
hovertext="Name:"+worst_10["name"].astype(str)+ '<br>' +
selected_var + " : " + worst_10["percent_tokens_circulation"].astype(str) + '<br>' +
'Market Cap: ' + worst_10["market_cap"].astype(str) + '<br>' +
'Fully Diluted Market Cap: ' + worst_10["fully_diluted_market_cap"].astype(str) + '<br>' +
'Last Updated: ' + worst_10["last_updated"].astype(str),
name="worst_10"
)
)
# Customize aspect
fig.update_traces(marker_line_color='rgb(8,48,107)', marker_line_width=1.5, opacity=0.8)
fig.update_layout(title_text=f'Top 10 and Worst 10 by {selected_var.split("_")[-1]} Percentage Change')
fig.update_xaxes(categoryorder='total ascending')
fig.update_layout(
autosize=False,
width=500,
height=500,
margin=dict(
l=50,
r=50,
b=100,
t=100,
pad=4
),
#paper_bgcolor="LightSteelBlue",
)
st.plotly_chart(fig)
#-------------------------------------end ----------------------------------
|