-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresult_graph.py
140 lines (116 loc) · 4.07 KB
/
result_graph.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
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
# graph: dictionary 형태의 데이터
# n: 한 군집 내 시계열 데이터 개수
# label: 딕셔너리 keys(list형태)
# color: 그래프 line 색
def makeGraph_dictionary(graph, n, label, color):
df=[]
for i in range(0, n):
df.append(graph[label[i]])
fig = go.Figure()
for i in range(0, n):
fig.add_trace(go.Scatter(y=df[i], name=label[i], line=dict(color=color)))
return fig
import math
def makeGraph_Cluster(graph, color):
fig = go.Figure()
for i in range(0, len(graph)):
new_graph = [x for x in graph[i] if math.isnan(x) == False]
fig.add_trace(go.Scatter(y=new_graph, line=dict(color=color), showlegend=False))
return fig
# figure: makeGraph()를 이용해 만든 그래프
# label: 그래프 이름
def updateLayout(figure, name, yaxis='value'):
figure.update_layout(
title=name,
yaxis_title=yaxis,
)
def makeGraph_Detail(graph, color):
new_graph = [x for x in graph if math.isnan(x) == False]
fig = go.Figure(data=go.Scatter(y=new_graph, line=dict(color=color)))
return fig
# figure: makeGraph()를 이용해 만든 그래프
# label: 그래프 이름
def updateLayout_Detail(figure, name, yaxis='value'):
figure.update_layout(
title=name,
yaxis_title=yaxis
)
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
colors = {
'background': 'dimgray',
'text': 'white'
}
def graphCluster(GG):
figs=[]
for i in range(0,len(GG)):
figs.append(makeGraph_Cluster(GG[i],'teal'))
updateLayout(figs[i], 'Cluster'+str(i+1))
# new_fig = go.Figure()
# for i, fig in enumerate(figs):
# new_fig.add_trace(fig, row= (i//3) + 1, col=(i%3)+1)
graph = html.Div(style={ }, children=[
html.Div(["CLUSTERS"], className='subtitle'),
html.Div([
html.Div(
dcc.Graph(id=f'GC{i}', figure=fig),
className='graph graph-hover'
) for i, fig in enumerate(figs)
# html.Div(dcc.Graph(id='GC1', figure=new_fig), className='graph graph-hover')
], className='graphdiv'
)
], className='clusters')
return graph
def graphDetail(nth_cluster, num_graph, GG):
figs=[]
for i in range(0, num_graph):
figs.append(makeGraph_Detail(GG[nth_cluster][i], 'firebrick'))
updateLayout(figs[i], 'Cluster'+str(nth_cluster+1)+' '+str(i+1))
graph = html.Div(style={'height': "500px"}, children=[
html.Div(
[html.Div(
dcc.Graph(id=f'GD{i}', figure=fig),
className='graph'
) for i, fig in enumerate(figs)
]
)
])
return graph
def graphBig(nth_cluster, num_graph, GG):
fig = []
fig.append(makeGraph_Cluster(GG[nth_cluster][:num_graph], 'teal'))
updateLayout(fig[0], 'cluster'+str(nth_cluster))
graph = html.Div(style={}, children=[
html.Div(
[html.Div(
[dcc.Graph(
id='GB1',
figure=fig[0]
)]),
]
)
])
return graph
def textResultDiv(num_cluster, num_tsdatas_per_cluster, siluet_score, used_algorithm, total_time=30):
textdata = html.Div(children=[
html.Div(["SUMMARIZATION"], className='subtitle'),
html.Div([
html.Div(children=f'사용된 알고리즘 : {used_algorithm}'),
html.Hr(),
html.Div(children=f'군집 개수 : {num_cluster}개'),
html.Hr(),
html.Div(children=f'군집별 데이터 개수 : {num_tsdatas_per_cluster}'),
html.Hr(),
html.Div(children=f'실루엣 점수 : {siluet_score}'),
html.Hr(),
html.Div(children=f'총 소요시간 : {total_time}s(초)'),
html.Hr(),
], className='textbox')
])
return textdata