File size: 3,409 Bytes
265edfa 1b1a976 265edfa 1b1a976 265edfa 1b1a976 265edfa 1b1a976 265edfa 1b1a976 265edfa 1b1a976 265edfa 1b1a976 12e1cba 1b1a976 265edfa 123c8d1 1b1a976 123c8d1 6795c4b 23bf7c3 1b1a976 123c8d1 1b1a976 123c8d1 1b1a976 123c8d1 1b1a976 123c8d1 1b1a976 |
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
import pandas as pd
import streamlit as st
import plotly.express as px
import pydeck as pdk
# Function to display system summary metrics
def display_dashboard(df: pd.DataFrame):
st.subheader("📊 System Summary")
col1, col2, col3, col4 = st.columns(4)
# Metrics for Total Poles, Red Alerts, Power Issues, Offline Cameras
col1.metric("Total Poles", df.shape[0])
col2.metric("🚨 Red Alerts", df[df["Alert_Level__c"] == "Red"].shape[0])
col3.metric("⚡ Power Issues", df[df["Power_Sufficient__c"] == "No"].shape[0])
col4.metric("📷 Offline Cameras", df[df["Camera_Status__c"] == "Offline"].shape[0])
# Function to display charts related to energy generation and alert levels
def display_charts(df: pd.DataFrame):
# Energy Generation Bar Chart
fig_energy = px.bar(
df,
x="Name",
y=["Solar_Generation__c", "Wind_Generation__c"],
title="Energy Generation (Solar vs Wind)"
)
st.plotly_chart(fig_energy)
# Alert Level Breakdown Histogram
st.subheader("🚨 Alert Level Breakdown")
fig_alerts = px.histogram(
df,
x="Alert_Level__c",
title="Number of Poles by Alert Level"
)
st.plotly_chart(fig_alerts)
# Function to generate heatmap for a given site
def generate_heatmap_for_site(site_name, df):
site_df = df[df['Site__c'] == site_name]
# Ensure that Alert_Level__c is treated as a string (for color mapping)
site_df['Alert_Level__c'] = site_df['Alert_Level__c'].astype(str)
# Define color mapping for alert levels
color_map = {
"Green": [0, 255, 0], # Green for "Green" alert level
"Yellow": [255, 255, 0], # Yellow for "Yellow" alert level
"Red": [255, 0, 0] # Red for "Red" alert level
}
# Create a color column based on Alert_Level__c
site_df["color"] = site_df["Alert_Level__c"].map(color_map)
# Drop rows with missing Longitude or Latitude to avoid errors in the map
site_df = site_df.dropna(subset=["Longitude__c", "Latitude__c"])
# Create a Pydeck map for the site
layer = pdk.Layer(
"ScatterplotLayer",
data=site_df,
get_position='[Longitude__c, Latitude__c]',
get_color="color",
get_radius=80, # You can adjust the radius if needed
pickable=True,
auto_highlight=True
)
# Set the view state to center the map on the site
latitude = site_df["Latitude__c"].mean() if not site_df["Latitude__c"].isnull().all() else 0
longitude = site_df["Longitude__c"].mean() if not site_df["Longitude__c"].isnull().all() else 0
view_state = pdk.ViewState(
latitude=latitude,
longitude=longitude,
zoom=10,
pitch=40
)
# Tooltip for when you hover over a pole
tooltip = {
"html": """
<b>Pole Name:</b> {Name}<br>
<b>Site:</b> {Site__c}<br>
<b>Alert Level:</b> {Alert_Level__c}<br>
<b>RFID Tag:</b> {RFID_Tag__c}<br>
<b>Tilt:</b> {Tilt__c}<br>
<b>Vibration:</b> {Vibration__c}
""",
"style": {
"backgroundColor": "steelblue",
"color": "white"
}
}
# Return the heatmap as a Pydeck map
return pdk.Deck(
map_style="mapbox://styles/mapbox/dark-v10",
initial_view_state=view_state,
layers=[layer],
tooltip=tooltip
)
|