Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,83 @@
|
|
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 |
-
#
|
12 |
-
df = fetch_poles()
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
# Fetch the raw data from Salesforce
|
17 |
df = fetch_poles()
|
18 |
|
19 |
-
#
|
20 |
st.sidebar.header("π Filter Data")
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
)
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
)
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
)
|
|
|
|
|
34 |
|
|
|
|
|
35 |
|
36 |
-
#
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
-
#
|
40 |
st.subheader("π Pole Table")
|
41 |
-
st.dataframe(
|
42 |
|
43 |
-
#
|
44 |
st.subheader("β Energy Generation (Solar vs Wind)")
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_sites = st.sidebar.multiselect("Site", sites, default=sites)
|
23 |
+
selected_camera_status = st.sidebar.selectbox("Camera Status", ["All"] + camera_statuses)
|
|
|
24 |
|
25 |
+
# Apply filters
|
26 |
+
filtered_df = df[
|
27 |
+
(df["Alert_Level__c"].isin(selected_alert_levels)) &
|
28 |
+
(df["Site__c"].isin(selected_sites))
|
29 |
+
]
|
30 |
|
31 |
+
if selected_camera_status != "All":
|
32 |
+
filtered_df = filtered_df[filtered_df["Camera_Status__c"] == selected_camera_status]
|
33 |
|
34 |
+
# --- System Summary ---
|
35 |
+
st.subheader("π System Summary")
|
36 |
+
st.metric("Total Poles", len(filtered_df))
|
37 |
+
st.metric("Red Alerts", len(filtered_df[filtered_df["Alert_Level__c"] == "Red"]))
|
38 |
+
st.metric("Offline Cameras", len(filtered_df[filtered_df["Camera_Status__c"] == "Offline"]))
|
39 |
|
40 |
+
# --- Pole Table ---
|
41 |
st.subheader("π Pole Table")
|
42 |
+
st.dataframe(filtered_df, use_container_width=True)
|
43 |
|
44 |
+
# --- Energy Generation Chart ---
|
45 |
st.subheader("β Energy Generation (Solar vs Wind)")
|
46 |
+
if not filtered_df.empty:
|
47 |
+
energy_chart = px.bar(
|
48 |
+
filtered_df,
|
49 |
+
x="Name",
|
50 |
+
y=["Solar_Generation__c", "Wind_Generation__c"],
|
51 |
+
barmode="group",
|
52 |
+
title="Solar vs Wind Energy Generation"
|
53 |
+
)
|
54 |
+
st.plotly_chart(energy_chart, use_container_width=True)
|
55 |
+
else:
|
56 |
+
st.info("No data available for the selected filters.")
|
57 |
+
|
58 |
+
# --- Alert Level Breakdown ---
|
59 |
+
st.subheader("π¨ Alert Level Breakdown")
|
60 |
+
if not filtered_df.empty:
|
61 |
+
alert_counts = filtered_df["Alert_Level__c"].value_counts().reset_index()
|
62 |
+
alert_counts.columns = ["Alert Level", "Count"]
|
63 |
+
alert_pie = px.pie(alert_counts, values="Count", names="Alert Level", title="Alert Distribution")
|
64 |
+
st.plotly_chart(alert_pie, use_container_width=True)
|
65 |
+
else:
|
66 |
+
st.info("No alerts to display.")
|
67 |
+
|
68 |
+
# --- Tilt & Vibration Chart ---
|
69 |
+
st.subheader("π Tilt & Vibration from RFID")
|
70 |
+
# Example RFID_Tag__c format: "Tilt:12;Vib:34" or "Tilt=12|Vib=34"
|
71 |
+
filtered_df["Tilt"] = filtered_df["RFID_Tag__c"].str.extract(r'Tilt[:=](\d+)').astype(float)
|
72 |
+
filtered_df["Vibration"] = filtered_df["RFID_Tag__c"].str.extract(r'Vib[:=](\d+)').astype(float)
|
73 |
+
|
74 |
+
if not filtered_df[["Tilt", "Vibration"]].dropna().empty:
|
75 |
+
fig = go.Figure()
|
76 |
+
fig.add_trace(go.Scatter(x=filtered_df["Name"], y=filtered_df["Tilt"],
|
77 |
+
mode='lines+markers', name='Tilt'))
|
78 |
+
fig.add_trace(go.Scatter(x=filtered_df["Name"], y=filtered_df["Vibration"],
|
79 |
+
mode='lines+markers', name='Vibration'))
|
80 |
+
fig.update_layout(title="Tilt and Vibration per Pole", xaxis_title="Pole", yaxis_title="Value")
|
81 |
+
st.plotly_chart(fig, use_container_width=True)
|
82 |
+
else:
|
83 |
+
st.info("No Tilt or Vibration data available.")
|