-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
172 lines (151 loc) · 6.34 KB
/
app.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import os
import json
import random
import numpy as np
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
from util import plot_users, plot_network, plot_clusters, plot_closeness
from flask import render_template
def render_tab(name, res_dict):
tab_style = {
'padding-top': '15px',
'height': 50,
'margin-top': 20,
'margin-bottom': 2,
'margin-left': 2,
'margin-right': 2,
'background-color': 'rgba(256, 256, 256, 0.8)',
'border-style': 'solid',
'border-radius': 7,
'border-width': 0,
'border-color': 'white',
'overflow': 'hidden',
'width': '45%'
}
tab_style_selected = {
'padding-top': '15px',
'align-items': 'center',
'height': 50,
'margin-top': 20,
'margin-bottom': 2,
'margin-left': 2,
'margin-right': 2,
'background-color': '#ffffff',
'border-style': 'solid',
'border-radius': 7,
'border-width': 2,
'border-color': '#3b738f',
'overflow': 'hidden',
'width': '55%'
}
return dcc.Tab(
label=name,
style=tab_style,
selected_style=tab_style_selected,
children=[
html.Div(className="div-btm", children=[
html.Div(className="div-btm-inner", children=[
html.Div(className="div-network-graph", children=[
html.Div(className="div-graph-btm", children=[
html.Div(html.Span('Network Graph', className="graph-title"), className="div-graph-title"),
dcc.Graph(
className='graph-network',
config={'displayModeBar': False},
figure=plot_network(
np.array(res_dict['adjacencym']),
res_dict['clusters'],
res_dict['cluster_names'],
{int(key): value for key, value in res_dict['id_to_name'].items()},
seed)
)
])
]),
html.Div(className="div-mma-graph", children=[
html.Div(className="div-graph-btm", children=[
html.Div(html.Span('Avg-Max-Min', className="graph-title"), className="div-graph-title"),
dcc.Graph(
className='graph-mma',
config={'displayModeBar': False},
figure=plot_clusters(
res_dict['cluster_size'],
res_dict['cluster_max'],
res_dict['cluster_min'],
res_dict['cluster_avg'],
res_dict['cluster_names'])
)
])
]),
html.Div(className="div-heatmap-graph", children=[
html.Div(className="div-graph-btm", children=[
html.Div(className="div-graph-btm", children=[
html.Div(html.Span('Closeness Between Clusters', className="graph-title"), className="div-graph-title"),
dcc.Graph(
className='graph-heatmap',
config={'displayModeBar': False},
figure=plot_closeness(
res_dict['closeness'])
)
])
])
])
])
])
])
app = dash.Dash(__name__)
server = app.server
app.title = 'Network Analysis'
with open(os.path.join('output', 'cluster1.json')) as f:
group1 = json.load(f)
with open(os.path.join('output', 'cluster2.json')) as f:
group2 = json.load(f)
user_stats = pd.read_csv(os.path.join('output', 'user_stats.csv'), header=0, index_col=0)
user_stats.columns = [0, 1, 2, 3]
seed = random.randint(1, 100)
app.layout = html.Div([
html.Div(className="div-top", children=[
html.Div(className="div-top-inner", children=[
html.Div(className="div-desc", children=[
html.Div(className="div-title",
children=html.Span(className="title", children='Network Analysis')
),
html.Div(className="div-desc-inner", children=[
html.Div(className="links", children=[
html.A(
'',
href='#',
),
html.A(
'Check code',
href='https://github.com/gautam-sankalp/software-engineering-project',
target="_blank"
),
]),
html.Div(className="caption", children="On the plot, click and drag to zoom in, double click to rescale."),
html.Div(className="caption", children="On the legend, click or double click to filter."),
html.Div(className="caption", children='Usernames in the network are masked with randomly generated string.')
])
]),
html.Div(className="div-user-graph", children=[
html.Div(className="div-graph-top", children=[
html.Div(html.Span('Percentage of Mutual Connection', className="graph-title"), className="div-graph-title"),
dcc.Graph(
className='graph-user',
config={'displayModeBar': False},
figure=plot_users(user_stats)
)
])
])
])
]),
dcc.Tabs(
parent_className='custom-tabs',
className='custom-tabs-container',
children=[
render_tab('No. of clusters = 8', group1),
render_tab('No. of clusters = 16', group2)
])
])
if __name__ == '__main__':
app.run_server(debug=True)