Spaces:
Runtime error
Runtime error
File size: 7,217 Bytes
d60e033 6e49f7b d60e033 f145778 d7cb618 1fbe6f1 30a937a 1fbe6f1 30a937a 807f2c6 e106f11 1fbe6f1 d7cb618 18cc147 7351df4 18cc147 7458408 18cc147 7351df4 18cc147 9f9e18e e6f2d5e f46e4cd e6f2d5e 7351df4 e6f2d5e 18cc147 05b7c85 e6f2d5e 78f3bba cfff22d 9da1266 d7cb618 7fb5ee1 ed8977f d7cb618 7fb5ee1 ed8977f 04ea239 ed8977f d7cb618 0845357 dd1f670 edafd41 dd1f670 ed8977f 926c750 04ea239 dd1f670 04ea239 926c750 ed8977f 78f3bba 75eef70 48244a4 76bcdcc 926c750 f87d4b0 04ea239 a6bee90 f87d4b0 fdc6ee6 0845357 ed8977f 926c750 cfff22d d7cb618 ed8977f f87d4b0 04ea239 fa458e1 a6bee90 3be802b f87d4b0 d7cb618 34735a3 04fbb28 30e51a1 cc6fb9a 30e51a1 61b68c5 04fbb28 1e9b1ef 28fc158 7194023 e10366b 28fc158 114081b 7194023 34735a3 7194023 28fc158 ed8977f 93a651b 61b68c5 | 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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | import streamlit as st
import pandas as pd
import plotly.express as px
st.set_page_config(layout="wide")
# Load the dataset
data = pd.read_csv('manafeth_es_output.csv')
# Remove commas and convert to numeric values for all columns except 'Date'
data[data.columns.difference(['Date'])] = data[data.columns.difference(['Date'])].replace(',', '', regex=True).astype(float)
# Convert 'Date' column to datetime
data['Date'] = pd.to_datetime(data['Date'])
# Set 'Date' column as the index
data.set_index('Date', inplace=True)
data.drop(data.index[-1], inplace=True)
# Filter out rows beyond 2025 and drop them
data.index = pd.to_datetime(data.index)
#data = data[data.index.year <= 2025]
#data.index = data.index.date
# Set up the Streamlit app
st.set_option('deprecation.showPyplotGlobalUse', False)
# # Set the title of your Streamlit app
# title = 'Dashboard'
# # Set the URL of the logo image
# logo_url = "https://i.imgur.com/x5OCu61.png"
# # Create the HTML markup to display the logo
# logo_html = f'<img src="{logo_url}" alt="Logo" style="vertical-align:middle; margin-right:10px; width:50px;">'
# # Combine the logo HTML with the title text
# title_html = f'{logo_html}<span style="font-size:32px;">{title}</span>'
# # Render the title with logo using markdown
# st.markdown(title_html, unsafe_allow_html=True)
# Set the title of your Streamlit app
title = 'Dashboard'
# Set the URL of the logo image
logo_url = "https://i.imgur.com/x5OCu61.png"
# Set the URL of the additional image
image_url = "https://i.imgur.com/xsTBjxI.png"
# Create the HTML markup to display the logo
logo_html = f'<img src="{logo_url}" alt="Logo" style="vertical-align:middle; margin-right:10px; width:50px;">'
# Create the HTML markup to display the additional image
image_html = f'<img src="{image_url}" alt="Image" style="vertical-align:middle; margin-left:625px; width:100px;">'
# Combine the logo HTML, title text, and additional image HTML
title_html = f'{logo_html}<span style="font-size:32px;">{title}</span>{image_html}'
# Render the title with logo and additional image using markdown
st.markdown(title_html, unsafe_allow_html=True)
linewidths = 1300
tab1, tab2, tab3, corrs = st.tabs(["Dataset & Summary", "Plots", "Max Insights",'Borders Comparison & Correlation'])
with tab1:
# Display the dataset
with st.container():
st.dataframe(data)
# Show summary statistics
summary = data.copy(deep=True)
summary.drop('Month sum',axis=1,inplace=True)
st.subheader('Summary Statistics')
st.write(summary.describe())
import datetime
status = True
with tab2:
st.title('All borders')
# Year range selection using two dropdown boxes
years = pd.unique(data.index.year)
min_year = min(years)
max_year = max(years)
start_year = st.selectbox("Select Start Year", options=range(min_year, max_year + 1), index=0)
end_year = st.selectbox("Select End Year", options=range(start_year, max_year + 1), index=len(range(start_year, max_year + 1))-1)
# Convert start_year and end_year to datetime objects
start_datetime = datetime.datetime(start_year, 1, 1)
end_datetime = datetime.datetime(end_year, 12, 31)
# Filter the data based on the selected year range
filtered_data = data[(data.index >= start_datetime) & (data.index <= end_datetime)]
with st.expander('All borders sum', expanded=status):
fig = px.line(filtered_data, x=filtered_data.index, y=filtered_data.columns[-1], title='All borders ' + str(start_year) + '-' + str(end_year))
fig.update_layout(width=linewidths)
#fig = px.line(data, y=data.columns[-1], color_discrete_sequence=['blue'])
#fig.add_vrect(x0="2023-05", x1=data.index[-1], fillcolor="rgba(0, 255, 0, 0.3)", layer="below", line_width=0)
st.plotly_chart(fig)
# Calculate and display the sum of the selected duration
sum_value = filtered_data.loc[start_datetime:end_datetime, filtered_data.columns[-1]].sum()
sum_value = "{:,.0f}".format(sum_value)
st.markdown(f"<p style='color:white;font-size:35px;'>Sum of selected duration: <span style='color:green'>{sum_value}</span></p>", unsafe_allow_html=True)
st.title('Per border')
for column in data.columns[:-1]:
with st.expander(column, expanded=status):
fig = px.line(filtered_data, x=filtered_data.index, y=column, title=column)
fig.update_layout(width=linewidths)
st.plotly_chart(fig)
# Calculate and display the sum of the selected duration
sum_value = filtered_data.loc[start_datetime:end_datetime, column].sum()
#st.write('Sum of selected duration:', "{:,.0f}".format(sum_value))
sum_value = "{:,.0f}".format(sum_value)
st.markdown(f"<p style='color:white;font-size:35px;'>Sum of selected duration: <span style='color:green'>{sum_value}</span></p>", unsafe_allow_html=True)
#st.write(f"<p style='color:red;font-size:20px;'>Sum of selected duration: {"{:,.0f}".format(sum_value)}</p>", unsafe_allow_html=True)
status = False
with tab3:
col1, col2 = st.columns(2)
with st.container():
st.subheader('Stacked Borders')
# Group data by year and calculate the sum for each border
yearly_data = summary.groupby(summary.index.year).sum()
# Stacked bar chart showing the difference between borders for each year
fig = px.bar(yearly_data, x=yearly_data.index, y=yearly_data.columns, barmode='stack',
title='Stacked Borders by Year')
fig.update_layout(width=linewidths)
st.plotly_chart(fig)
with st.container():
max_values = summary.max()
# Converting max_values to a DataFrame with a single column
max_values_df = pd.DataFrame(max_values, columns=['Maximum Value'])
# Sorting the DataFrame in descending order
max_values_sorted = max_values_df.sort_values(by='Maximum Value', ascending=False)
# Plotting the maximum values over time in descending order
st.subheader('Top borders')
fig = px.bar(max_values_sorted, x=max_values_sorted.index, y='Maximum Value',
labels={'x': 'Columns', 'y': 'Maximum Value'}, title='Borders in descending order')
fig.update_layout(height=600, width=650*2) # Adjust the height value as desired
st.plotly_chart(fig)
with corrs:
st.subheader('Monthly Entries by Border')
with st.expander('Toggle',expanded=True):
# Line chart for monthly entries by border
fig = px.line(data, x=data.index, y=data.columns[:-1], title='Monthly Entries by Border')
fig.update_layout(width=linewidths)
st.plotly_chart(fig)
st.subheader('Correlation heat map')
with st.expander('Toggle'):
correlation = summary.corr()
# st.subheader('Correlation Heatmap')
# st.write(correlation)
fig = px.imshow(correlation, color_continuous_scale='RdBu', labels=dict(x='Columns', y='Columns'),
title='Correlation Heatmap')
fig.update_layout(height=600*2,width=600*2) # Adjust the height value as desired
st.plotly_chart(fig) |