-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
78 lines (63 loc) · 2.91 KB
/
main.py
File metadata and controls
78 lines (63 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import folium
import networkx as nx
from nodes import nodes
from edges import links
# -------------------- BUILD NETWORK GRAPH --------------------
# Create a geographic graph
G = nx.Graph()
# Add all nodes to the graph with positions
for node, attributes in nodes.items():
G.add_node(attributes.uid, pos=attributes.position)
# Add all links to the graph
for link in links:
G.add_edge(link.start_uid, link.end_uid, label=link.label, length=link.length, transmission=link.transmission, link_type=link.link_type)
# -------------------- CREATE FOLIUM MAP --------------------
# Create a Folium map centered around Boston
m = folium.Map(location=[42.3601, -71.0589], zoom_start=5, tiles='cartodb positron')
# Add nodes to the map with detailed labels
for node, attributes in nodes.items():
lat, lon = attributes.position
info = (
f"{attributes.name}<br>"
f"Memory type: {attributes.memory_type}<br>"
f"Cooling: {attributes.cooling}<br>"
f"T2: {attributes.T2}<br>"
f"Status: {attributes.status}<br>"
f"Participants: {attributes.participants}<br>"
f"Technologies: {', '.join(attributes.technologies)}"
)
folium.Marker(location=[lat, lon], popup=info, icon=folium.Icon(color='blue')).add_to(m)
# Add edges to the map with curved lines
def add_curved_edge(start, end, label, color='blue', dash_array=None):
try:
start_node = G.nodes[start]
end_node = G.nodes[end]
# Create a curved line effect by adding intermediary points
mid_point = [(start_node['pos'][0] + end_node['pos'][0]) / 2, (start_node['pos'][1] + end_node['pos'][1]) / 2 + 0.01] # Adjust for curvature
locations = [start_node['pos'], mid_point, end_node['pos']]
folium.PolyLine(locations=locations, color=color, weight=2.5, dash_array=dash_array, popup=label).add_to(m)
except KeyError as e:
print(f"KeyError: {e} for edge from {start} to {end}")
print(f"Start node data: {G.nodes[start]}")
print(f"End node data: {G.nodes[end]}")
# Add existing links (solid blue lines)
for edge in G.edges(data=True):
add_curved_edge(edge[0], edge[1], edge[2]['label'], color='blue')
# Add planned links (dashed red lines)
add_curved_edge("MIT-FH576-A", "UA", "Planned Link: Joint Device Development", color='red', dash_array='5, 5')
# -------------------- ADD LEGEND --------------------
# Create a legend for the map
legend_html = """
<div style="position: fixed;
bottom: 50px; left: 50px; width: 200px; height: auto;
background-color: white; border:2px solid grey; z-index:9999;
font-size:14px; padding: 10px;">
 <b>Legend</b><br>
 <i style="color:blue;">●</i> Existing Edge<br>
 <i style="color:red;">●</i> Planned Link<br>
 <i style="color:gray;">●</i> Fiber Connection<br>
</div>
"""
m.get_root().html.add_child(folium.Element(legend_html))
# Save the map
m.save("boston_network_map.html")