Spaces:
Running
Running
Commit Β·
2901e2c
1
Parent(s): 0f3999b
map improve
Browse files
app.py
CHANGED
|
@@ -31,27 +31,35 @@ print(f"Ready. {len(sample_agents)} agents loaded.")
|
|
| 31 |
|
| 32 |
# ββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 33 |
def build_map(agent_sp):
|
|
|
|
| 34 |
lat = agent_sp["latitude"].mean()
|
| 35 |
lon = agent_sp["longitude"].mean()
|
| 36 |
m = folium.Map(location=[lat, lon], zoom_start=12, tiles="CartoDB positron")
|
| 37 |
|
|
|
|
| 38 |
coords = list(zip(agent_sp["latitude"], agent_sp["longitude"]))
|
|
|
|
| 39 |
if len(coords) > 1:
|
| 40 |
-
folium.PolyLine(coords, color="#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
for _, row in agent_sp.iterrows():
|
| 43 |
folium.CircleMarker(
|
| 44 |
location=[row["latitude"], row["longitude"]],
|
| 45 |
-
radius=
|
| 46 |
popup=folium.Popup(
|
| 47 |
-
f"<b>{row['name']}</b><br>"
|
| 48 |
f"{row['start_datetime'].strftime('%a %m/%d %H:%M')}<br>"
|
| 49 |
f"{int(row['duration_min'])} min",
|
| 50 |
max_width=200
|
| 51 |
)
|
| 52 |
).add_to(m)
|
| 53 |
|
| 54 |
-
# return m.get_root().render()
|
| 55 |
m.get_root().width = "100%"
|
| 56 |
m.get_root().height = "500px"
|
| 57 |
return m._repr_html_()
|
|
|
|
| 31 |
|
| 32 |
# ββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 33 |
def build_map(agent_sp):
|
| 34 |
+
agent_sp = agent_sp.reset_index(drop=True)
|
| 35 |
lat = agent_sp["latitude"].mean()
|
| 36 |
lon = agent_sp["longitude"].mean()
|
| 37 |
m = folium.Map(location=[lat, lon], zoom_start=12, tiles="CartoDB positron")
|
| 38 |
|
| 39 |
+
n = len(agent_sp)
|
| 40 |
coords = list(zip(agent_sp["latitude"], agent_sp["longitude"]))
|
| 41 |
+
|
| 42 |
if len(coords) > 1:
|
| 43 |
+
folium.PolyLine(coords, color="#aaaaaa", weight=1.5, opacity=0.4).add_to(m)
|
| 44 |
+
|
| 45 |
+
for i, row in agent_sp.iterrows():
|
| 46 |
+
# green β red gradient
|
| 47 |
+
ratio = i / max(n - 1, 1)
|
| 48 |
+
r = int(255 * ratio)
|
| 49 |
+
g = int(255 * (1 - ratio))
|
| 50 |
+
color = f"#{r:02x}{g:02x}33"
|
| 51 |
|
|
|
|
| 52 |
folium.CircleMarker(
|
| 53 |
location=[row["latitude"], row["longitude"]],
|
| 54 |
+
radius=7, color=color, fill=True, fill_color=color, fill_opacity=0.9,
|
| 55 |
popup=folium.Popup(
|
| 56 |
+
f"<b>#{i+1} {row['name']}</b><br>"
|
| 57 |
f"{row['start_datetime'].strftime('%a %m/%d %H:%M')}<br>"
|
| 58 |
f"{int(row['duration_min'])} min",
|
| 59 |
max_width=200
|
| 60 |
)
|
| 61 |
).add_to(m)
|
| 62 |
|
|
|
|
| 63 |
m.get_root().width = "100%"
|
| 64 |
m.get_root().height = "500px"
|
| 65 |
return m._repr_html_()
|