-
Notifications
You must be signed in to change notification settings - Fork 0
/
visual.py
87 lines (73 loc) · 2.95 KB
/
visual.py
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
79
80
81
82
83
84
85
86
87
# Import library
from d3graph import d3graph, vec2adjmat
import boelterMap
import graph
def createVisual(s,e):
print('VISUAL working: ', s, ', ', e)
source = []
target = []
weight = []
s = convertNodeName(s)
e = convertNodeName(e)
boelterG = graph.Graph()
with open('nodes.txt','r') as f:
line = f.readline()
while line:
line = line.rstrip()
if (line and line[0] != '#'):
data = line.split(',')
boelterG.addEdge((convertNodeName(data[0]),convertNodeName(data[1]),int(data[2])))
line = f.readline()
a = boelterG.djikstra(s,e)
with open('nodes.txt','r') as f:
line = f.readline()
while line:
line = line.rstrip()
data = line.split(',')
if (line and line[0] != '#'):
if(convertNodeName(data[0]) in a):
source.append(convertNodeName(data[0]))
target.append(convertNodeName(data[1]))
if(int(data[2]) == 0):
weight.append(0.1)
else:
weight.append(int(data[2]))
line = f.readline()
# Convert to adjacency matrix
adjmat = vec2adjmat(source, target, weight)
# Initialize
d3 = d3graph()
# Proces adjmat
d3.graph(adjmat)
d3.set_node_properties(color='#dcdcdc', fontcolor='#5a4866')
for x in range(len(a)):
d3.node_properties[a[x]]['color']='#9791b5'
d3.node_properties[a[x]]['fontcolor']='#000000'
# Plot
d3.show(filepath='templates/', show_slider=False, showfig = False, overwrite = True)
def convertNodeName(node_name):
if node_name[:4].isdigit():
return "RM" + node_name[:4]
elif len(node_name) == 2 and node_name[1] in ['n', 'e', 's', 'w']:
floor_num = node_name[0]
direction = {'n': 'North', 'e': 'East', 's': 'South', 'w': 'West'}[node_name[1]]
return f"{floor_num}-{direction}_ELEV"
elif len(node_name) > 2 and node_name[1:3] in ['e-', 'w-'] and node_name[3:] in ['n', 'ne', 'nw', 's', 'se', 'sw']:
floor_num = node_name[0]
direction = node_name[3:].replace('ne', 'Northeast').replace('nw', 'Northwest').replace('se', 'Southeast').replace('sw', 'Southwest').title()
return f"{floor_num}-{direction}_ELEV"
elif node_name == "COS":
return "Court_of_Sciences"
elif node_name[:4] == "COS-":
direction = {'n': 'North', 'e': 'East', 's': 'South', 'w': 'West', 'm': 'Middle'}[node_name[-1]]
return f"{direction}_Court_of_Sciences"
elif node_name == "BOMB":
return "Bomb_Shelter"
elif node_name == "e4":
return "Engineering_4"
elif node_name == "m":
return "MATHSCI"
elif node_name.startswith("m") and node_name[1:].isdigit():
return f"MATHSCI{node_name[1:]}"
else:
return node_name