|
|
import pandas as pd |
|
|
import streamlit as st |
|
|
import plotly.express as px |
|
|
import pydeck as pdk |
|
|
|
|
|
|
|
|
def display_dashboard(df: pd.DataFrame): |
|
|
st.subheader("π System Summary") |
|
|
col1, col2, col3, col4 = st.columns(4) |
|
|
|
|
|
|
|
|
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]) |
|
|
|
|
|
|
|
|
def display_charts(df: pd.DataFrame): |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
def generate_heatmap_for_site(site_name, df): |
|
|
site_df = df[df['Site__c'] == site_name] |
|
|
|
|
|
|
|
|
site_df['Alert_Level__c'] = site_df['Alert_Level__c'].astype(str) |
|
|
|
|
|
|
|
|
color_map = { |
|
|
"Green": [0, 255, 0], |
|
|
"Yellow": [255, 255, 0], |
|
|
"Red": [255, 0, 0] |
|
|
} |
|
|
|
|
|
|
|
|
site_df["color"] = site_df["Alert_Level__c"].map(color_map) |
|
|
|
|
|
|
|
|
site_df = site_df.dropna(subset=["Longitude__c", "Latitude__c"]) |
|
|
|
|
|
|
|
|
layer = pdk.Layer( |
|
|
"ScatterplotLayer", |
|
|
data=site_df, |
|
|
get_position='[Longitude__c, Latitude__c]', |
|
|
get_color="color", |
|
|
get_radius=80, |
|
|
pickable=True, |
|
|
auto_highlight=True |
|
|
) |
|
|
|
|
|
|
|
|
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 = { |
|
|
"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 pdk.Deck( |
|
|
map_style="mapbox://styles/mapbox/dark-v10", |
|
|
initial_view_state=view_state, |
|
|
layers=[layer], |
|
|
tooltip=tooltip |
|
|
) |
|
|
|