Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import plotly.express as px | |
| import pandas as pd | |
| def display_dashboard(df, location): | |
| st.subheader(f"📊 System Summary - {location}") | |
| col1, col2, col3 = st.columns(3) | |
| col1.metric("Total Poles", df.shape[0]) | |
| col2.metric("🚨 Red Alerts", df[df['AlertLevel'] == "Red"].shape[0]) | |
| col3.metric("⚡ Power Issues", df[df['PowerSufficient'] == "No"].shape[0]) | |
| def display_charts(df): | |
| st.subheader("⚙️ Energy Generation Trends") | |
| st.bar_chart(df.groupby("Zone")[["SolarGen(kWh)", "WindGen(kWh)"]].sum()) | |
| st.subheader("📉 Tilt vs Vibration") | |
| st.scatter_chart(df.rename(columns={"Tilt(°)": "Tilt", "Vibration(g)": "Vibration"}).set_index("PoleID")[["Tilt", "Vibration"]]) | |
| def display_map_heatmap(df, location): | |
| if df.empty: | |
| st.warning("No data available for this location.") | |
| return | |
| # Map AlertLevel to sizes and styles | |
| df = df.copy() | |
| df["AlertColor"] = df["AlertLevel"].map({"Green": "green", "Yellow": "yellow", "Red": "red"}) | |
| df["MarkerSize"] = df["AlertLevel"].map({"Green": 10, "Yellow": 15, "Red": 20}) | |
| df["MarkerSymbol"] = df["AlertLevel"].map({"Green": "circle", "Yellow": "circle", "Red": "star"}) | |
| df["MarkerOpacity"] = df["AlertLevel"].map({"Green": 0.7, "Yellow": 0.8, "Red": 1.0}) | |
| # Create scatter map | |
| fig = px.scatter_mapbox( | |
| df, | |
| lat="Latitude", | |
| lon="Longitude", | |
| color="AlertLevel", | |
| color_discrete_map={"Green": "green", "Yellow": "yellow", "Red": "red"}, | |
| size="MarkerSize", | |
| size_max=25, | |
| zoom=11, | |
| hover_data={ | |
| "PoleID": True, | |
| "RFID": True, | |
| "AlertLevel": True, | |
| "Anomalies": True, | |
| "Zone": True, | |
| "Latitude": False, | |
| "Longitude": False | |
| }, | |
| title=f"Pole Alert Map - {location}", | |
| height=600 | |
| ) | |
| fig.update_traces( | |
| marker=dict( | |
| symbol=df["MarkerSymbol"], | |
| opacity=df["MarkerOpacity"] | |
| ) | |
| ) | |
| fig.update_layout( | |
| mapbox_style="open-street-map", | |
| margin={"r":0,"t":50,"l":0,"b":0}, | |
| showlegend=True | |
| ) | |
| st.plotly_chart(fig, use_container_width=True) |