loubnabnl HF staff commited on
Commit
9150d37
1 Parent(s): 4d03435

fix issue in requests filtering (we didn't support multiple requests for the same entry)

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -20,7 +20,7 @@ from src.text_content import (
20
  REVIEW_TEXT,
21
  SLOGAN,
22
  )
23
- from src.utils import add_latlng_col, init_map, parse_gg_sheet
24
 
25
  TOKEN = os.environ.get("HF_TOKEN", None)
26
  REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
@@ -97,12 +97,14 @@ def show_requests(filtered_df):
97
  """Display victim requests on the map"""
98
  for index, row in filtered_df.iterrows():
99
  request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
 
100
  long_lat = row[
101
  "هل يمكنك تقديم الإحداثيات الدقيقة للموقع؟ (ادا كنت لا توجد بعين المكان) متلاً \n31.01837503440344, -6.781405948842175"
102
  ]
103
  maps_url = f"https://maps.google.com/?q={long_lat}"
 
104
  display_text = f'<b>Request Type:</b> {request_type}<br><b>Id:</b> {row["id"]}<br><a href="{maps_url}" target="_blank" rel="noopener noreferrer"><b>Google Maps</b></a>'
105
- icon_name = ICON_MAPPING.get(request_type, "info-sign")
106
  if row["latlng"] is None:
107
  continue
108
 
@@ -113,7 +115,7 @@ def show_requests(filtered_df):
113
  else None,
114
  popup=folium.Popup(display_text, max_width=300),
115
  icon=folium.Icon(
116
- color=COLOR_MAPPING.get(request_type, "blue"), icon=icon_name
117
  ),
118
  ))
119
 
@@ -258,8 +260,11 @@ for i, option in enumerate(options):
258
  selected_options.append(option)
259
 
260
  df["id"] = df.index
261
- filtered_df = df[df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"].isin(selected_options)]
262
- selected_headers = [HEADERS_MAPPING[request] for request in selected_options]
 
 
 
263
 
264
  # Selection of interventions
265
  show_interventions = st.checkbox(
@@ -268,7 +273,6 @@ show_interventions = st.checkbox(
268
  )
269
 
270
  # Categories of villages
271
-
272
  st.markdown(
273
  "👉 **State of villages visited by NGOs| Etat de villages visités par les ONGs | وضعية القرى التي زارتها الجمعيات**",
274
  unsafe_allow_html=True,
 
20
  REVIEW_TEXT,
21
  SLOGAN,
22
  )
23
+ from src.utils import add_latlng_col, init_map, parse_gg_sheet, is_request_in_list, marker_request
24
 
25
  TOKEN = os.environ.get("HF_TOKEN", None)
26
  REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
 
97
  """Display victim requests on the map"""
98
  for index, row in filtered_df.iterrows():
99
  request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
100
+ displayed_request = marker_request(request_type)
101
  long_lat = row[
102
  "هل يمكنك تقديم الإحداثيات الدقيقة للموقع؟ (ادا كنت لا توجد بعين المكان) متلاً \n31.01837503440344, -6.781405948842175"
103
  ]
104
  maps_url = f"https://maps.google.com/?q={long_lat}"
105
+ # we display all requests in popup text and use the first one for the icon/color
106
  display_text = f'<b>Request Type:</b> {request_type}<br><b>Id:</b> {row["id"]}<br><a href="{maps_url}" target="_blank" rel="noopener noreferrer"><b>Google Maps</b></a>'
107
+ icon_name = ICON_MAPPING.get(displayed_request, "info-sign")
108
  if row["latlng"] is None:
109
  continue
110
 
 
115
  else None,
116
  popup=folium.Popup(display_text, max_width=300),
117
  icon=folium.Icon(
118
+ color=COLOR_MAPPING.get(displayed_request, "blue"), icon=icon_name
119
  ),
120
  ))
121
 
 
260
  selected_options.append(option)
261
 
262
  df["id"] = df.index
263
+ # keep rows with at least one request in selected_options
264
+ filtered_df = df[df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"].apply(
265
+ lambda x: is_request_in_list(x, selected_options)
266
+ )]
267
+
268
 
269
  # Selection of interventions
270
  show_interventions = st.checkbox(
 
273
  )
274
 
275
  # Categories of villages
 
276
  st.markdown(
277
  "👉 **State of villages visited by NGOs| Etat de villages visités par les ONGs | وضعية القرى التي زارتها الجمعيات**",
278
  unsafe_allow_html=True,