Spaces:
Sleeping
Sleeping
import pandas as pd | |
import plotly.express as px | |
import streamlit as st | |
def show_fault_map(df): | |
# Filter valid location rows | |
df_map = df.dropna(subset=["Location_Latitude__c", "Location_Longitude__c"]).copy() | |
# Define color mapping for alert levels | |
alert_color_map = { | |
"High": "red", | |
"Medium": "yellow", | |
"Low": "green", | |
"Normal": "green", | |
"City": "blue" | |
} | |
# Apply color mapping | |
df_map["Color"] = df_map["Alert_Level__c"].map(alert_color_map).fillna("gray") | |
# Add fixed city markers | |
fixed_cities = pd.DataFrame([ | |
{"Name": "Hyderabad", "Location_Latitude__c": 17.3850, "Location_Longitude__c": 78.4867, "Alert_Level__c": "City", "Color": "blue"}, | |
{"Name": "Ballari", "Location_Latitude__c": 15.1394, "Location_Longitude__c": 76.9214, "Alert_Level__c": "City", "Color": "blue"}, | |
{"Name": "Gadwal", "Location_Latitude__c": 16.2333, "Location_Longitude__c": 77.8000, "Alert_Level__c": "City", "Color": "blue"}, | |
{"Name": "Warangal", "Location_Latitude__c": 17.9784, "Location_Longitude__c": 79.5941, "Alert_Level__c": "City", "Color": "blue"}, | |
]) | |
df_map_combined = pd.concat([df_map, fixed_cities], ignore_index=True) | |
# Define map center (around Telangana/Karnataka) | |
map_center = {"lat": 16.5, "lon": 78.0} | |
# Plot map | |
fig = px.scatter_mapbox( | |
df_map_combined, | |
lat="Location_Latitude__c", | |
lon="Location_Longitude__c", | |
hover_name="Name", | |
color="Color", | |
color_discrete_map="identity", | |
zoom=7, | |
center=map_center, | |
mapbox_style="open-street-map" | |
) | |
st.subheader("πΊοΈ Pole Locations with Fault Levels") | |
st.plotly_chart(fig, use_container_width=True) | |
# Optional: Add legend explanation | |
with st.expander("π’ Legend"): | |
st.markdown(""" | |
- π΄ **Red** = High Alert | |
- π‘ **Yellow** = Medium Alert | |
- π’ **Green** = Low/Normal | |
- π΅ **Blue** = Fixed Cities | |
- βͺ **Gray** = Unknown | |
""") | |