-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNetworkGraph.py
135 lines (112 loc) · 3.06 KB
/
NetworkGraph.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from cProfile import label
import plotly.offline
from Classes import Utils
from dash import Dash, html, callback, Input, Output
import dash_cytoscape as cyto
from Classes.Student import Student
cyto.load_extra_layouts()
groups = Utils.getGroups()
groupList = ["redacted"]
groupsIWant = []
for group in groups:
if group.departmentOfBranch == "redacted":
groupsIWant.append(group)
students = []
for group in groupsIWant:
students += Utils.getStudentsInGroup(group.id)
studentNodeData = [(student.student, student.fullName, student.mainGroup) for student in students]
studentNodes = [
{
'data': {'id': short, 'label': label, 'parent': str(mainGroup)},
'classes': 'student'
}
for short, label, mainGroup in studentNodeData
]
mainGroups = set()
for student in students:
mainGroups.add([group for group in groups if group.id == student.mainGroup][0])
mainGroupNodes = [
{
'data': {'id': str(group.id), 'label': group.extendedName}
}
for group in mainGroups
]
groupsIWant = [group for group in groupsIWant if group not in mainGroups]
groupNodes = [
{
'data': {'id': str(group.id), 'label': group.extendedName},
'classes': 'group'
}
for group in groupsIWant
]
groupEdgeData = [(str(group.id), student.student) for student in students for group in groupsIWant if group.id in student.groupInDepartments]
edges = [
{
'data': {'source': edge[0], 'target': edge[1]}
}
for edge in groupEdgeData
]
elements = studentNodes + groupNodes + edges + mainGroupNodes
defaultStyleSheet = [
{
'selector': 'node',
'style': {'content': 'data(label)'}
},
{
'selector': '.group',
'style': {
'label': 'data(label)',
'background-color': '#0024FF'
}
},
{
'selector': '.student',
'style': {
'label': 'data(label)',
'background-color': '#FF0000'
}
},
{
'selector': 'edge',
'style': {
'line-color': 'rgb(150, 150, 150)',
'line-opacity': 0.05
}
},
{
'selector': ':selected',
'style': {
'background-color': '#FFD500',
'line-color': '#FFD500'
}
}
]
app = Dash()
app.layout = html.Div([
cyto.Cytoscape(
id='studentGraph',
layout={
'name': 'cose-bilkent',
'quality': 'proof',
'nodeDimensionsIncludeLabels': True,
'fit': True,
'idealEdgeLength': 100,
'edgeElasticity': 0.001,
'padding': 20,
# 'animate': False,
# 'random': True,
# 'fit': False,
# 'gravity': 0.5,
# 'nodeRepulsion': 400000,
# 'edgeElasticity': 1000,
# 'idealEdgeLength': 100,
# 'initialTemp': 20,
# 'nodeOverlap': 20,
},
style={'width': '100vw', 'height': '100vh'},
elements=elements,
stylesheet=defaultStyleSheet
)
])
if __name__ == '__main__':
app.run(debug=True)