Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
ebc2ece
1
Parent(s):
15d58ea
update
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ 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,23 +38,23 @@ st.markdown("""
|
|
37 |
✉️ nt3awnou@annarabic.com المتطوعين ليبغاو يعاونوا يقدرو يتصلوا معنا عبر البريد
|
38 |
""")
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
def parse_gg_sheet_interventions(url):
|
43 |
df = pd.read_csv(url)
|
44 |
-
def parse_latlng_from_link(url):
|
45 |
-
try:
|
46 |
-
# extract latitude and longitude from gmaps link
|
47 |
-
session = requests.Session()
|
48 |
-
if "@" not in url:
|
49 |
-
# We first need to get the redirect URL
|
50 |
-
resp = session.head(url, allow_redirects=True)
|
51 |
-
url = resp.url
|
52 |
-
latlng = url.split('@')[1].split(',')[0:2]
|
53 |
-
return [float(latlng[0]), float(latlng[1])]
|
54 |
-
except Exception as e:
|
55 |
-
print(f"Error parsing latlng from link: {e}")
|
56 |
-
return None
|
57 |
return df.assign(latlng=df.iloc[:, 3].apply(parse_latlng_from_link))
|
58 |
|
59 |
def parse_gg_sheet(url):
|
@@ -163,6 +164,11 @@ for index, row in filtered_df.iterrows():
|
|
163 |
popup=folium.Popup(display_text, max_width=300),
|
164 |
icon=folium.Icon(color=colors_mapping.get(request_type, "blue"), icon=icon_name)
|
165 |
).add_to(m)
|
|
|
|
|
|
|
|
|
|
|
166 |
st_data = st_folium(m, use_container_width=True)
|
167 |
|
168 |
# Google Sheet Table
|
|
|
4 |
from streamlit_folium import st_folium
|
5 |
import time
|
6 |
import requests
|
7 |
+
from utils import legend_macro
|
8 |
|
9 |
st.set_page_config(layout="wide")
|
10 |
|
|
|
38 |
✉️ nt3awnou@annarabic.com المتطوعين ليبغاو يعاونوا يقدرو يتصلوا معنا عبر البريد
|
39 |
""")
|
40 |
|
41 |
+
session = requests.Session()
|
42 |
+
@st.cache_data(persist=True)
|
43 |
+
def parse_latlng_from_link(url):
|
44 |
+
try:
|
45 |
+
# extract latitude and longitude from gmaps link
|
46 |
+
if "@" not in url:
|
47 |
+
# We first need to get the redirect URL
|
48 |
+
resp = session.head(url, allow_redirects=True)
|
49 |
+
url = resp.url
|
50 |
+
latlng = url.split('@')[1].split(',')[0:2]
|
51 |
+
return [float(latlng[0]), float(latlng[1])]
|
52 |
+
except Exception as e:
|
53 |
+
print(f"Error parsing latlng from link: {e}")
|
54 |
+
return None
|
55 |
+
|
56 |
def parse_gg_sheet_interventions(url):
|
57 |
df = pd.read_csv(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
return df.assign(latlng=df.iloc[:, 3].apply(parse_latlng_from_link))
|
59 |
|
60 |
def parse_gg_sheet(url):
|
|
|
164 |
popup=folium.Popup(display_text, max_width=300),
|
165 |
icon=folium.Icon(color=colors_mapping.get(request_type, "blue"), icon=icon_name)
|
166 |
).add_to(m)
|
167 |
+
|
168 |
+
|
169 |
+
# Macro to add legend
|
170 |
+
m.get_root().add_child(legend_macro)
|
171 |
+
|
172 |
st_data = st_folium(m, use_container_width=True)
|
173 |
|
174 |
# Google Sheet Table
|
utils.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from branca.element import Template, MacroElement
|
2 |
+
|
3 |
+
|
4 |
+
template = """
|
5 |
+
{% macro html(this, kwargs) %}
|
6 |
+
|
7 |
+
<!doctype html>
|
8 |
+
<html lang="en">
|
9 |
+
<head>
|
10 |
+
<meta charset="utf-8">
|
11 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
12 |
+
<title>jQuery UI Draggable - Default functionality</title>
|
13 |
+
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
|
14 |
+
|
15 |
+
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
16 |
+
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
17 |
+
|
18 |
+
<script>
|
19 |
+
$( function() {
|
20 |
+
$( "#maplegend" ).draggable({
|
21 |
+
start: function (event, ui) {
|
22 |
+
$(this).css({
|
23 |
+
right: "auto",
|
24 |
+
top: "auto",
|
25 |
+
bottom: "auto"
|
26 |
+
});
|
27 |
+
}
|
28 |
+
});
|
29 |
+
});
|
30 |
+
|
31 |
+
</script>
|
32 |
+
</head>
|
33 |
+
<body>
|
34 |
+
|
35 |
+
|
36 |
+
<div id='maplegend' class='maplegend'
|
37 |
+
style='position: absolute; z-index:9999; border:2px solid grey; background-color:rgba(255, 255, 255, 0.8);
|
38 |
+
border-radius:6px; padding: 10px; font-size:14px; right: 20px; bottom: 20px;'>
|
39 |
+
|
40 |
+
<div class='legend-title'>Legend / مفتاح الخريطة</div>
|
41 |
+
<div class='legend-scale'>
|
42 |
+
<ul class='legend-labels'>
|
43 |
+
<li><span style='background:red;opacity:0.7;'></span>Rescue / إغاثة</li>
|
44 |
+
<li><span style='background:orange;opacity:0.7;'></span>Medical Assistance / مساعدة طبية</li>
|
45 |
+
<li><span style='background:yellow;opacity:0.7;'></span>Shelter / مأوى</li>
|
46 |
+
<li><span style='background:blue;opacity:0.7;'></span>Food & Water / طعام وماء</li>
|
47 |
+
<li><span style='background:grey;opacity:0.7;'></span>Danger / مخاطر (تسرب الغاز، تلف في الخدمات العامة...)</li>
|
48 |
+
<li><span style='background:green;opacity:0.7;'></span>Done / تم</li>
|
49 |
+
<li><span style='background:pink;opacity:0.7;'></span>Planned / مخطط لها</li>
|
50 |
+
</ul>
|
51 |
+
</div>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
</body>
|
55 |
+
</html>
|
56 |
+
|
57 |
+
<style type='text/css'>
|
58 |
+
.maplegend .legend-title {
|
59 |
+
text-align: left;
|
60 |
+
margin-bottom: 5px;
|
61 |
+
font-weight: bold;
|
62 |
+
font-size: 90%;
|
63 |
+
}
|
64 |
+
.maplegend .legend-scale ul {
|
65 |
+
margin: 0;
|
66 |
+
margin-bottom: 5px;
|
67 |
+
padding: 0;
|
68 |
+
float: left;
|
69 |
+
list-style: none;
|
70 |
+
}
|
71 |
+
.maplegend .legend-scale ul li {
|
72 |
+
font-size: 80%;
|
73 |
+
list-style: none;
|
74 |
+
margin-left: 0;
|
75 |
+
line-height: 18px;
|
76 |
+
margin-bottom: 2px;
|
77 |
+
}
|
78 |
+
.maplegend ul.legend-labels li span {
|
79 |
+
display: block;
|
80 |
+
float: left;
|
81 |
+
height: 16px;
|
82 |
+
width: 30px;
|
83 |
+
margin-right: 5px;
|
84 |
+
margin-left: 0;
|
85 |
+
border: 1px solid #999;
|
86 |
+
}
|
87 |
+
.maplegend .legend-source {
|
88 |
+
font-size: 80%;
|
89 |
+
color: #777;
|
90 |
+
clear: both;
|
91 |
+
}
|
92 |
+
.maplegend a {
|
93 |
+
color: #777;
|
94 |
+
}
|
95 |
+
</style>
|
96 |
+
{% endmacro %}"""
|
97 |
+
legend_macro = MacroElement()
|
98 |
+
legend_macro._template = Template(template)
|
99 |
+
|
100 |
+
__all__ = ["legend_macro"]
|