Spaces:
Sleeping
Sleeping
File size: 2,078 Bytes
d272f9e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
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
""")
|