Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import requests
|
|
| 6 |
from io import BytesIO
|
| 7 |
import streamlit as st
|
| 8 |
import streamlit.components.v1 as components
|
|
|
|
| 9 |
|
| 10 |
# Load data from Excel URL with error handling
|
| 11 |
def load_data(url):
|
|
@@ -94,23 +95,36 @@ def calculate_impact(df, center):
|
|
| 94 |
# Return the new statistics
|
| 95 |
return latency_reduction, download_increase, upload_increase, avg_latency_before, avg_download_before, avg_upload_before
|
| 96 |
|
| 97 |
-
# Display the
|
| 98 |
-
def
|
| 99 |
-
|
| 100 |
-
"
|
| 101 |
-
|
| 102 |
-
"Download Speed": f"{avg_download_before:.2f} Mbps",
|
| 103 |
-
"Upload Speed": f"{avg_upload_before:.2f} Mbps"
|
| 104 |
-
},
|
| 105 |
-
"After Data Center": {
|
| 106 |
-
"Latency": f"{latency_reduction:.2f} ms",
|
| 107 |
-
"Download Speed": f"{download_increase:.2f} Mbps",
|
| 108 |
-
"Upload Speed": f"{upload_increase:.2f} Mbps"
|
| 109 |
-
}
|
| 110 |
-
}
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
# Main function to run the application
|
| 116 |
def main():
|
|
@@ -137,7 +151,7 @@ def main():
|
|
| 137 |
# Calculate the impact of adding the data center
|
| 138 |
latency_reduction, download_increase, upload_increase, avg_latency_before, avg_download_before, avg_upload_before = calculate_impact(df, center)
|
| 139 |
if latency_reduction is not None:
|
| 140 |
-
|
| 141 |
|
| 142 |
if __name__ == "__main__":
|
| 143 |
main()
|
|
|
|
| 6 |
from io import BytesIO
|
| 7 |
import streamlit as st
|
| 8 |
import streamlit.components.v1 as components
|
| 9 |
+
import plotly.express as px
|
| 10 |
|
| 11 |
# Load data from Excel URL with error handling
|
| 12 |
def load_data(url):
|
|
|
|
| 95 |
# Return the new statistics
|
| 96 |
return latency_reduction, download_increase, upload_increase, avg_latency_before, avg_download_before, avg_upload_before
|
| 97 |
|
| 98 |
+
# Display the 3D bar chart for impact
|
| 99 |
+
def display_3d_bar_chart(latency_reduction, download_increase, upload_increase, avg_latency_before, avg_download_before, avg_upload_before):
|
| 100 |
+
if latency_reduction is None:
|
| 101 |
+
st.write("No data to display in the chart.")
|
| 102 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
# Create data for plotting
|
| 105 |
+
metrics = ['Latency (ms)', 'Download Speed (Mbps)', 'Upload Speed (Mbps)']
|
| 106 |
+
before = [avg_latency_before, avg_download_before, avg_upload_before]
|
| 107 |
+
after = [latency_reduction, download_increase, upload_increase]
|
| 108 |
+
|
| 109 |
+
impact_data = pd.DataFrame({
|
| 110 |
+
'Metric': metrics,
|
| 111 |
+
'Before': before,
|
| 112 |
+
'After': after
|
| 113 |
+
})
|
| 114 |
+
|
| 115 |
+
# Create a 3D bar chart using Plotly
|
| 116 |
+
fig = px.bar(
|
| 117 |
+
impact_data,
|
| 118 |
+
x='Metric',
|
| 119 |
+
y=['Before', 'After'],
|
| 120 |
+
barmode='group',
|
| 121 |
+
title="Impact of Data Center on Latency and Bandwidth",
|
| 122 |
+
labels={"value": "Speed / Latency", "Metric": "Metric"},
|
| 123 |
+
height=400
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
# Display the chart in the Streamlit app
|
| 127 |
+
st.plotly_chart(fig)
|
| 128 |
|
| 129 |
# Main function to run the application
|
| 130 |
def main():
|
|
|
|
| 151 |
# Calculate the impact of adding the data center
|
| 152 |
latency_reduction, download_increase, upload_increase, avg_latency_before, avg_download_before, avg_upload_before = calculate_impact(df, center)
|
| 153 |
if latency_reduction is not None:
|
| 154 |
+
display_3d_bar_chart(latency_reduction, download_increase, upload_increase, avg_latency_before, avg_download_before, avg_upload_before)
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|
| 157 |
main()
|