Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
add interventions & change icons
#5
by
loubnabnl
HF staff
- opened
app.py
CHANGED
@@ -3,6 +3,7 @@ import streamlit as st
|
|
3 |
import pandas as pd
|
4 |
from streamlit_folium import st_folium
|
5 |
import time
|
|
|
6 |
|
7 |
st.set_page_config(layout="wide")
|
8 |
|
@@ -36,6 +37,20 @@ st.markdown("""
|
|
36 |
✉️ nt3awnou@annarabic.com المتطوعين ليبغاو يعاونوا يقدرو يتصلوا معنا عبر البريد
|
37 |
""")
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
def parse_gg_sheet(url):
|
41 |
url = url.replace("edit#gid=", "export?format=csv&gid=")
|
@@ -51,12 +66,14 @@ def parse_gg_sheet(url):
|
|
51 |
|
52 |
return df.assign(latlng=df.iloc[:, 4].apply(parse_latlng))
|
53 |
|
54 |
-
|
55 |
df = parse_gg_sheet(
|
56 |
"https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
|
57 |
)
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
headers_mapping = {
|
61 |
"إغاثة": "Rescue/إغاثة",
|
62 |
"مساعدة طبية": "Medical Assistance/مساعدة طبية",
|
@@ -71,6 +88,14 @@ colors_mapping = {
|
|
71 |
"طعام وماء": "blue",
|
72 |
"مخاطر (تسرب الغاز، تلف في الخدمات العامة...)": "grey",
|
73 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
options = ["إغاثة", "مساعدة طبية", "مأوى", "طعام وماء", "مخاطر (تسرب الغاز، تلف في الخدمات العامة...)"]
|
75 |
selected_options = []
|
76 |
|
@@ -87,7 +112,10 @@ arabic_options = [e.split("/")[1] for e in selected_options]
|
|
87 |
df['id'] = df.index
|
88 |
filtered_df = df[df['ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)'].isin(arabic_options)]
|
89 |
selected_headers = [headers_mapping[request] for request in arabic_options]
|
90 |
-
|
|
|
|
|
|
|
91 |
|
92 |
m = folium.Map(
|
93 |
location=[31.628674, -7.992047],
|
@@ -100,14 +128,27 @@ m = folium.Map(
|
|
100 |
max_bounds=True,
|
101 |
)
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
for index, row in filtered_df.iterrows():
|
105 |
request_type = row['ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)']
|
106 |
-
#phone = row["رقم الهاتف (اختياري)"] if not pd.isna(row["رقم الهاتف (اختياري)"]) else ""
|
107 |
-
|
108 |
-
# Formatted text using HTML
|
109 |
display_text = f"<b>Request Type:</b> {request_type}<br><b>Id:</b> {row['id']}"
|
110 |
-
|
111 |
if row["latlng"] is None:
|
112 |
continue
|
113 |
|
@@ -115,7 +156,7 @@ for index, row in filtered_df.iterrows():
|
|
115 |
location=row["latlng"],
|
116 |
tooltip=row[' لأي جماعة / قيادة / دوار تنتمون ؟'] if not pd.isna(row[' لأي جماعة / قيادة / دوار تنتمون ؟']) else None,
|
117 |
popup=folium.Popup(display_text, max_width=300),
|
118 |
-
icon=folium.Icon(color=colors_mapping.get(request_type, "blue"))
|
119 |
).add_to(m)
|
120 |
st_data = st_folium(m, use_container_width=True)
|
121 |
|
@@ -147,7 +188,6 @@ st.markdown(
|
|
147 |
""",
|
148 |
unsafe_allow_html=True,
|
149 |
)
|
150 |
-
|
151 |
if auto_refresh:
|
152 |
time.sleep(number)
|
153 |
st.experimental_rerun()
|
|
|
3 |
import pandas as pd
|
4 |
from streamlit_folium import st_folium
|
5 |
import time
|
6 |
+
import requests
|
7 |
|
8 |
st.set_page_config(layout="wide")
|
9 |
|
|
|
37 |
✉️ nt3awnou@annarabic.com المتطوعين ليبغاو يعاونوا يقدرو يتصلوا معنا عبر البريد
|
38 |
""")
|
39 |
|
40 |
+
def parse_latlng_from_link(url):
|
41 |
+
# extract latitude and longitude from gmaps link
|
42 |
+
session = requests.Session()
|
43 |
+
if "@" not in url:
|
44 |
+
# We first need to get the redirect URL
|
45 |
+
resp = session.head(url, allow_redirects=True)
|
46 |
+
url = resp.url
|
47 |
+
latlng = url.split('@')[1].split(',')[0:2]
|
48 |
+
return [float(latlng[0]), float(latlng[1])]
|
49 |
+
|
50 |
+
|
51 |
+
def parse_gg_sheet_interventions(url):
|
52 |
+
df = pd.read_csv(url)
|
53 |
+
return df.assign(latlng=df.iloc[:, 3].apply(parse_latlng_from_link))
|
54 |
|
55 |
def parse_gg_sheet(url):
|
56 |
url = url.replace("edit#gid=", "export?format=csv&gid=")
|
|
|
66 |
|
67 |
return df.assign(latlng=df.iloc[:, 4].apply(parse_latlng))
|
68 |
|
|
|
69 |
df = parse_gg_sheet(
|
70 |
"https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
|
71 |
)
|
72 |
+
interventions_df = parse_gg_sheet_interventions(
|
73 |
+
"https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/gviz/tq?tqx=out:csv"
|
74 |
+
)
|
75 |
|
76 |
+
# select requests
|
77 |
headers_mapping = {
|
78 |
"إغاثة": "Rescue/إغاثة",
|
79 |
"مساعدة طبية": "Medical Assistance/مساعدة طبية",
|
|
|
88 |
"طعام وماء": "blue",
|
89 |
"مخاطر (تسرب الغاز، تلف في الخدمات العامة...)": "grey",
|
90 |
}
|
91 |
+
icon_mapping = {
|
92 |
+
"إغاثة": "bell", # life ring icon for rescue
|
93 |
+
"مساعدة طبية": "heart", # medical kit for medical assistance
|
94 |
+
"مأوى": "home", # home icon for shelter
|
95 |
+
"طعام وماء": "cutlery", # cutlery (fork and knife) for food & water
|
96 |
+
"مخاطر (تسرب الغاز، تلف في الخدمات العامة...)": "Warning" # warning triangle for dangers
|
97 |
+
}
|
98 |
+
|
99 |
options = ["إغاثة", "مساعدة طبية", "مأوى", "طعام وماء", "مخاطر (تسرب الغاز، تلف في الخدمات العامة...)"]
|
100 |
selected_options = []
|
101 |
|
|
|
112 |
df['id'] = df.index
|
113 |
filtered_df = df[df['ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)'].isin(arabic_options)]
|
114 |
selected_headers = [headers_mapping[request] for request in arabic_options]
|
115 |
+
|
116 |
+
# select interventions
|
117 |
+
st.markdown("👇 **View past or planned interventions / عرض عمليات المساعدة السابقة أو المخطط لها**")
|
118 |
+
show_interventions = st.checkbox("Display Interventions عرض التدخلات")
|
119 |
|
120 |
m = folium.Map(
|
121 |
location=[31.628674, -7.992047],
|
|
|
128 |
max_bounds=True,
|
129 |
)
|
130 |
|
131 |
+
if show_interventions:
|
132 |
+
for index, row in interventions_df.iterrows():
|
133 |
+
status = "Done ✅" if row[interventions_df.columns[5]]=="Intervention prévue dans le futur / Planned future intervention" else "Planned ⌛"
|
134 |
+
color_mk = "green" if row[interventions_df.columns[5]]=="Intervention prévue dans le futur / Planned future intervention" else "pink"
|
135 |
+
intervention_type = row[interventions_df.columns[6]].split("/")[0].strip()
|
136 |
+
org = row[interventions_df.columns[1]]
|
137 |
+
city = row[interventions_df.columns[9]]
|
138 |
+
date = row[interventions_df.columns[4]]
|
139 |
+
intervention_info = f"<b>Status:</b> {status}<br><b>Org:</b> {org}<br><b>Intervention:</b> {intervention_type}<br><b>📅 Date:</b> {date}"
|
140 |
+
print(f"intervention_info: {intervention_info}")
|
141 |
+
folium.Marker(
|
142 |
+
location=row["latlng"],
|
143 |
+
tooltip=city,
|
144 |
+
popup=folium.Popup(intervention_info, max_width=300),
|
145 |
+
icon=folium.Icon(color=color_mk)
|
146 |
+
).add_to(m)
|
147 |
|
148 |
for index, row in filtered_df.iterrows():
|
149 |
request_type = row['ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)']
|
|
|
|
|
|
|
150 |
display_text = f"<b>Request Type:</b> {request_type}<br><b>Id:</b> {row['id']}"
|
151 |
+
icon_name = icon_mapping.get(request_type, 'info-sign')
|
152 |
if row["latlng"] is None:
|
153 |
continue
|
154 |
|
|
|
156 |
location=row["latlng"],
|
157 |
tooltip=row[' لأي جماعة / قيادة / دوار تنتمون ؟'] if not pd.isna(row[' لأي جماعة / قيادة / دوار تنتمون ؟']) else None,
|
158 |
popup=folium.Popup(display_text, max_width=300),
|
159 |
+
icon=folium.Icon(color=colors_mapping.get(request_type, "blue"), icon=icon_name)
|
160 |
).add_to(m)
|
161 |
st_data = st_folium(m, use_container_width=True)
|
162 |
|
|
|
188 |
""",
|
189 |
unsafe_allow_html=True,
|
190 |
)
|
|
|
191 |
if auto_refresh:
|
192 |
time.sleep(number)
|
193 |
st.experimental_rerun()
|