Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
BounharAbdelaziz
commited on
Commit
•
35814d4
1
Parent(s):
ec5ae8b
Added map layer of electricity need (level) in each douar
Browse files- src/utils.py +33 -0
src/utils.py
CHANGED
@@ -8,6 +8,8 @@ import streamlit as st
|
|
8 |
EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
|
9 |
BORDER_COLOR = "black"
|
10 |
DOUARS_URL = "data/regions.json"
|
|
|
|
|
11 |
|
12 |
# @st.cache_resource
|
13 |
def parse_gg_sheet(url):
|
@@ -22,6 +24,8 @@ def parse_json_file(url):
|
|
22 |
return df
|
23 |
|
24 |
douar_df = parse_json_file(DOUARS_URL)
|
|
|
|
|
25 |
|
26 |
def is_request_in_list(request, selection_list, options):
|
27 |
if isinstance(request, float): # Check if the input is a float (like NaN)
|
@@ -145,6 +149,31 @@ def add_village_names(douar_df, map_obj):
|
|
145 |
opacity = 0.7
|
146 |
).add_to(village_fgroup)
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
def init_map():
|
150 |
m = folium.Map(
|
@@ -187,7 +216,11 @@ def init_map():
|
|
187 |
# Add danger zones
|
188 |
add_epicentre_to_map(m)
|
189 |
add_danger_distances_to_map(m)
|
|
|
190 |
add_village_names(douar_df, m)
|
|
|
|
|
|
|
191 |
|
192 |
# Add a LayerControl to the map to toggle between layers (Satellite View and Default One)
|
193 |
folium.LayerControl().add_to(m)
|
|
|
8 |
EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
|
9 |
BORDER_COLOR = "black"
|
10 |
DOUARS_URL = "data/regions.json"
|
11 |
+
DATA_IMPORTANT_ELECTRICITY_PATH = "data/Besoin important en électricité.csv"
|
12 |
+
DATA_MOINS_IMPORTANT_ELECTRICITY_PATH = "data/Besoin moins important en électricité.csv"
|
13 |
|
14 |
# @st.cache_resource
|
15 |
def parse_gg_sheet(url):
|
|
|
24 |
return df
|
25 |
|
26 |
douar_df = parse_json_file(DOUARS_URL)
|
27 |
+
df_important = pd.read_csv(DATA_IMPORTANT_ELECTRICITY_PATH)
|
28 |
+
df_moins_important = pd.read_csv(DATA_MOINS_IMPORTANT_ELECTRICITY_PATH)
|
29 |
|
30 |
def is_request_in_list(request, selection_list, options):
|
31 |
if isinstance(request, float): # Check if the input is a float (like NaN)
|
|
|
149 |
opacity = 0.7
|
150 |
).add_to(village_fgroup)
|
151 |
|
152 |
+
def add_electricity_needs(electricity_need_df, map_obj, high_need=False):
|
153 |
+
if high_need:
|
154 |
+
hex_color = "#fc0303"
|
155 |
+
electricity_fgroup = folium.FeatureGroup(name='High electricity need / Besoin en électricité élevé/ في حاجة كبيرة للكهرباء', show=False).add_to(map_obj)
|
156 |
+
else:
|
157 |
+
hex_color = "#fc7303"
|
158 |
+
electricity_fgroup = folium.FeatureGroup(name='Medium electricity need / Besoin en électricité moyen / حاجة متوسطة للكهرباء', show=False).add_to(map_obj)
|
159 |
+
|
160 |
+
for _, row in electricity_need_df.iterrows():
|
161 |
+
lat = row['Latitude']
|
162 |
+
lng = row['Longitude']
|
163 |
+
lat_lng = (lat, lng)
|
164 |
+
dour_name = str(row['Name']).capitalize()
|
165 |
+
maps_url = f"https://maps.google.com/?q={lat_lng}"
|
166 |
+
display_text = f'<br><b>⛰️ Douar:</b> {dour_name}<br><a href="{maps_url}" target="_blank" rel="noopener noreferrer"><b>🧭 Google Maps</b></a>'
|
167 |
+
|
168 |
+
folium.CircleMarker(
|
169 |
+
location=[lat, lng],
|
170 |
+
radius=0.1,
|
171 |
+
tooltip = dour_name, # we might remove the tooltip to avoid crowding the map
|
172 |
+
popup=folium.Popup(display_text, max_width=200),
|
173 |
+
color=hex_color,
|
174 |
+
opacity = 0.7
|
175 |
+
).add_to(electricity_fgroup)
|
176 |
+
|
177 |
|
178 |
def init_map():
|
179 |
m = folium.Map(
|
|
|
216 |
# Add danger zones
|
217 |
add_epicentre_to_map(m)
|
218 |
add_danger_distances_to_map(m)
|
219 |
+
# Add Douars names
|
220 |
add_village_names(douar_df, m)
|
221 |
+
# Add Electricity needs
|
222 |
+
add_electricity_needs(df_important, m, high_need=True)
|
223 |
+
add_electricity_needs(df_moins_important, m, high_need=False)
|
224 |
|
225 |
# Add a LayerControl to the map to toggle between layers (Satellite View and Default One)
|
226 |
folium.LayerControl().add_to(m)
|