Update app.py
Browse files
app.py
CHANGED
|
@@ -1,98 +1,69 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import streamlit as st
|
| 3 |
-
from salesforce_integration import fetch_poles
|
| 4 |
-
from modules.visuals import display_dashboard, display_charts
|
| 5 |
import plotly.express as px
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
st.title("π‘ VIEP Smart Poles Dashboard")
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
df = fetch_poles()
|
| 18 |
-
|
| 19 |
-
# Sidebar Filters (your code should go here!)
|
| 20 |
st.sidebar.header("π Filter Data")
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
selected_sites = st.sidebar.multiselect(
|
| 27 |
-
"Site", ["Hyderabad", "Gadwal", "Kurnool", "Ballari"],
|
| 28 |
-
default=["Hyderabad", "Gadwal", "Kurnool", "Ballari"]
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
selected_camera_status = st.sidebar.selectbox(
|
| 32 |
-
"Camera Status", ["All", "Online", "Offline"]
|
| 33 |
-
)
|
| 34 |
|
| 35 |
-
# Apply filters
|
| 36 |
filtered_df = df[
|
| 37 |
-
(df["Alert_Level__c"].isin(
|
| 38 |
(df["Site__c"].isin(selected_sites))
|
| 39 |
]
|
| 40 |
-
|
| 41 |
if selected_camera_status != "All":
|
| 42 |
filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
|
| 43 |
|
| 44 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
display_dashboard(filtered_df)
|
| 48 |
-
|
| 49 |
-
# Show pole table
|
| 50 |
st.subheader("π Pole Table")
|
| 51 |
st.dataframe(filtered_df)
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
# Tilt vs Vibration Scatter Plot
|
| 57 |
-
st.subheader("π Tilt vs Vibration")
|
| 58 |
-
fig_tv = px.scatter(
|
| 59 |
filtered_df,
|
| 60 |
-
x="
|
| 61 |
-
y="
|
| 62 |
-
|
| 63 |
-
hover_name="Name",
|
| 64 |
-
title="Tilt Angle vs Vibration Level"
|
| 65 |
)
|
| 66 |
-
st.plotly_chart(
|
| 67 |
-
|
| 68 |
-
#
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
fig_tv = px.scatter(
|
| 87 |
-
filtered_df,
|
| 88 |
-
x="Tilt_Angle__c", # make sure this is your column name
|
| 89 |
-
y="Vibration_Level__c", # make sure this is your column name
|
| 90 |
-
color="Alert_Level__c",
|
| 91 |
-
hover_name="Name",
|
| 92 |
-
title="Tilt Angle vs Vibration Level"
|
| 93 |
-
)
|
| 94 |
-
st.plotly_chart(fig_tv)
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
import plotly.express as px
|
| 3 |
+
from salesforce_integration import fetch_poles
|
| 4 |
|
| 5 |
+
st.set_page_config(layout="wide")
|
| 6 |
st.title("π‘ VIEP Smart Poles Dashboard")
|
| 7 |
|
| 8 |
+
# β
Fetch raw data
|
| 9 |
+
try:
|
| 10 |
+
df = fetch_poles()
|
| 11 |
+
except Exception as e:
|
| 12 |
+
st.error(f"β οΈ Error connecting to Salesforce:\n\n{e}")
|
| 13 |
+
st.stop()
|
| 14 |
|
| 15 |
+
# β
Sidebar Filters
|
|
|
|
|
|
|
|
|
|
| 16 |
st.sidebar.header("π Filter Data")
|
| 17 |
|
| 18 |
+
selected_alerts = st.sidebar.multiselect("Alert Level", ["Red", "Yellow", "Green"], default=["Red", "Yellow", "Green"])
|
| 19 |
+
selected_sites = st.sidebar.multiselect("Site", df["Site__c"].unique().tolist(), default=df["Site__c"].unique().tolist())
|
| 20 |
+
selected_camera_status = st.sidebar.selectbox("Camera Status", ["All", "Online", "Offline"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# β
Apply filters
|
| 23 |
filtered_df = df[
|
| 24 |
+
(df["Alert_Level__c"].isin(selected_alerts)) &
|
| 25 |
(df["Site__c"].isin(selected_sites))
|
| 26 |
]
|
|
|
|
| 27 |
if selected_camera_status != "All":
|
| 28 |
filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
|
| 29 |
|
| 30 |
+
# β
Dashboard Summary
|
| 31 |
+
st.subheader("π System Summary")
|
| 32 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 33 |
+
col1.metric("Total Poles", filtered_df.shape[0])
|
| 34 |
+
col2.metric("Red Alerts", filtered_df[filtered_df["Alert_Level__c"] == "Red"].shape[0])
|
| 35 |
+
col3.metric("Power Issues", filtered_df[filtered_df["Power_Sufficient__c"] == "No"].shape[0])
|
| 36 |
+
col4.metric("Offline Cameras", filtered_df[filtered_df["Camera_Status__c"] == "Offline"].shape[0])
|
| 37 |
|
| 38 |
+
# β
Pole Table
|
|
|
|
|
|
|
|
|
|
| 39 |
st.subheader("π Pole Table")
|
| 40 |
st.dataframe(filtered_df)
|
| 41 |
|
| 42 |
+
# β
Energy Chart
|
| 43 |
+
st.subheader("β Energy Generation")
|
| 44 |
+
fig1 = px.bar(
|
|
|
|
|
|
|
|
|
|
| 45 |
filtered_df,
|
| 46 |
+
x="Name",
|
| 47 |
+
y=["Solar_Generation__c", "Wind_Generation__c"],
|
| 48 |
+
barmode="group"
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
+
st.plotly_chart(fig1)
|
| 51 |
+
|
| 52 |
+
# β
Camera Status
|
| 53 |
+
st.subheader("π₯ Camera Status Distribution")
|
| 54 |
+
fig2 = px.pie(filtered_df, names="Camera_Status__c", hole=0.4)
|
| 55 |
+
st.plotly_chart(fig2)
|
| 56 |
+
|
| 57 |
+
# β
Tilt vs Vibration
|
| 58 |
+
if "Tilt__c" in filtered_df.columns and "Vibration__c" in filtered_df.columns:
|
| 59 |
+
st.subheader("π Tilt vs Vibration")
|
| 60 |
+
fig3 = px.scatter(
|
| 61 |
+
filtered_df,
|
| 62 |
+
x="Tilt__c",
|
| 63 |
+
y="Vibration__c",
|
| 64 |
+
color="Alert_Level__c",
|
| 65 |
+
hover_name="Name"
|
| 66 |
+
)
|
| 67 |
+
st.plotly_chart(fig3)
|
| 68 |
+
else:
|
| 69 |
+
st.warning("Tilt or Vibration data not available in records.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|