Update app.py
Browse files
app.py
CHANGED
|
@@ -63,64 +63,85 @@ st.plotly_chart(px.bar(
|
|
| 63 |
# --- Alert Level Breakdown Chart ---
|
| 64 |
display_charts(filtered_df)
|
| 65 |
|
| 66 |
-
# --- Heatmap Section ---
|
| 67 |
-
st.subheader("🌡 Pole Fault Heatmap")
|
| 68 |
-
|
| 69 |
-
# Map Color based on Faults
|
| 70 |
-
def get_fault_level(fault_count):
|
| 71 |
-
if fault_count <= 1:
|
| 72 |
-
return "Green"
|
| 73 |
-
elif 2 <= fault_count <= 3:
|
| 74 |
-
return "Yellow"
|
| 75 |
-
else:
|
| 76 |
-
return "Red"
|
| 77 |
-
|
| 78 |
-
filtered_df["Fault_Level"] = filtered_df["Fault_Count__c"].apply(get_fault_level)
|
| 79 |
-
|
| 80 |
-
color_map = {
|
| 81 |
-
"Green": [0, 255, 0],
|
| 82 |
-
"Yellow": [255, 255, 0],
|
| 83 |
-
"Red": [255, 0, 0]
|
| 84 |
-
}
|
| 85 |
-
filtered_df["color"] = filtered_df["Fault_Level"].map(color_map)
|
| 86 |
-
|
| 87 |
-
# Pydeck Map
|
| 88 |
-
layer = pdk.Layer(
|
| 89 |
-
"ScatterplotLayer",
|
| 90 |
-
data=filtered_df,
|
| 91 |
-
get_position='[Longitude__c, Latitude__c]',
|
| 92 |
-
get_color="color",
|
| 93 |
-
get_radius=80,
|
| 94 |
-
pickable=True,
|
| 95 |
-
auto_highlight=True
|
| 96 |
-
)
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
longitude=filtered_df["Location_Longitude__c"].mean(),
|
| 101 |
-
zoom=10,
|
| 102 |
-
pitch=40
|
| 103 |
-
)
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
}
|
| 119 |
-
}
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# --- Alert Level Breakdown Chart ---
|
| 64 |
display_charts(filtered_df)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
# Fetch the raw data from Salesforce
|
| 68 |
+
df = fetch_poles()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
# Define function to generate heatmap based on site
|
| 71 |
+
def generate_heatmap_for_site(site_name, df):
|
| 72 |
+
site_df = df[df['Site__c'] == site_name]
|
| 73 |
+
|
| 74 |
+
# Define color mapping for fault levels
|
| 75 |
+
def get_fault_level(fault_count):
|
| 76 |
+
if fault_count <= 1:
|
| 77 |
+
return "Green"
|
| 78 |
+
elif 2 <= fault_count <= 3:
|
| 79 |
+
return "Yellow"
|
| 80 |
+
else:
|
| 81 |
+
return "Red"
|
| 82 |
+
|
| 83 |
+
color_map = {
|
| 84 |
+
"Green": [0, 255, 0],
|
| 85 |
+
"Yellow": [255, 255, 0],
|
| 86 |
+
"Red": [255, 0, 0]
|
| 87 |
}
|
|
|
|
| 88 |
|
| 89 |
+
site_df["Fault_Level"] = site_df["Fault_Count__c"].apply(get_fault_level)
|
| 90 |
+
site_df["color"] = site_df["Fault_Level"].map(color_map)
|
| 91 |
+
|
| 92 |
+
# Create a Pydeck map for the site
|
| 93 |
+
layer = pdk.Layer(
|
| 94 |
+
"ScatterplotLayer",
|
| 95 |
+
data=site_df,
|
| 96 |
+
get_position='[Longitude__c, Latitude__c]',
|
| 97 |
+
get_color="color",
|
| 98 |
+
get_radius=80,
|
| 99 |
+
pickable=True,
|
| 100 |
+
auto_highlight=True
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
view_state = pdk.ViewState(
|
| 104 |
+
latitude=site_df["Location_Latitude__c"].mean(),
|
| 105 |
+
longitude=site_df["Location_Longitude__c"].mean(),
|
| 106 |
+
zoom=10,
|
| 107 |
+
pitch=40
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
tooltip = {
|
| 111 |
+
"html": """
|
| 112 |
+
<b>Pole Name:</b> {Name}<br>
|
| 113 |
+
<b>Site:</b> {Site__c}<br>
|
| 114 |
+
<b>Fault Count:</b> {Fault_Count__c}<br>
|
| 115 |
+
<b>Alert Level:</b> {Alert_Level__c}<br>
|
| 116 |
+
<b>RFID Tag:</b> {RFID_Tag__c}<br>
|
| 117 |
+
<b>Tilt:</b> {Tilt__c}<br>
|
| 118 |
+
<b>Vibration:</b> {Vibration__c}
|
| 119 |
+
""",
|
| 120 |
+
"style": {
|
| 121 |
+
"backgroundColor": "steelblue",
|
| 122 |
+
"color": "white"
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
return pdk.Deck(
|
| 127 |
+
map_style="mapbox://styles/mapbox/dark-v10",
|
| 128 |
+
initial_view_state=view_state,
|
| 129 |
+
layers=[layer],
|
| 130 |
+
tooltip=tooltip
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
# Divide into four columns (Hyderabad, Kurnool, Ballari, Gadwal)
|
| 134 |
+
col1, col2 = st.columns(2)
|
| 135 |
+
with col1:
|
| 136 |
+
st.subheader("Hyderabad")
|
| 137 |
+
st.pydeck_chart(generate_heatmap_for_site("Hyderabad", df))
|
| 138 |
+
|
| 139 |
+
st.subheader("Kurnool")
|
| 140 |
+
st.pydeck_chart(generate_heatmap_for_site("Kurnool", df))
|
| 141 |
+
|
| 142 |
+
with col2:
|
| 143 |
+
st.subheader("Ballari")
|
| 144 |
+
st.pydeck_chart(generate_heatmap_for_site("Ballari", df))
|
| 145 |
+
|
| 146 |
+
st.subheader("Gadwal")
|
| 147 |
+
st.pydeck_chart(generate_heatmap_for_site("Gadwal", df))
|