Spaces:
Build error
Build error
elli-teu
commited on
Commit
·
d18dba3
1
Parent(s):
227f85a
Added colors and legend
Browse files
app.py
CHANGED
|
@@ -207,6 +207,40 @@ def visualize(filtered_data, stop_name):
|
|
| 207 |
4:'Crushed standing room',
|
| 208 |
5: 'Full'}
|
| 209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
# Create a folium map centered around a location
|
| 211 |
m = folium.Map(location=[filtered_data.iloc[0]["stop_lat"], filtered_data.iloc[0]["stop_lon"]], zoom_start=12)
|
| 212 |
|
|
@@ -222,7 +256,49 @@ def visualize(filtered_data, stop_name):
|
|
| 222 |
[row['stop_lat'], row['stop_lon']],
|
| 223 |
|
| 224 |
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 225 |
-
icon = folium.Icon(color="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
).add_to(m)
|
| 227 |
else:
|
| 228 |
folium.Marker(
|
|
@@ -230,9 +306,19 @@ def visualize(filtered_data, stop_name):
|
|
| 230 |
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 231 |
icon = folium.Icon(icon="bus-simple", prefix="fa")
|
| 232 |
).add_to(m)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
|
|
|
|
|
|
|
|
|
| 234 |
# Display the map
|
| 235 |
-
st_folium(m, width=700, height=500)
|
| 236 |
|
| 237 |
def drop_the_duplicates(df):
|
| 238 |
|
|
|
|
| 207 |
4:'Crushed standing room',
|
| 208 |
5: 'Full'}
|
| 209 |
|
| 210 |
+
legend_html = '''
|
| 211 |
+
<style>
|
| 212 |
+
.legend-box {
|
| 213 |
+
position: relative;
|
| 214 |
+
width: 250px;
|
| 215 |
+
background-color: white;
|
| 216 |
+
padding: 10px;
|
| 217 |
+
border: 2px solid grey;
|
| 218 |
+
border-radius: 5px;
|
| 219 |
+
font-size: 14px;
|
| 220 |
+
}
|
| 221 |
+
.legend-box div {
|
| 222 |
+
margin-bottom: 5px;
|
| 223 |
+
}
|
| 224 |
+
.legend-box i {
|
| 225 |
+
width: 20px;
|
| 226 |
+
height: 10px;
|
| 227 |
+
display: inline-block;
|
| 228 |
+
margin-right: 5px;
|
| 229 |
+
}
|
| 230 |
+
</style>
|
| 231 |
+
<div class="legend-box">
|
| 232 |
+
<b>Occupancy Legend:</b><br>
|
| 233 |
+
<div><i style="background: green;"></i>Empty</div>
|
| 234 |
+
<div><i style="background: blue;"></i>Many seats available</div>
|
| 235 |
+
<div><i style="background: purple;"></i>Few seats available</div>
|
| 236 |
+
<div><i style="background: pink;"></i>Standing room only</div>
|
| 237 |
+
<div><i style="background: orange;"></i>Crushed standing room</div>
|
| 238 |
+
<div><i style="background: red;"></i>Full</div>
|
| 239 |
+
<div><i style="background: black;"></i>Your stop</div>
|
| 240 |
+
</div>
|
| 241 |
+
'''
|
| 242 |
+
#st.markdown(legend_html, unsafe_allow_html=True)
|
| 243 |
+
|
| 244 |
# Create a folium map centered around a location
|
| 245 |
m = folium.Map(location=[filtered_data.iloc[0]["stop_lat"], filtered_data.iloc[0]["stop_lon"]], zoom_start=12)
|
| 246 |
|
|
|
|
| 256 |
[row['stop_lat'], row['stop_lon']],
|
| 257 |
|
| 258 |
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 259 |
+
icon = folium.Icon(color="black", icon="bus-simple", prefix="fa")
|
| 260 |
+
).add_to(m)
|
| 261 |
+
elif row['vehicle_occupancystatus'] == 0:
|
| 262 |
+
folium.Marker(
|
| 263 |
+
[row['stop_lat'], row['stop_lon']],
|
| 264 |
+
|
| 265 |
+
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 266 |
+
icon = folium.Icon(color="green", icon="bus-simple", prefix="fa")
|
| 267 |
+
).add_to(m)
|
| 268 |
+
elif row['vehicle_occupancystatus'] == 1:
|
| 269 |
+
folium.Marker(
|
| 270 |
+
[row['stop_lat'], row['stop_lon']],
|
| 271 |
+
|
| 272 |
+
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 273 |
+
icon = folium.Icon(color="blue", icon="bus-simple", prefix="fa")
|
| 274 |
+
).add_to(m)
|
| 275 |
+
elif row['vehicle_occupancystatus'] == 2:
|
| 276 |
+
folium.Marker(
|
| 277 |
+
[row['stop_lat'], row['stop_lon']],
|
| 278 |
+
|
| 279 |
+
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 280 |
+
icon = folium.Icon(color="purple", icon="bus-simple", prefix="fa")
|
| 281 |
+
).add_to(m)
|
| 282 |
+
elif row['vehicle_occupancystatus'] == 3:
|
| 283 |
+
folium.Marker(
|
| 284 |
+
[row['stop_lat'], row['stop_lon']],
|
| 285 |
+
|
| 286 |
+
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 287 |
+
icon = folium.Icon(color="pink", icon="bus-simple", prefix="fa")
|
| 288 |
+
).add_to(m)
|
| 289 |
+
elif row['vehicle_occupancystatus'] == 4:
|
| 290 |
+
folium.Marker(
|
| 291 |
+
[row['stop_lat'], row['stop_lon']],
|
| 292 |
+
|
| 293 |
+
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 294 |
+
icon = folium.Icon(color="orange", icon="bus-simple", prefix="fa")
|
| 295 |
+
).add_to(m)
|
| 296 |
+
elif row['vehicle_occupancystatus'] == 5:
|
| 297 |
+
folium.Marker(
|
| 298 |
+
[row['stop_lat'], row['stop_lon']],
|
| 299 |
+
|
| 300 |
+
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 301 |
+
icon = folium.Icon(color="red", icon="bus-simple", prefix="fa")
|
| 302 |
).add_to(m)
|
| 303 |
else:
|
| 304 |
folium.Marker(
|
|
|
|
| 306 |
popup=f"Bus stop: {row['stop_name']} Bus occupancy: {categories[row['vehicle_occupancystatus']] }",
|
| 307 |
icon = folium.Icon(icon="bus-simple", prefix="fa")
|
| 308 |
).add_to(m)
|
| 309 |
+
|
| 310 |
+
# Layout: Split screen into two columns
|
| 311 |
+
col1, col2 = st.columns([3, 1]) # Adjust proportions (3:1) as needed
|
| 312 |
+
|
| 313 |
+
# Display Folium map in the first column
|
| 314 |
+
with col1:
|
| 315 |
+
st_folium(m, width=700, height=500)
|
| 316 |
|
| 317 |
+
# Display Legend in the second column
|
| 318 |
+
with col2:
|
| 319 |
+
st.markdown(legend_html, unsafe_allow_html=True)
|
| 320 |
# Display the map
|
| 321 |
+
#st_folium(m, width=700, height=500)
|
| 322 |
|
| 323 |
def drop_the_duplicates(df):
|
| 324 |
|