nouamanetazi HF staff commited on
Commit
0188ddf
1 Parent(s): df311b6

show interventions

Browse files
Files changed (2) hide show
  1. app.py +64 -5
  2. src/utils.py +2 -4
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, is_request_in_list, marker_request
24
  from src.map_utils import get_legend_macro
25
 
26
  TOKEN = os.environ.get("HF_TOKEN", None)
@@ -31,6 +31,7 @@ REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fO
31
  INTERVENTIONS_URL = (
32
  "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
33
  )
 
34
  api = HfApi(TOKEN)
35
 
36
 
@@ -90,7 +91,6 @@ def display_interventions(interventions_df, selected_statuses):
90
  population = row[interventions_df.columns[11]]
91
  details = row[interventions_df.columns[8]]
92
  road_state = row[interventions_df.columns[12]]
93
- # 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}"
94
  intervention_info = f"""
95
  <b>Date:</b> {date}<br>
96
  <b>City:</b> {city}<br>
@@ -116,6 +116,57 @@ def display_interventions(interventions_df, selected_statuses):
116
  )
117
  )
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  def show_requests(filtered_df):
121
  """Display victim requests on the map"""
@@ -351,13 +402,20 @@ for i, option in enumerate(options):
351
  df = parse_gg_sheet(REQUESTS_URL)
352
  if show_unverified:
353
  df = add_latlng_col(df, process_column=15)
354
- len_requests = len(df)
355
  interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
356
  interventions_df = add_latlng_col(interventions_df, process_column="Automatic Extracted Coordinates")
357
- len_interventions = len(interventions_df)
358
  verified_df = parse_gg_sheet(VERIFIED_REQUESTS_URL)
359
  verified_df = add_latlng_col(verified_df, process_column="Automatic Extracted Coordinates")
 
 
 
 
 
 
 
 
360
  len_verified_requests = len(verified_df)
 
361
 
362
  df["id"] = df.index # Needed to display request id
363
  verified_df["id"] = verified_df.index # Needed to display request id
@@ -408,6 +466,7 @@ selected_statuses = [status_mapping[status] for status in selected_village_types
408
 
409
  if show_interventions:
410
  display_interventions(interventions_df, selected_statuses)
 
411
 
412
  # Show requests
413
  if show_unverified:
@@ -424,7 +483,7 @@ for child in m.get_root()._children:
424
  # if child.startswith("macro_element"):
425
  # m.get_root()._children.remove(child)
426
  m.get_root().add_child(legend_macro)
427
-
428
  st_folium(m, use_container_width=True, returned_objects=[], feature_group_to_add=fg, key="map")
429
 
430
  # Embed code
 
20
  REVIEW_TEXT,
21
  SLOGAN,
22
  )
23
+ from src.utils import add_latlng_col, add_village_names, init_map, parse_gg_sheet, is_request_in_list, marker_request, parse_json_file
24
  from src.map_utils import get_legend_macro
25
 
26
  TOKEN = os.environ.get("HF_TOKEN", None)
 
31
  INTERVENTIONS_URL = (
32
  "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
33
  )
34
+ DOUARS_URL = "data/regions.json"
35
  api = HfApi(TOKEN)
36
 
37
 
 
91
  population = row[interventions_df.columns[11]]
92
  details = row[interventions_df.columns[8]]
93
  road_state = row[interventions_df.columns[12]]
 
94
  intervention_info = f"""
95
  <b>Date:</b> {date}<br>
96
  <b>City:</b> {city}<br>
 
116
  )
117
  )
118
 
119
+ def display_solved(solved_verified_requests, selected_statuses):
120
+ # Index(['VerificationStatus', 'Verification Date', 'Help Details',
121
+ # 'Further details', 'Phone Number', 'Location Details',
122
+ # 'Emergency Degree', 'Location Link/GPS Coordinates', 'Status',
123
+ # 'Intervenant ', 'Intervention Date', 'Any remarks',
124
+ # 'Automatic Extracted Coordinates'],
125
+ # dtype='object')
126
+
127
+ global fg
128
+ for index, row in solved_verified_requests.iterrows():
129
+ if row["latlng"] is None:
130
+ continue
131
+ intervention_status = row[solved_verified_requests.columns[8]]
132
+ is_future_intervention = (
133
+ intervention_status == "Planned"
134
+ )
135
+
136
+ if is_future_intervention:
137
+ status = "Planned ⌛"
138
+ icon = folium.Icon(icon="heart", prefix="glyphicon", color="pink", icon_color="red")
139
+ else:
140
+ status = "Done ✅"
141
+ icon = folium.Icon(icon="heart", prefix="glyphicon", color="darkgreen", icon_color="red")
142
+ # if village_status not in selected_statuses:
143
+ # continue # TODO: enable filters
144
+ intervention_type = row[solved_verified_requests.columns[2]]
145
+ details = row[solved_verified_requests.columns[3]]
146
+ contact = row[solved_verified_requests.columns[4]]
147
+ location = row[solved_verified_requests.columns[5]]
148
+ org = row[solved_verified_requests.columns[9]]
149
+ intervention_date = row[solved_verified_requests.columns[10]]
150
+ remarks = row[solved_verified_requests.columns[11]]
151
+ intervention_info = f"""
152
+ <b>Intervention Date:</b> {intervention_date}<br>
153
+ <b>Org:</b> {org}<br>
154
+ <b>Intervention:</b> {intervention_type}<br>
155
+ <b>Invervention Status:</b> {status}<br>
156
+ <b>Details:</b> {details}<br>
157
+ <b>Location:</b> {location}<br>
158
+ <b>Remarks:</b> {remarks}<br>
159
+ <b>Contact:</b> {contact}<br>
160
+ """
161
+ # golden color
162
+ fg.add_child(
163
+ folium.Marker(
164
+ location=row["latlng"],
165
+ tooltip=location,
166
+ popup=folium.Popup(intervention_info, max_width=300),
167
+ icon=icon
168
+ )
169
+ )
170
 
