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": "Pole: {Pole ID}
Site: {Site}
Alert: {Alert Level}
Anomalies: {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"]])