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