Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,94 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import plotly.express as px
|
| 3 |
from salesforce_integration import fetch_poles
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
st.title("π‘ VIEP Smart Poles Dashboard")
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
except Exception as e:
|
| 12 |
-
st.error(f"β οΈ Error connecting to Salesforce:\n\n{e}")
|
| 13 |
-
st.stop()
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
st.sidebar.header("π Filter Data")
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
filtered_df = df[
|
| 24 |
-
(df["Alert_Level__c"].isin(
|
| 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 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 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 |
-
#
|
| 39 |
st.subheader("π Pole Table")
|
| 40 |
st.dataframe(filtered_df)
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
filtered_df,
|
| 46 |
-
x="
|
| 47 |
-
y=
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
-
st.plotly_chart(
|
| 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.")
|
|
|
|
| 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 |
+
import pandas as pd
|
| 7 |
|
| 8 |
+
# Title
|
| 9 |
st.title("π‘ VIEP Smart Poles Dashboard")
|
| 10 |
|
| 11 |
+
# Get data
|
| 12 |
+
df = fetch_poles()
|
| 13 |
+
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
|
| 16 |
+
# Fetch the raw data from Salesforce
|
| 17 |
+
df = fetch_poles()
|
| 18 |
+
|
| 19 |
+
# Sidebar Filters (your code should go here!)
|
| 20 |
st.sidebar.header("π Filter Data")
|
| 21 |
|
| 22 |
+
selected_alert_levels = st.sidebar.multiselect(
|
| 23 |
+
"Alert Level", ["Red", "Yellow", "Green"], default=["Red", "Yellow", "Green"]
|
| 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 to create filtered_df
|
| 36 |
filtered_df = df[
|
| 37 |
+
(df["Alert_Level__c"].isin(selected_alert_levels)) &
|
| 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 |
+
# Now use filtered_df everywhere
|
| 45 |
+
|
| 46 |
+
# Show system summary
|
| 47 |
+
display_dashboard(filtered_df)
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# Show pole table
|
| 50 |
st.subheader("π Pole Table")
|
| 51 |
st.dataframe(filtered_df)
|
| 52 |
|
| 53 |
+
# Show charts
|
| 54 |
+
display_charts(filtered_df)
|
| 55 |
+
|
| 56 |
+
# Tilt vs Vibration Scatter Plot
|
| 57 |
+
st.subheader("π Tilt vs Vibration")
|
| 58 |
+
fig_tv = px.scatter(
|
| 59 |
+
filtered_df,
|
| 60 |
+
x="Tilt_Angle__c",
|
| 61 |
+
y="Vibration_Level__c",
|
| 62 |
+
color="Alert_Level__c",
|
| 63 |
+
hover_name="Name",
|
| 64 |
+
title="Tilt Angle vs Vibration Level"
|
| 65 |
+
)
|
| 66 |
+
st.plotly_chart(fig_tv)
|
| 67 |
+
|
| 68 |
+
# 1. System Summary (Show first)
|
| 69 |
+
display_dashboard(df)
|
| 70 |
+
|
| 71 |
+
# 2. Pole Table
|
| 72 |
+
st.subheader("π Pole Table")
|
| 73 |
+
st.dataframe(df, use_container_width=True)
|
| 74 |
+
|
| 75 |
+
# 3. Charts
|
| 76 |
+
st.subheader("β Energy Generation (Solar vs Wind)")
|
| 77 |
+
st.plotly_chart(px.bar(df, x="Name", y=["Solar_Generation__c", "Wind_Generation__c"], barmode="group"))
|
| 78 |
+
|
| 79 |
+
# 4. Charts (Energy + Alert Breakdown)
|
| 80 |
+
display_charts(df)
|
| 81 |
+
|
| 82 |
+
import plotly.express as df
|
| 83 |
+
|
| 84 |
+
st.subheader("π Tilt vs Vibration")
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|