Heat_Map / modules /visuals.py
Nawinkumar15's picture
Update modules/visuals.py
62c93b9 verified
import streamlit as st
import pydeck as pdk
def display_map(df):
st.subheader("πŸ“ Smart Poles Location Map with Alerts")
alert_colors = {
"Green": [0, 255, 0],
"Yellow": [255, 255, 0],
"Red": [255, 0, 0]
}
df["color"] = df["Alert Level"].apply(lambda x: alert_colors.get(x, [0, 0, 0]))
layer = pdk.Layer(
"ScatterplotLayer",
data=df,
get_position='[Longitude, Latitude]',
get_color="color",
get_radius=4,
pickable=True,
)
view_state = pdk.ViewState(
latitude=df["Latitude"].mean(),
longitude=df["Longitude"].mean(),
zoom=8,
pitch=0
)
tooltip = {
"html": "<b>Pole:</b> {Pole ID} <br/><b>Site:</b> {Site} <br/><b>Alert:</b> {Alert Level} <br/><b>Anomalies:</b> {Anomalies}",
"style": {"backgroundColor": "steelblue", "color": "white"}
}
st.pydeck_chart(pdk.Deck(layers=[layer], initial_view_state=view_state, tooltip=tooltip))
def display_dashboard(df):
st.subheader("πŸ“Š System Summary")
col1, col2, col3 = st.columns(3)
col1.metric("Total Poles", df.shape[0])
col2.metric("🚨 Red Alerts", df[df['Alert Level'] == "Red"].shape[0])
col3.metric("⚑ Power Issues", df[df['Power Sufficient'] == "No"].shape[0])
def display_charts(df):
st.subheader("βš™οΈ Energy Generation Trends")
st.bar_chart(df.set_index("Pole ID")[["Solar Gen (kWh)", "Wind Gen (kWh)"]])
st.subheader("πŸ“‰ Tilt vs Vibration")
scatter_df = df.rename(columns={"Tilt (Β°)": "Tilt", "Vibration (g)": "Vibration"})
st.scatter_chart(scatter_df.set_index("Pole ID")[["Tilt", "Vibration"]])