Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
a1551a6
1
Parent(s):
0963bdd
update legend
Browse files- app.py +106 -82
- src/map_utils.py +30 -15
- src/utils.py +0 -3
app.py
CHANGED
@@ -22,11 +22,16 @@ from src.text_content import (
|
|
22 |
SLOGAN,
|
23 |
)
|
24 |
from src.utils import add_latlng_col, init_map, parse_gg_sheet, is_request_in_list, marker_request
|
|
|
25 |
|
26 |
TOKEN = os.environ.get("HF_TOKEN", None)
|
27 |
-
VERIFIED_REQUESTS_URL =
|
|
|
|
|
28 |
REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
|
29 |
-
INTERVENTIONS_URL =
|
|
|
|
|
30 |
api = HfApi(TOKEN)
|
31 |
|
32 |
|
@@ -46,9 +51,7 @@ if "auto_refresh" not in st.session_state:
|
|
46 |
|
47 |
auto_refresh = st.sidebar.checkbox("Auto Refresh?", st.session_state.auto_refresh)
|
48 |
if auto_refresh:
|
49 |
-
number = st.sidebar.number_input(
|
50 |
-
"Refresh rate in seconds", value=st.session_state.sleep_time
|
51 |
-
)
|
52 |
st.session_state.sleep_time = number
|
53 |
|
54 |
|
@@ -58,7 +61,9 @@ def display_interventions(interventions_df, selected_statuses):
|
|
58 |
global fg
|
59 |
for index, row in interventions_df.iterrows():
|
60 |
village_status = row[interventions_df.columns[7]]
|
61 |
-
is_future_intervention =
|
|
|
|
|
62 |
|
63 |
if pd.isna(village_status) and not is_future_intervention:
|
64 |
village_status = "Partiellement satisfait / Partially Served"
|
@@ -69,10 +74,7 @@ def display_interventions(interventions_df, selected_statuses):
|
|
69 |
if is_future_intervention:
|
70 |
color_mk = "pink"
|
71 |
status = "Planned ⌛"
|
72 |
-
elif
|
73 |
-
village_status
|
74 |
-
!= "Critique, Besoin d'aide en urgence / Critical, in urgent need of help"
|
75 |
-
):
|
76 |
# past intervention and village not in a critical condition
|
77 |
color_mk = "green"
|
78 |
status = "Done ✅"
|
@@ -89,13 +91,15 @@ def display_interventions(interventions_df, selected_statuses):
|
|
89 |
intervention_info = f"<b>Intervention Status:</b> {status}<br><b>Village Status:</b> {village_status}<br><b>Org:</b> {org}<br><b>Intervention:</b> {intervention_type}<br><b>Population:</b> {population}<br><b>📅 Date:</b> {date}"
|
90 |
if row["latlng"] is None:
|
91 |
continue
|
92 |
-
|
93 |
-
fg.add_child(
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
99 |
|
100 |
|
101 |
def show_requests(filtered_df):
|
@@ -103,7 +107,7 @@ def show_requests(filtered_df):
|
|
103 |
global fg
|
104 |
for index, row in filtered_df.iterrows():
|
105 |
request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
|
106 |
-
displayed_request = marker_request(request_type)
|
107 |
long_lat = row["latlng"]
|
108 |
maps_url = f"https://maps.google.com/?q={long_lat}"
|
109 |
# we display all requests in popup text and use the first one for the icon/color
|
@@ -112,41 +116,67 @@ def show_requests(filtered_df):
|
|
112 |
if long_lat is None:
|
113 |
continue
|
114 |
|
115 |
-
fg.add_child(
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
125 |
|
126 |
def show_verified_requests(filtered_verified_df):
|
127 |
"""Display verified victim requests on the map"""
|
128 |
global fg
|
|
|
|
|
|
|
|
|
|
|
129 |
for index, row in filtered_verified_df.iterrows():
|
130 |
-
request_type = row["Help Details"]
|
131 |
-
displayed_request = marker_request(request_type) # TODO: the marker should depend on selected_options
|
132 |
long_lat = row["latlng"]
|
133 |
-
maps_url = f"https://maps.google.com/?q={long_lat}"
|
134 |
# we display all requests in popup text and use the first one for the icon/color
|
135 |
-
display_text =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
icon_name = ICON_MAPPING.get(request_type, "list")
|
|
|
137 |
if long_lat is None:
|
138 |
continue
|
139 |
-
location = row[
|
140 |
-
fg.add_child(
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
)
|
149 |
-
)
|
|
|
150 |
|
151 |
def display_google_sheet_tables(data_url):
|
152 |
"""Display the google sheet tables for requests and interventions"""
|
@@ -161,10 +191,7 @@ def display_dataframe(df, drop_cols, data_url, search_id=True, status=False, for
|
|
161 |
col_1, col_2 = st.columns([1, 1])
|
162 |
|
163 |
with col_1:
|
164 |
-
query = st.text_input(
|
165 |
-
"🔍 Search for information / بحث عن المعلومات",
|
166 |
-
key=f"query_{uuid.uuid4()}"
|
167 |
-
)
|
168 |
with col_2:
|
169 |
if search_id:
|
170 |
id_number = st.number_input(
|
@@ -173,13 +200,11 @@ def display_dataframe(df, drop_cols, data_url, search_id=True, status=False, for
|
|
173 |
max_value=len(filtered_df),
|
174 |
value=0,
|
175 |
step=1,
|
176 |
-
key=f"id_{uuid.uuid4()}"
|
177 |
)
|
178 |
if status:
|
179 |
selected_status = st.selectbox(
|
180 |
-
"🗓️ Status / حالة",
|
181 |
-
["all / الكل", "Done / تم", "Planned / مخطط لها"],
|
182 |
-
key=f"status_{uuid.uuid4()}"
|
183 |
)
|
184 |
|
185 |
if query:
|
@@ -197,14 +222,10 @@ def display_dataframe(df, drop_cols, data_url, search_id=True, status=False, for
|
|
197 |
if status:
|
198 |
target = "Pouvez-vous nous préciser si vous êtes déjà intervenus ou si vous prévoyez de le faire | Tell us if you already made the intervention, or if you're planning to do it"
|
199 |
if selected_status == "Done / تم":
|
200 |
-
display_df = display_df[
|
201 |
-
display_df[target] == "Intervention déjà passée / Past intevention"
|
202 |
-
]
|
203 |
|
204 |
elif selected_status == "Planned / مخطط لها":
|
205 |
-
display_df = display_df[
|
206 |
-
display_df[target] != "Intervention déjà passée / Past intevention"
|
207 |
-
]
|
208 |
|
209 |
st.dataframe(display_df, height=500)
|
210 |
# Original link to the Google Sheet
|
@@ -233,9 +254,7 @@ def id_review_submission():
|
|
233 |
with st.expander("🔍 Review of requests | مراجعة طلب مساعدة"):
|
234 |
st.markdown(REVIEW_TEXT)
|
235 |
|
236 |
-
id_to_review = st.number_input(
|
237 |
-
"Enter id / أدخل الرقم", min_value=0, max_value=len(df), value=0, step=1
|
238 |
-
)
|
239 |
reason_for_review = st.text_area("Explain why / أدخل سبب المراجعة")
|
240 |
if st.button("Submit / أرسل"):
|
241 |
if reason_for_review == "":
|
@@ -250,9 +269,7 @@ def id_review_submission():
|
|
250 |
repo_id="nt3awnou/review_requests",
|
251 |
repo_type="dataset",
|
252 |
)
|
253 |
-
st.success(
|
254 |
-
"Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال"
|
255 |
-
)
|
256 |
|
257 |
|
258 |
# Logo and Title
|
@@ -285,9 +302,7 @@ with col2:
|
|
285 |
value=True,
|
286 |
)
|
287 |
|
288 |
-
st.markdown(
|
289 |
-
"👉 **Choose request type | Choissisez le type de demande | اختر نوع الطلب**"
|
290 |
-
)
|
291 |
col1, col2, col3, col4, col5 = st.columns([2, 4, 2, 3, 2])
|
292 |
cols = [col1, col2, col3, col4, col5]
|
293 |
|
@@ -308,15 +323,15 @@ verified_df = parse_gg_sheet(VERIFIED_REQUESTS_URL)
|
|
308 |
verified_df = add_latlng_col(verified_df, process_column="Automatic Extracted Coordinates")
|
309 |
len_verified_requests = len(verified_df)
|
310 |
|
311 |
-
df["id"] = df.index
|
312 |
-
verified_df["id"] = verified_df.index
|
313 |
# keep rows with at least one request in selected_options
|
314 |
-
filtered_df = df[
|
315 |
-
lambda x: is_request_in_list(x, selected_options, options)
|
316 |
-
|
317 |
-
filtered_verified_df = verified_df[
|
318 |
-
lambda x: is_request_in_list(x, selected_options, options)
|
319 |
-
|
320 |
|
321 |
|
322 |
# Selection of interventions
|
@@ -340,14 +355,10 @@ fully_satisfied_villages = col_3.checkbox(
|
|
340 |
)
|
341 |
selected_village_types = []
|
342 |
if critical_villages:
|
343 |
-
selected_village_types.append(
|
344 |
-
"🚨 Critical, in urgent need of help / وضع حرج، في حاجة عاجلة للمساعدة"
|
345 |
-
)
|
346 |
|
347 |
if partially_satisfied_villages:
|
348 |
-
selected_village_types.append(
|
349 |
-
"⚠️ Partially served / مساعدة جزئية، بحاجة للمزيد من التدخلات"
|
350 |
-
)
|
351 |
|
352 |
if fully_satisfied_villages:
|
353 |
selected_village_types.append("✅ Fully served / تمت المساعدة بشكل كامل")
|
@@ -369,6 +380,17 @@ if show_unverified:
|
|
369 |
# Show verified requests
|
370 |
show_verified_requests(verified_df)
|
371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
st_folium(m, use_container_width=True, returned_objects=[], feature_group_to_add=fg, key="map")
|
373 |
|
374 |
# Embed code
|
@@ -476,9 +498,11 @@ drop_cols = [
|
|
476 |
"Intervention Date",
|
477 |
"Any remarks",
|
478 |
"VerificationStatus",
|
479 |
-
"Automatic Extracted Coordinates"
|
480 |
]
|
481 |
-
display_dataframe(
|
|
|
|
|
482 |
|
483 |
# Requests table
|
484 |
st.divider()
|
|
|
22 |
SLOGAN,
|
23 |
)
|
24 |
from src.utils import add_latlng_col, init_map, parse_gg_sheet, is_request_in_list, marker_request
|
25 |
+
from src.map_utils import get_legend_macro
|
26 |
|
27 |
TOKEN = os.environ.get("HF_TOKEN", None)
|
28 |
+
VERIFIED_REQUESTS_URL = (
|
29 |
+
"https://docs.google.com/spreadsheets/d/1PXcAtI5L95hHSXAiRl3Y4v5O4coG39S86OTfBEcvLTE/edit#gid=0"
|
30 |
+
)
|
31 |
REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
|
32 |
+
INTERVENTIONS_URL = (
|
33 |
+
"https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
|
34 |
+
)
|
35 |
api = HfApi(TOKEN)
|
36 |
|
37 |
|
|
|
51 |
|
52 |
auto_refresh = st.sidebar.checkbox("Auto Refresh?", st.session_state.auto_refresh)
|
53 |
if auto_refresh:
|
54 |
+
number = st.sidebar.number_input("Refresh rate in seconds", value=st.session_state.sleep_time)
|
|
|
|
|
55 |
st.session_state.sleep_time = number
|
56 |
|
57 |
|
|
|
61 |
global fg
|
62 |
for index, row in interventions_df.iterrows():
|
63 |
village_status = row[interventions_df.columns[7]]
|
64 |
+
is_future_intervention = (
|
65 |
+
row[interventions_df.columns[5]] == "Intervention prévue dans le futur / Planned future intervention"
|
66 |
+
)
|
67 |
|
68 |
if pd.isna(village_status) and not is_future_intervention:
|
69 |
village_status = "Partiellement satisfait / Partially Served"
|
|
|
74 |
if is_future_intervention:
|
75 |
color_mk = "pink"
|
76 |
status = "Planned ⌛"
|
77 |
+
elif village_status != "Critique, Besoin d'aide en urgence / Critical, in urgent need of help":
|
|
|
|
|
|
|
78 |
# past intervention and village not in a critical condition
|
79 |
color_mk = "green"
|
80 |
status = "Done ✅"
|
|
|
91 |
intervention_info = f"<b>Intervention Status:</b> {status}<br><b>Village Status:</b> {village_status}<br><b>Org:</b> {org}<br><b>Intervention:</b> {intervention_type}<br><b>Population:</b> {population}<br><b>📅 Date:</b> {date}"
|
92 |
if row["latlng"] is None:
|
93 |
continue
|
94 |
+
|
95 |
+
fg.add_child(
|
96 |
+
folium.Marker(
|
97 |
+
location=row["latlng"],
|
98 |
+
tooltip=city,
|
99 |
+
popup=folium.Popup(intervention_info, max_width=300),
|
100 |
+
icon=folium.Icon(color=color_mk),
|
101 |
+
)
|
102 |
+
)
|
103 |
|
104 |
|
105 |
def show_requests(filtered_df):
|
|
|
107 |
global fg
|
108 |
for index, row in filtered_df.iterrows():
|
109 |
request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
|
110 |
+
displayed_request = marker_request(request_type) # TODO: the marker should depend on selected_options
|
111 |
long_lat = row["latlng"]
|
112 |
maps_url = f"https://maps.google.com/?q={long_lat}"
|
113 |
# we display all requests in popup text and use the first one for the icon/color
|
|
|
116 |
if long_lat is None:
|
117 |
continue
|
118 |
|
119 |
+
fg.add_child(
|
120 |
+
folium.Marker(
|
121 |
+
location=long_lat,
|
122 |
+
tooltip=row[" لأي جماعة / قيادة / دوار تنتمون ؟"]
|
123 |
+
if not pd.isna(row[" لأي جماعة / قيادة / دوار تنتمون ؟"])
|
124 |
+
else None,
|
125 |
+
popup=folium.Popup(display_text, max_width=300),
|
126 |
+
icon=folium.Icon(
|
127 |
+
color=COLOR_MAPPING.get(displayed_request, "beige"), icon=icon_name, prefix="glyphicon"
|
128 |
+
),
|
129 |
+
)
|
130 |
+
)
|
131 |
+
|
132 |
|
133 |
def show_verified_requests(filtered_verified_df):
|
134 |
"""Display verified victim requests on the map"""
|
135 |
global fg
|
136 |
+
verified_color_mapping = {
|
137 |
+
"Low": "beige",
|
138 |
+
"Medium": "orange",
|
139 |
+
"High": "red",
|
140 |
+
}
|
141 |
for index, row in filtered_verified_df.iterrows():
|
|
|
|
|
142 |
long_lat = row["latlng"]
|
|
|
143 |
# we display all requests in popup text and use the first one for the icon/color
|
144 |
+
display_text = ""
|
145 |
+
for col, val in zip(filtered_verified_df.columns, row):
|
146 |
+
if col == "Help Details":
|
147 |
+
request_type = row["Help Details"]
|
148 |
+
marker_request(request_type) # TODO: the marker should depend on selected_options
|
149 |
+
display_text += f"<b>Request Type:</b> {request_type}<br>"
|
150 |
+
elif col == "Location Details":
|
151 |
+
display_text += f"<b>Location:</b> {val}<br>"
|
152 |
+
elif col == "Emergency Degree":
|
153 |
+
display_text += f"<b>Emergency Degree:</b> {val}<br>"
|
154 |
+
elif col == "Verification Date":
|
155 |
+
display_text += f"<b>Verification Date:</b> {val}<br>"
|
156 |
+
elif col == "id":
|
157 |
+
display_text = f"<b>Id:</b> {val}<br>" + display_text
|
158 |
+
elif col == "latlng":
|
159 |
+
maps_url = f"https://maps.google.com/?q={val}"
|
160 |
+
display_text += (
|
161 |
+
f'<a href="{maps_url}" target="_blank" rel="noopener noreferrer"><b>Google Maps</b></a><br>'
|
162 |
+
)
|
163 |
+
|
164 |
icon_name = ICON_MAPPING.get(request_type, "list")
|
165 |
+
emergency = row.get("Emergency Degree", "Low")
|
166 |
if long_lat is None:
|
167 |
continue
|
168 |
+
location = row["Location Details"]
|
169 |
+
fg.add_child(
|
170 |
+
folium.Marker(
|
171 |
+
location=long_lat,
|
172 |
+
tooltip=location if not pd.isna(location) else None,
|
173 |
+
popup=folium.Popup(display_text, max_width=300),
|
174 |
+
icon=folium.Icon(
|
175 |
+
color=verified_color_mapping.get(emergency, "beige"), icon=icon_name, prefix="glyphicon"
|
176 |
+
),
|
177 |
+
)
|
178 |
+
)
|
179 |
+
|
180 |
|
181 |
def display_google_sheet_tables(data_url):
|
182 |
"""Display the google sheet tables for requests and interventions"""
|
|
|
191 |
col_1, col_2 = st.columns([1, 1])
|
192 |
|
193 |
with col_1:
|
194 |
+
query = st.text_input("🔍 Search for information / بحث عن المعلومات", key=f"query_{uuid.uuid4()}")
|
|
|
|
|
|
|
195 |
with col_2:
|
196 |
if search_id:
|
197 |
id_number = st.number_input(
|
|
|
200 |
max_value=len(filtered_df),
|
201 |
value=0,
|
202 |
step=1,
|
203 |
+
key=f"id_{uuid.uuid4()}",
|
204 |
)
|
205 |
if status:
|
206 |
selected_status = st.selectbox(
|
207 |
+
"🗓️ Status / حالة", ["all / الكل", "Done / تم", "Planned / مخطط لها"], key=f"status_{uuid.uuid4()}"
|
|
|
|
|
208 |
)
|
209 |
|
210 |
if query:
|
|
|
222 |
if status:
|
223 |
target = "Pouvez-vous nous préciser si vous êtes déjà intervenus ou si vous prévoyez de le faire | Tell us if you already made the intervention, or if you're planning to do it"
|
224 |
if selected_status == "Done / تم":
|
225 |
+
display_df = display_df[display_df[target] == "Intervention déjà passée / Past intevention"]
|
|
|
|
|
226 |
|
227 |
elif selected_status == "Planned / مخطط لها":
|
228 |
+
display_df = display_df[display_df[target] != "Intervention déjà passée / Past intevention"]
|
|
|
|
|
229 |
|
230 |
st.dataframe(display_df, height=500)
|
231 |
# Original link to the Google Sheet
|
|
|
254 |
with st.expander("🔍 Review of requests | مراجعة طلب مساعدة"):
|
255 |
st.markdown(REVIEW_TEXT)
|
256 |
|
257 |
+
id_to_review = st.number_input("Enter id / أدخل الرقم", min_value=0, max_value=len(df), value=0, step=1)
|
|
|
|
|
258 |
reason_for_review = st.text_area("Explain why / أدخل سبب المراجعة")
|
259 |
if st.button("Submit / أرسل"):
|
260 |
if reason_for_review == "":
|
|
|
269 |
repo_id="nt3awnou/review_requests",
|
270 |
repo_type="dataset",
|
271 |
)
|
272 |
+
st.success("Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال")
|
|
|
|
|
273 |
|
274 |
|
275 |
# Logo and Title
|
|
|
302 |
value=True,
|
303 |
)
|
304 |
|
305 |
+
st.markdown("👉 **Choose request type | Choissisez le type de demande | اختر نوع الطلب**")
|
|
|
|
|
306 |
col1, col2, col3, col4, col5 = st.columns([2, 4, 2, 3, 2])
|
307 |
cols = [col1, col2, col3, col4, col5]
|
308 |
|
|
|
323 |
verified_df = add_latlng_col(verified_df, process_column="Automatic Extracted Coordinates")
|
324 |
len_verified_requests = len(verified_df)
|
325 |
|
326 |
+
df["id"] = df.index # Needed to display request id
|
327 |
+
verified_df["id"] = verified_df.index # Needed to display request id
|
328 |
# keep rows with at least one request in selected_options
|
329 |
+
filtered_df = df[
|
330 |
+
df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"].apply(lambda x: is_request_in_list(x, selected_options, options))
|
331 |
+
]
|
332 |
+
filtered_verified_df = verified_df[
|
333 |
+
verified_df["Help Details"].apply(lambda x: is_request_in_list(x, selected_options, options))
|
334 |
+
]
|
335 |
|
336 |
|
337 |
# Selection of interventions
|
|
|
355 |
)
|
356 |
selected_village_types = []
|
357 |
if critical_villages:
|
358 |
+
selected_village_types.append("🚨 Critical, in urgent need of help / وضع حرج، في حاجة عاجلة للمساعدة")
|
|
|
|
|
359 |
|
360 |
if partially_satisfied_villages:
|
361 |
+
selected_village_types.append("⚠️ Partially served / مساعدة جزئية، بحاجة للمزيد من التدخلات")
|
|
|
|
|
362 |
|
363 |
if fully_satisfied_villages:
|
364 |
selected_village_types.append("✅ Fully served / تمت المساعدة بشكل كامل")
|
|
|
380 |
# Show verified requests
|
381 |
show_verified_requests(verified_df)
|
382 |
|
383 |
+
# Add legend
|
384 |
+
legend_macro = get_legend_macro(show_unverified)
|
385 |
+
print(legend_macro)
|
386 |
+
# delete old legend
|
387 |
+
for child in m.get_root()._children:
|
388 |
+
pass
|
389 |
+
# if child.startswith("macro_element"):
|
390 |
+
# m.get_root()._children.remove(child)
|
391 |
+
m.get_root().add_child(legend_macro)
|
392 |
+
print(m.get_root()._children)
|
393 |
+
|
394 |
st_folium(m, use_container_width=True, returned_objects=[], feature_group_to_add=fg, key="map")
|
395 |
|
396 |
# Embed code
|
|
|
498 |
"Intervention Date",
|
499 |
"Any remarks",
|
500 |
"VerificationStatus",
|
501 |
+
"Automatic Extracted Coordinates",
|
502 |
]
|
503 |
+
display_dataframe(
|
504 |
+
verified_df, drop_cols, VERIFIED_REQUESTS_URL, search_id=True, for_help_requests=True, show_link=False
|
505 |
+
)
|
506 |
|
507 |
# Requests table
|
508 |
st.divider()
|
src/map_utils.py
CHANGED
@@ -1,7 +1,25 @@
|
|
1 |
from branca.element import Template, MacroElement
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
{% macro html(this, kwargs) %}
|
6 |
|
7 |
<!doctype html>
|
@@ -40,14 +58,9 @@ template = """
|
|
40 |
<div class='legend-title'>Legend / مفتاح الخريطة</div>
|
41 |
<div class='legend-scale'>
|
42 |
<ul class='legend-labels'>
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
<li><span style='background:#37A8DA;opacity:0.7;'></span>Food & Water / طعام وماء</li>
|
47 |
-
<li><span style='background:#575757;opacity:0.7;'></span>Danger / مخاطر (تسرب الغاز، تلف في الخدمات العامة...)</li>
|
48 |
-
<li><span style='background:#6EAA25;opacity:0.7;'></span>Done / تم</li>
|
49 |
-
<li><span style='background:#023020;opacity:0.7;'></span>Partial / تم جزئيا</li>
|
50 |
-
<li><span style='background:#FF91E8;opacity:0.7;'></span>Planned / مخطط لها</li>
|
51 |
</ul>
|
52 |
</div>
|
53 |
</div>
|
@@ -95,12 +108,14 @@ template = """
|
|
95 |
.maplegend a {
|
96 |
color: #777;
|
97 |
}
|
98 |
-
.leaflet-control-geocoder-form input {
|
99 |
-
color: #000;
|
100 |
-
}
|
101 |
</style>
|
102 |
{% endmacro %}"""
|
103 |
-
legend_macro = MacroElement()
|
104 |
-
legend_macro._template = Template(template)
|
105 |
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from branca.element import Template, MacroElement
|
2 |
|
3 |
+
labels_unverified_requests="""
|
4 |
+
<li><span style='background:#CE3C28;opacity:0.7;'></span>Rescue / إغاثة</li>
|
5 |
+
<li><span style='background:#ED922E;opacity:0.7;'></span>Medical Assistance / مساعدة طبية</li>
|
6 |
+
<li><span style='background:#FFCA92;opacity:0.7;'></span>Shelter / مأوى</li>
|
7 |
+
<li><span style='background:#37A8DA;opacity:0.7;'></span>Food & Water / طعام وماء</li>
|
8 |
+
<li><span style='background:#575757;opacity:0.7;'></span>Danger / مخاطر (تسرب الغاز، تلف في الخدمات العامة...)</li>
|
9 |
+
<li><span style='background:#6EAA25;opacity:0.7;'></span>Done / تم</li>
|
10 |
+
<li><span style='background:#023020;opacity:0.7;'></span>Partial / تم جزئيا</li>
|
11 |
+
<li><span style='background:#FF91E8;opacity:0.7;'></span>Planned / مخطط لها</li>
|
12 |
+
"""
|
13 |
+
labels_verified="""
|
14 |
+
<li><span style='background:#CE3C28;opacity:0.7;'></span>High Emergency / طوارئ عالية</li>
|
15 |
+
<li><span style='background:#ED922E;opacity:0.7;'></span>Medium Emergency / طوارئ متوسطة</li>
|
16 |
+
<li><span style='background:#FFCA92;opacity:0.7;'></span>Low Emergency / طوارئ منخفضة</li>
|
17 |
+
<li><span style='background:#6EAA25;opacity:0.7;'></span>Done / تم</li>
|
18 |
+
<li><span style='background:#023020;opacity:0.7;'></span>Partial / تم جزئيا</li>
|
19 |
+
<li><span style='background:#FF91E8;opacity:0.7;'></span>Planned / مخطط لها</li>
|
20 |
+
"""
|
21 |
|
22 |
+
template_1 = """
|
23 |
{% macro html(this, kwargs) %}
|
24 |
|
25 |
<!doctype html>
|
|
|
58 |
<div class='legend-title'>Legend / مفتاح الخريطة</div>
|
59 |
<div class='legend-scale'>
|
60 |
<ul class='legend-labels'>
|
61 |
+
|
62 |
+
"""
|
63 |
+
template_2 = """
|
|
|
|
|
|
|
|
|
|
|
64 |
</ul>
|
65 |
</div>
|
66 |
</div>
|
|
|
108 |
.maplegend a {
|
109 |
color: #777;
|
110 |
}
|
|
|
|
|
|
|
111 |
</style>
|
112 |
{% endmacro %}"""
|
|
|
|
|
113 |
|
114 |
+
def get_legend_macro(show_unverified):
|
115 |
+
print("show_unverified", show_unverified)
|
116 |
+
legend_macro = MacroElement()
|
117 |
+
legend_macro._template = Template(template_1 + (labels_unverified_requests if show_unverified else labels_verified) + template_2)
|
118 |
+
# legend_macro._template = Template(template_1 + (labels_unverified_requests) + template_2)
|
119 |
+
return legend_macro
|
120 |
+
|
121 |
+
__all__ = ["get_legend_macro"]
|
src/utils.py
CHANGED
@@ -3,7 +3,6 @@ from typing import Union
|
|
3 |
import folium
|
4 |
import pandas as pd
|
5 |
from folium import plugins
|
6 |
-
from src.map_utils import legend_macro
|
7 |
import streamlit as st
|
8 |
|
9 |
EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
|
@@ -172,6 +171,4 @@ def init_map():
|
|
172 |
strings={"title": "My location | موقعي", "popup": "My location | موقعي"},
|
173 |
).add_to(m)
|
174 |
|
175 |
-
# Macro to add legend
|
176 |
-
m.get_root().add_child(legend_macro)
|
177 |
return m
|
|
|
3 |
import folium
|
4 |
import pandas as pd
|
5 |
from folium import plugins
|
|
|
6 |
import streamlit as st
|
7 |
|
8 |
EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
|
|
|
171 |
strings={"title": "My location | موقعي", "popup": "My location | موقعي"},
|
172 |
).add_to(m)
|
173 |
|
|
|
|
|
174 |
return m
|