Update app.py
Browse files
app.py
CHANGED
@@ -47,9 +47,9 @@ display_charts(filtered_df)
|
|
47 |
def generate_heatmap_for_site(site_name, df):
|
48 |
site_df = df[df['Site__c'] == site_name]
|
49 |
|
50 |
-
|
51 |
site_df['Alert_Level__c'] = site_df['Alert_Level__c'].astype(str)
|
52 |
-
|
53 |
# Define color mapping for alert levels
|
54 |
color_map = {
|
55 |
"Green": [0, 255, 0],
|
@@ -64,16 +64,21 @@ def generate_heatmap_for_site(site_name, df):
|
|
64 |
layer = pdk.Layer(
|
65 |
"ScatterplotLayer",
|
66 |
data=site_df,
|
67 |
-
get_position='[Longitude__c, Latitude__c]',
|
68 |
get_color="color",
|
69 |
-
get_radius=80,
|
70 |
pickable=True,
|
71 |
auto_highlight=True
|
72 |
)
|
73 |
|
|
|
|
|
|
|
|
|
|
|
74 |
view_state = pdk.ViewState(
|
75 |
-
latitude=
|
76 |
-
longitude=
|
77 |
zoom=10,
|
78 |
pitch=40
|
79 |
)
|
@@ -92,7 +97,8 @@ def generate_heatmap_for_site(site_name, df):
|
|
92 |
"color": "white"
|
93 |
}
|
94 |
}
|
95 |
-
|
|
|
96 |
return pdk.Deck(
|
97 |
map_style="mapbox://styles/mapbox/dark-v10",
|
98 |
initial_view_state=view_state,
|
|
|
47 |
def generate_heatmap_for_site(site_name, df):
|
48 |
site_df = df[df['Site__c'] == site_name]
|
49 |
|
50 |
+
# Ensure that Alert_Level__c is treated as a string (for color mapping)
|
51 |
site_df['Alert_Level__c'] = site_df['Alert_Level__c'].astype(str)
|
52 |
+
|
53 |
# Define color mapping for alert levels
|
54 |
color_map = {
|
55 |
"Green": [0, 255, 0],
|
|
|
64 |
layer = pdk.Layer(
|
65 |
"ScatterplotLayer",
|
66 |
data=site_df,
|
67 |
+
get_position='[Longitude__c, Latitude__c]', # Ensure the column names are correct
|
68 |
get_color="color",
|
69 |
+
get_radius=80, # You can adjust the radius if needed
|
70 |
pickable=True,
|
71 |
auto_highlight=True
|
72 |
)
|
73 |
|
74 |
+
# Handle potential missing coordinates for map center
|
75 |
+
latitude = site_df["Latitude__c"].mean() if not site_df["Latitude__c"].isnull().all() else 0
|
76 |
+
longitude = site_df["Longitude__c"].mean() if not site_df["Longitude__c"].isnull().all() else 0
|
77 |
+
|
78 |
+
# View state for the map
|
79 |
view_state = pdk.ViewState(
|
80 |
+
latitude=latitude,
|
81 |
+
longitude=longitude,
|
82 |
zoom=10,
|
83 |
pitch=40
|
84 |
)
|
|
|
97 |
"color": "white"
|
98 |
}
|
99 |
}
|
100 |
+
|
101 |
+
# Return the heatmap
|
102 |
return pdk.Deck(
|
103 |
map_style="mapbox://styles/mapbox/dark-v10",
|
104 |
initial_view_state=view_state,
|