Fazle Mawla Wahyuhanda
commited on
Commit
·
a2815a2
1
Parent(s):
33e89d8
update
Browse files- src/streamlit_app.py +111 -0
src/streamlit_app.py
CHANGED
|
@@ -448,6 +448,117 @@ def main():
|
|
| 448 |
else:
|
| 449 |
st.info("Tidak ada menu yang ditemukan sesuai kriteria Anda. Coba sesuaikan filter!")
|
| 450 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
# Jalankan aplikasi jika file dieksekusi langsung
|
| 452 |
if __name__ == "__main__":
|
| 453 |
main()
|
|
|
|
| 448 |
else:
|
| 449 |
st.info("Tidak ada menu yang ditemukan sesuai kriteria Anda. Coba sesuaikan filter!")
|
| 450 |
|
| 451 |
+
# Tambahkan section untuk visualisasi graph
|
| 452 |
+
st.subheader("🔗 Visualisasi Graph Network ITS")
|
| 453 |
+
|
| 454 |
+
# Checkbox untuk menampilkan graph
|
| 455 |
+
show_graph = st.checkbox("Tampilkan visualisasi graph network")
|
| 456 |
+
|
| 457 |
+
if show_graph:
|
| 458 |
+
# Ambil subset graph untuk visualisasi (untuk performa)
|
| 459 |
+
with st.spinner("Memproses visualisasi graph..."):
|
| 460 |
+
# Ambil node subset untuk visualisasi yang lebih ringan
|
| 461 |
+
building_nodes = [n for n in graph.nodes() if graph.nodes[n].get('type') == 'building']
|
| 462 |
+
road_nodes = [n for n in graph.nodes() if graph.nodes[n].get('type') == 'road']
|
| 463 |
+
|
| 464 |
+
# Batasi jumlah road nodes untuk performa
|
| 465 |
+
road_nodes_subset = road_nodes[:50] if len(road_nodes) > 50 else road_nodes
|
| 466 |
+
|
| 467 |
+
# Gabungkan nodes untuk visualisasi
|
| 468 |
+
nodes_to_show = building_nodes + road_nodes_subset
|
| 469 |
+
subgraph = graph.subgraph(nodes_to_show)
|
| 470 |
+
|
| 471 |
+
# Siapkan data untuk plotly
|
| 472 |
+
edge_x = []
|
| 473 |
+
edge_y = []
|
| 474 |
+
edge_info = []
|
| 475 |
+
|
| 476 |
+
for edge in subgraph.edges(data=True):
|
| 477 |
+
x0, y0 = subgraph.nodes[edge[0]]['x'], subgraph.nodes[edge[0]]['y']
|
| 478 |
+
x1, y1 = subgraph.nodes[edge[1]]['x'], subgraph.nodes[edge[1]]['y']
|
| 479 |
+
edge_x.extend([x0, x1, None])
|
| 480 |
+
edge_y.extend([y0, y1, None])
|
| 481 |
+
edge_info.append(f"Length: {edge[2].get('length', 'N/A'):.1f}m")
|
| 482 |
+
|
| 483 |
+
# Data untuk nodes
|
| 484 |
+
node_x = []
|
| 485 |
+
node_y = []
|
| 486 |
+
node_text = []
|
| 487 |
+
node_color = []
|
| 488 |
+
|
| 489 |
+
for node in subgraph.nodes(data=True):
|
| 490 |
+
x, y = node[1]['x'], node[1]['y']
|
| 491 |
+
node_x.append(x)
|
| 492 |
+
node_y.append(y)
|
| 493 |
+
|
| 494 |
+
if node[1].get('type') == 'building':
|
| 495 |
+
node_text.append(f"Building: {node[1].get('name', 'Unknown')}")
|
| 496 |
+
node_color.append('red')
|
| 497 |
+
else:
|
| 498 |
+
node_text.append(f"Road Node: {node[0]}")
|
| 499 |
+
node_color.append('blue')
|
| 500 |
+
|
| 501 |
+
# Buat plot dengan plotly
|
| 502 |
+
fig = go.Figure()
|
| 503 |
+
|
| 504 |
+
# Tambahkan edges
|
| 505 |
+
fig.add_trace(go.Scatter(
|
| 506 |
+
x=edge_x, y=edge_y,
|
| 507 |
+
line=dict(width=1, color='gray'),
|
| 508 |
+
hoverinfo='none',
|
| 509 |
+
mode='lines',
|
| 510 |
+
name='Roads'
|
| 511 |
+
))
|
| 512 |
+
|
| 513 |
+
# Tambahkan nodes
|
| 514 |
+
fig.add_trace(go.Scatter(
|
| 515 |
+
x=node_x, y=node_y,
|
| 516 |
+
mode='markers',
|
| 517 |
+
marker=dict(
|
| 518 |
+
size=8,
|
| 519 |
+
color=node_color,
|
| 520 |
+
line=dict(width=2, color='white')
|
| 521 |
+
),
|
| 522 |
+
text=node_text,
|
| 523 |
+
hoverinfo='text',
|
| 524 |
+
name='Locations'
|
| 525 |
+
))
|
| 526 |
+
|
| 527 |
+
# Update layout
|
| 528 |
+
fig.update_layout(
|
| 529 |
+
title="Graph Network ITS (Building & Road Connections)",
|
| 530 |
+
showlegend=True,
|
| 531 |
+
hovermode='closest',
|
| 532 |
+
margin=dict(b=20,l=5,r=5,t=40),
|
| 533 |
+
annotations=[
|
| 534 |
+
dict(
|
| 535 |
+
text="Red: Buildings, Blue: Road Nodes",
|
| 536 |
+
showarrow=False,
|
| 537 |
+
xref="paper", yref="paper",
|
| 538 |
+
x=0.005, y=-0.002,
|
| 539 |
+
xanchor='left', yanchor='bottom',
|
| 540 |
+
font=dict(size=12)
|
| 541 |
+
)
|
| 542 |
+
],
|
| 543 |
+
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False, title="Longitude"),
|
| 544 |
+
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False, title="Latitude"),
|
| 545 |
+
height=600
|
| 546 |
+
)
|
| 547 |
+
|
| 548 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 549 |
+
|
| 550 |
+
# Tampilkan statistik graph
|
| 551 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 552 |
+
with col1:
|
| 553 |
+
st.metric("Total Nodes", len(graph.nodes()))
|
| 554 |
+
with col2:
|
| 555 |
+
st.metric("Total Edges", len(graph.edges()))
|
| 556 |
+
with col3:
|
| 557 |
+
st.metric("Buildings", len(building_nodes))
|
| 558 |
+
with col4:
|
| 559 |
+
st.metric("Road Nodes", len(road_nodes))
|
| 560 |
+
|
| 561 |
+
|
| 562 |
# Jalankan aplikasi jika file dieksekusi langsung
|
| 563 |
if __name__ == "__main__":
|
| 564 |
main()
|