nouamanetazi HF staff commited on
Commit
d2eac8a
1 Parent(s): c72f674

add NGOs data to map

Browse files
Files changed (2) hide show
  1. app.py +5 -8
  2. src/utils.py +8 -2
app.py CHANGED
@@ -55,6 +55,8 @@ def display_interventions(interventions_df):
55
  """Display NGO interventions on the map"""
56
  for index, row in interventions_df.iterrows():
57
  village_status = row[interventions_df.columns[7]]
 
 
58
  if (
59
  row[interventions_df.columns[5]]
60
  == "Intervention prévue dans le futur / Planned future intervention"
@@ -76,12 +78,12 @@ def display_interventions(interventions_df):
76
  color_mk = "darkgreen"
77
  status = "Partial ⚠️"
78
 
79
- intervention_type = row[interventions_df.columns[6]].split("/")[0].strip()
80
  org = row[interventions_df.columns[1]]
81
  city = row[interventions_df.columns[9]]
82
  date = row[interventions_df.columns[4]]
83
  population = row[interventions_df.columns[11]]
84
- intervention_info = f"<b>Intervention Status:</b> {status}<br><b>Village Status:</b> {village_status.split('/')[0]}<br><b>Org:</b> {org}<br><b>Intervention:</b> {intervention_type}<br><b>Population:</b> {population}<br><b>📅 Date:</b> {date}"
85
  if row["latlng"] is None:
86
  continue
87
 
@@ -234,7 +236,7 @@ df = parse_gg_sheet(REQUESTS_URL)
234
  df = add_latlng_col(df, process_column=15)
235
  len_requests = len(df)
236
  interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
237
- interventions_df = add_latlng_col(interventions_df, process_column=12)
238
  len_interventions = len(interventions_df)
239
  m = init_map()
240
  fg = folium.FeatureGroup(name="Markers")
@@ -320,11 +322,6 @@ status_mapping = {
320
  selected_statuses = [status_mapping[status] for status in selected_village_types]
321
 
322
  if show_interventions:
323
- interventions_df = interventions_df.loc[
324
- interventions_df[
325
- "Etat de la région actuel | Current situation of the area "
326
- ].isin(selected_statuses)
327
- ]
328
  display_interventions(interventions_df)
329
 
330
  # Show requests
 
55
  """Display NGO interventions on the map"""
56
  for index, row in interventions_df.iterrows():
57
  village_status = row[interventions_df.columns[7]]
58
+ if pd.isna(village_status):
59
+ village_status = "Partiellement satisfait / Partially Served"
60
  if (
61
  row[interventions_df.columns[5]]
62
  == "Intervention prévue dans le futur / Planned future intervention"
 
78
  color_mk = "darkgreen"
79
  status = "Partial ⚠️"
80
 
81
+ intervention_type = row[interventions_df.columns[6]]
82
  org = row[interventions_df.columns[1]]
83
  city = row[interventions_df.columns[9]]
84
  date = row[interventions_df.columns[4]]
85
  population = row[interventions_df.columns[11]]
86
+ 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}"
87
  if row["latlng"] is None:
88
  continue
89
 
 
236
  df = add_latlng_col(df, process_column=15)
237
  len_requests = len(df)
238
  interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
239
+ interventions_df = add_latlng_col(interventions_df, process_column="Automatic Extracted Coordinates")
240
  len_interventions = len(interventions_df)
241
  m = init_map()
242
  fg = folium.FeatureGroup(name="Markers")
 
322
  selected_statuses = [status_mapping[status] for status in selected_village_types]
323
 
324
  if show_interventions:
 
 
 
 
 
325
  display_interventions(interventions_df)
326
 
327
  # Show requests
src/utils.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import folium
2
  import pandas as pd
3
  from folium import plugins
@@ -40,9 +41,14 @@ def marker_request(request):
40
  return displayed_request
41
 
42
 
43
- def add_latlng_col(df, process_column):
44
  """Add a latlng column to the dataframe"""
45
- df = df.assign(latlng=df.iloc[:, process_column].apply(parse_latlng))
 
 
 
 
 
46
  return df
47
 
48
  # parse latlng (column 4) to [lat, lng]
 
1
+ from typing import Union
2
  import folium
3
  import pandas as pd
4
  from folium import plugins
 
41
  return displayed_request
42
 
43
 
44
+ def add_latlng_col(df, process_column: Union[str, int]):
45
  """Add a latlng column to the dataframe"""
46
+ if isinstance(process_column, str):
47
+ df["latlng"] = df[process_column].apply(parse_latlng)
48
+ elif isinstance(process_column, int):
49
+ df["latlng"] = df.iloc[:, process_column].apply(parse_latlng)
50
+ else:
51
+ raise ValueError(f"process_column should be a string or an integer, got {type(process_column)}")
52
  return df
53
 
54
  # parse latlng (column 4) to [lat, lng]