Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,108 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
import streamlit as st
|
4 |
-
|
5 |
import plotly.express as px
|
6 |
-
|
|
|
7 |
|
|
|
|
|
8 |
|
|
|
|
|
9 |
|
10 |
-
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
st.subheader("π Pole Table")
|
17 |
-
st.dataframe(
|
18 |
|
19 |
-
#
|
20 |
st.subheader("β Energy Generation (Solar vs Wind)")
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
st.subheader("π₯ Camera Status")
|
24 |
-
st.plotly_chart(px.pie(df, names="Camera_Status__c", hole=0.4))
|
25 |
-
display_dashboard(df)
|
26 |
-
display_charts(df)
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
+
import plotly.graph_objects as go
|
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 |
+
# Dynamic values from Salesforce data
|
17 |
+
alert_levels = df["Alert_Level__c"].dropna().unique().tolist()
|
18 |
+
sites = df["Site__c"].dropna().unique().tolist()
|
19 |
+
camera_statuses = df["Camera_Status__c"].dropna().unique().tolist()
|
20 |
+
|
21 |
+
selected_alert_levels = st.sidebar.multiselect("Alert Level", alert_levels, default=alert_levels)
|
22 |
+
selected_camera_status = st.sidebar.selectbox("Camera Status", ["All"] + camera_statuses)
|
23 |
+
|
24 |
+
# Initial filtering by alert level and camera status
|
25 |
+
filtered_df = df[
|
26 |
+
(df["Alert_Level__c"].isin(selected_alert_levels))
|
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 |
+
# Site filter logic (place here)
|
39 |
+
if selected_site != "All":
|
40 |
+
filtered_df = filtered_df[filtered_df["Site__c"] == selected_site]
|
41 |
|
42 |
+
|
43 |
+
# --- System Summary ---
|
44 |
+
st.subheader("π System Summary")
|
45 |
+
|
46 |
+
col1, col2, col3 = st.columns(3)
|
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")
|
54 |
+
st.dataframe(filtered_df, use_container_width=True)
|
55 |
|
56 |
+
# --- Energy Generation Chart ---
|
57 |
st.subheader("β Energy Generation (Solar vs Wind)")
|
58 |
+
if not filtered_df.empty:
|
59 |
+
energy_chart = px.bar(
|
60 |
+
filtered_df,
|
61 |
+
x="Name",
|
62 |
+
y=["Solar_Generation__c", "Wind_Generation__c"],
|
63 |
+
barmode="group",
|
64 |
+
title="Solar vs Wind Energy Generation"
|
65 |
+
)
|
66 |
+
st.plotly_chart(energy_chart, use_container_width=True)
|
67 |
+
else:
|
68 |
+
st.info("No data available for the selected filters.")
|
69 |
+
|
70 |
+
# --- Alert Level Breakdown ---
|
71 |
+
st.subheader("π¨ Alert Level Breakdown")
|
72 |
+
if not filtered_df.empty:
|
73 |
+
alert_counts = filtered_df["Alert_Level__c"].value_counts().reset_index()
|
74 |
+
alert_counts.columns = ["Alert Level", "Count"]
|
75 |
+
alert_pie = px.pie(alert_counts, values="Count", names="Alert Level", title="Alert Distribution")
|
76 |
+
st.plotly_chart(alert_pie, use_container_width=True)
|
77 |
+
else:
|
78 |
+
st.info("No alerts to display.")
|
79 |
+
|
80 |
+
# 5. Tilt vs Vibration Chart
|
81 |
+
st.subheader("π Tilt vs Vibration")
|
82 |
+
|
83 |
+
# Extract Tilt and Vibration from RFID_Tag__c
|
84 |
+
filtered_df["Tilt"] = filtered_df["RFID_Tag__c"].str.extract(r'Tilt:(\d+\.?\d*)').astype(float)
|
85 |
+
filtered_df["Vibration"] = filtered_df["RFID_Tag__c"].str.extract(r'Vib:(\d+\.?\d*)').astype(float)
|
86 |
+
|
87 |
+
# Drop rows with no tilt or vibration data
|
88 |
+
tilt_vib_df = filtered_df.dropna(subset=["Tilt", "Vibration"])
|
89 |
+
|
90 |
+
if not tilt_vib_df.empty:
|
91 |
+
fig_tilt_vib = go.Figure()
|
92 |
+
fig_tilt_vib.add_trace(go.Scatter(
|
93 |
+
x=tilt_vib_df["Name"],
|
94 |
+
y=tilt_vib_df["Tilt"],
|
95 |
+
mode='lines+markers',
|
96 |
+
name='Tilt'
|
97 |
+
))
|
98 |
+
fig_tilt_vib.add_trace(go.Scatter(
|
99 |
+
x=tilt_vib_df["Name"],
|
100 |
+
y=tilt_vib_df["Vibration"],
|
101 |
+
mode='lines+markers',
|
102 |
+
name='Vibration'
|
103 |
+
))
|
104 |
+
fig_tilt_vib.update_layout(title="Tilt vs Vibration by Pole", xaxis_title="Pole Name", yaxis_title="Value")
|
105 |
+
st.plotly_chart(fig_tilt_vib, use_container_width=True)
|
106 |
+
else:
|
107 |
+
st.info("No Tilt or Vibration data available.")
|
108 |
|
|
|
|
|
|
|
|