Spaces:
Sleeping
Sleeping
Create map_visualization.py
Browse files- map_visualization.py +58 -0
map_visualization.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
def show_fault_map(df):
|
| 6 |
+
# Filter valid location rows
|
| 7 |
+
df_map = df.dropna(subset=["Location_Latitude__c", "Location_Longitude__c"]).copy()
|
| 8 |
+
|
| 9 |
+
# Define color mapping for alert levels
|
| 10 |
+
alert_color_map = {
|
| 11 |
+
"High": "red",
|
| 12 |
+
"Medium": "yellow",
|
| 13 |
+
"Low": "green",
|
| 14 |
+
"Normal": "green",
|
| 15 |
+
"City": "blue"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
# Apply color mapping
|
| 19 |
+
df_map["Color"] = df_map["Alert_Level__c"].map(alert_color_map).fillna("gray")
|
| 20 |
+
|
| 21 |
+
# Add fixed city markers
|
| 22 |
+
fixed_cities = pd.DataFrame([
|
| 23 |
+
{"Name": "Hyderabad", "Location_Latitude__c": 17.3850, "Location_Longitude__c": 78.4867, "Alert_Level__c": "City", "Color": "blue"},
|
| 24 |
+
{"Name": "Ballari", "Location_Latitude__c": 15.1394, "Location_Longitude__c": 76.9214, "Alert_Level__c": "City", "Color": "blue"},
|
| 25 |
+
{"Name": "Gadwal", "Location_Latitude__c": 16.2333, "Location_Longitude__c": 77.8000, "Alert_Level__c": "City", "Color": "blue"},
|
| 26 |
+
{"Name": "Warangal", "Location_Latitude__c": 17.9784, "Location_Longitude__c": 79.5941, "Alert_Level__c": "City", "Color": "blue"},
|
| 27 |
+
])
|
| 28 |
+
|
| 29 |
+
df_map_combined = pd.concat([df_map, fixed_cities], ignore_index=True)
|
| 30 |
+
|
| 31 |
+
# Define map center (around Telangana/Karnataka)
|
| 32 |
+
map_center = {"lat": 16.5, "lon": 78.0}
|
| 33 |
+
|
| 34 |
+
# Plot map
|
| 35 |
+
fig = px.scatter_mapbox(
|
| 36 |
+
df_map_combined,
|
| 37 |
+
lat="Location_Latitude__c",
|
| 38 |
+
lon="Location_Longitude__c",
|
| 39 |
+
hover_name="Name",
|
| 40 |
+
color="Color",
|
| 41 |
+
color_discrete_map="identity",
|
| 42 |
+
zoom=7,
|
| 43 |
+
center=map_center,
|
| 44 |
+
mapbox_style="open-street-map"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
st.subheader("🗺️ Pole Locations with Fault Levels")
|
| 48 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 49 |
+
|
| 50 |
+
# Optional: Add legend explanation
|
| 51 |
+
with st.expander("🟢 Legend"):
|
| 52 |
+
st.markdown("""
|
| 53 |
+
- 🔴 **Red** = High Alert
|
| 54 |
+
- 🟡 **Yellow** = Medium Alert
|
| 55 |
+
- 🟢 **Green** = Low/Normal
|
| 56 |
+
- 🔵 **Blue** = Fixed Cities
|
| 57 |
+
- ⚪ **Gray** = Unknown
|
| 58 |
+
""")
|