171
  def show_requests(filtered_df):
172
  """Display victim requests on the map"""
 
402
  df = parse_gg_sheet(REQUESTS_URL)
403
  if show_unverified:
404
  df = add_latlng_col(df, process_column=15)
 
405
  interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
406
  interventions_df = add_latlng_col(interventions_df, process_column="Automatic Extracted Coordinates")
 
407
  verified_df = parse_gg_sheet(VERIFIED_REQUESTS_URL)
408
  verified_df = add_latlng_col(verified_df, process_column="Automatic Extracted Coordinates")
409
+ douar_df = parse_json_file(DOUARS_URL)
410
+
411
+ # check if verified requests have been solved
412
+ solved_verified_requests = verified_df[~pd.isnull(verified_df["Status"])]
413
+ verified_df = verified_df[pd.isnull(verified_df["Status"])]
414
+
415
+ len_requests = len(df)
416
+ len_interventions = len(interventions_df)
417
  len_verified_requests = len(verified_df)
418
+ len_solved_verified_requests = len(solved_verified_requests)
419
 
420
  df["id"] = df.index # Needed to display request id
421
  verified_df["id"] = verified_df.index # Needed to display request id
 
466
 
467
  if show_interventions:
468
  display_interventions(interventions_df, selected_statuses)
469
+ display_solved(solved_verified_requests, selected_statuses)
470
 
471
  # Show requests
472
  if show_unverified:
 
483
  # if child.startswith("macro_element"):
484
  # m.get_root()._children.remove(child)
485
  m.get_root().add_child(legend_macro)
486
+ # add_village_names(douar_df, m)
487
  st_folium(m, use_container_width=True, returned_objects=[], feature_group_to_add=fg, key="map")
488
 
489
  # Embed code
src/utils.py CHANGED
@@ -3,10 +3,10 @@ from typing import Union
3
  import folium
4
  import pandas as pd
5
  from folium import plugins
 
6
 
7
  EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
8
  BORDER_COLOR = "black"
9
- DOUARS_URL = "data/regions.json"
10
 
11
  # @st.cache_resource
12
  def parse_gg_sheet(url):
@@ -15,13 +15,12 @@ def parse_gg_sheet(url):
15
  df = pd.read_csv(url, on_bad_lines="warn")
16
  return df
17
 
 
18
  def parse_json_file(url):
19
  df = pd.read_json(url)
20
  df = pd.json_normalize(df.douars)
21
  return df
22
 
23
- douar_df = parse_json_file(DOUARS_URL)
24
-
25
  def is_request_in_list(request, selection_list, options):
26
  if isinstance(request, float): # Check if the input is a float (like NaN)
27
  return False
@@ -186,7 +185,6 @@ def init_map():
186
  # Add danger zones
187
  add_epicentre_to_map(m)
188
  add_danger_distances_to_map(m)
189
- add_village_names(douar_df, m)
190
 
191
  # Add a LayerControl to the map to toggle between layers (Satellite View and Default One)
192
  folium.LayerControl().add_to(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]
9
  BORDER_COLOR = "black"
 
10
 
11
  # @st.cache_resource
12
  def parse_gg_sheet(url):
 
15
  df = pd.read_csv(url, on_bad_lines="warn")
16
  return df
17
 
18
+ @st.cache_resource
19
  def parse_json_file(url):
20
  df = pd.read_json(url)
21
  df = pd.json_normalize(df.douars)
22
  return df
23
 
 
 
24
  def is_request_in_list(request, selection_list, options):
25
  if isinstance(request, float): # Check if the input is a float (like NaN)
26
  return False
 
185
  # Add danger zones
186
  add_epicentre_to_map(m)
187
  add_danger_distances_to_map(m)
 
188
 
189
  # Add a LayerControl to the map to toggle between layers (Satellite View and Default One)
190
  folium.LayerControl().add_to(m)