Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,50 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
-
import
|
5 |
from salesforce_integration import fetch_poles
|
|
|
6 |
|
7 |
# Title
|
8 |
st.title("π‘ VIEP Smart Poles Dashboard")
|
9 |
|
10 |
-
# Fetch data
|
11 |
df = fetch_poles()
|
12 |
|
13 |
-
# Sidebar Filters
|
14 |
st.sidebar.header("π Filter Data")
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
selected_camera_status = st.sidebar.selectbox(
|
|
|
|
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
28 |
|
29 |
if selected_camera_status != "All":
|
30 |
filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
|
31 |
|
32 |
-
# Site filter logic (place here)
|
33 |
-
site_options = ["All"] + df["Site__c"].dropna().unique().tolist()
|
34 |
-
selected_site = st.sidebar.selectbox("Site", site_options, index=0)
|
35 |
if selected_site != "All":
|
36 |
filtered_df = filtered_df[filtered_df["Site__c"] == selected_site]
|
37 |
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
# --- System Summary ---
|
44 |
-
st.subheader("π System Summary")
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
col1.metric("Total Poles", len(filtered_df))
|
49 |
-
col2.metric("Red Alerts", len(filtered_df[filtered_df["Alert_Level__c"] == "Red"]))
|
50 |
-
col3.metric("Offline Cameras", len(filtered_df[filtered_df["Camera_Status__c"] == "Offline"]))
|
51 |
|
52 |
# --- Pole Table ---
|
53 |
st.subheader("π Pole Table")
|
@@ -55,54 +52,86 @@ st.dataframe(filtered_df, use_container_width=True)
|
|
55 |
|
56 |
# --- Energy Generation Chart ---
|
57 |
st.subheader("β Energy Generation (Solar vs Wind)")
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
#
|
81 |
-
st.subheader("
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
+
import pydeck as pdk
|
5 |
from salesforce_integration import fetch_poles
|
6 |
+
from modules.visuals import display_dashboard, display_charts
|
7 |
|
8 |
# Title
|
9 |
st.title("π‘ VIEP Smart Poles Dashboard")
|
10 |
|
11 |
+
# Fetch the raw data from Salesforce
|
12 |
df = fetch_poles()
|
13 |
|
14 |
+
# --- Sidebar Filters ---
|
15 |
st.sidebar.header("π Filter Data")
|
16 |
|
17 |
+
# Alert Level Filter
|
18 |
+
selected_alert_levels = st.sidebar.multiselect(
|
19 |
+
"Alert Level", ["Red", "Yellow", "Green"], default=["Red", "Yellow", "Green"]
|
20 |
+
)
|
21 |
|
22 |
+
# Camera Status Filter
|
23 |
+
selected_camera_status = st.sidebar.selectbox(
|
24 |
+
"Camera Status", ["All", "Online", "Offline"]
|
25 |
+
)
|
26 |
|
27 |
+
# Site Filter with "All" option
|
28 |
+
site_options = ["All"] + df["Site__c"].dropna().unique().tolist()
|
29 |
+
selected_site = st.sidebar.selectbox("Site", site_options, index=0)
|
30 |
+
|
31 |
+
# --- Filtering Logic ---
|
32 |
+
filtered_df = df[df["Alert_Level__c"].isin(selected_alert_levels)]
|
33 |
|
34 |
if selected_camera_status != "All":
|
35 |
filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
|
36 |
|
|
|
|
|
|
|
37 |
if selected_site != "All":
|
38 |
filtered_df = filtered_df[filtered_df["Site__c"] == selected_site]
|
39 |
|
40 |
+
# --- Count Faults Based on Alert Level ---
|
41 |
+
# Assuming default 0 fault count or based on Alert Level:
|
42 |
+
filtered_df["Fault_Count__c"] = filtered_df["Alert_Level__c"].apply(
|
43 |
+
lambda x: 3 if x == "Red" else (2 if x == "Yellow" else 1)
|
44 |
+
)
|
|
|
|
|
45 |
|
46 |
+
# --- Display System Summary ---
|
47 |
+
display_dashboard(filtered_df)
|
|
|
|
|
|
|
48 |
|
49 |
# --- Pole Table ---
|
50 |
st.subheader("π Pole Table")
|
|
|
52 |
|
53 |
# --- Energy Generation Chart ---
|
54 |
st.subheader("β Energy Generation (Solar vs Wind)")
|
55 |
+
st.plotly_chart(px.bar(
|
56 |
+
filtered_df,
|
57 |
+
x="Name",
|
58 |
+
y=["Solar_Generation__c", "Wind_Generation__c"],
|
59 |
+
barmode="group"
|
60 |
+
))
|
61 |
+
|
62 |
+
# --- Tilt vs Vibration Chart ---
|
63 |
+
st.subheader("π§ Tilt vs Vibration Comparison")
|
64 |
+
|
65 |
+
fig_tilt_vibration = px.line(
|
66 |
+
filtered_df,
|
67 |
+
x="Name",
|
68 |
+
y=["Tilt__c", "Vibration__c"],
|
69 |
+
markers=True,
|
70 |
+
title="Tilt vs Vibration per Pole"
|
71 |
+
)
|
72 |
+
st.plotly_chart(fig_tilt_vibration)
|
73 |
+
|
74 |
+
# --- Alert Level Breakdown Chart ---
|
75 |
+
display_charts(filtered_df)
|
76 |
+
|
77 |
+
# --- Heatmap Section ---
|
78 |
+
st.subheader("π‘ Pole Fault Heatmap")
|
79 |
+
|
80 |
+
# Map Color based on Faults
|
81 |
+
def get_fault_level(fault_count):
|
82 |
+
if fault_count <= 1:
|
83 |
+
return "Green"
|
84 |
+
elif 2 <= fault_count <= 3:
|
85 |
+
return "Yellow"
|
86 |
+
else:
|
87 |
+
return "Red"
|
88 |
+
|
89 |
+
filtered_df["Fault_Level"] = filtered_df["Fault_Count__c"].apply(get_fault_level)
|
90 |
+
|
91 |
+
color_map = {
|
92 |
+
"Green": [0, 255, 0],
|
93 |
+
"Yellow": [255, 255, 0],
|
94 |
+
"Red": [255, 0, 0]
|
95 |
+
}
|
96 |
+
filtered_df["color"] = filtered_df["Fault_Level"].map(color_map)
|
97 |
+
|
98 |
+
# Pydeck Map
|
99 |
+
layer = pdk.Layer(
|
100 |
+
"ScatterplotLayer",
|
101 |
+
data=filtered_df,
|
102 |
+
get_position='[Longitude__c, Latitude__c]',
|
103 |
+
get_color="color",
|
104 |
+
get_radius=80,
|
105 |
+
pickable=True,
|
106 |
+
auto_highlight=True
|
107 |
+
)
|
108 |
+
|
109 |
+
view_state = pdk.ViewState(
|
110 |
+
latitude=filtered_df["Latitude__c"].mean(),
|
111 |
+
longitude=filtered_df["Longitude__c"].mean(),
|
112 |
+
zoom=10,
|
113 |
+
pitch=40
|
114 |
+
)
|
115 |
+
|
116 |
+
tooltip = {
|
117 |
+
"html": """
|
118 |
+
<b>Pole Name:</b> {Name}<br/>
|
119 |
+
<b>Site:</b> {Site__c}<br/>
|
120 |
+
<b>Fault Count:</b> {Fault_Count__c}<br/>
|
121 |
+
<b>Alert Level:</b> {Alert_Level__c}<br/>
|
122 |
+
<b>RFID Tag:</b> {RFID_Tag__c}<br/>
|
123 |
+
<b>Tilt:</b> {Tilt__c}<br/>
|
124 |
+
<b>Vibration:</b> {Vibration__c}
|
125 |
+
""",
|
126 |
+
"style": {
|
127 |
+
"backgroundColor": "steelblue",
|
128 |
+
"color": "white"
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
st.pydeck_chart(pdk.Deck(
|
133 |
+
map_style="mapbox://styles/mapbox/dark-v10",
|
134 |
+
initial_view_state=view_state,
|
135 |
+
layers=[layer],
|
136 |
+
tooltip=tooltip
|
137 |
+
))
|