4
4
import plotly
5
5
import plotly .graph_objs as go
6
6
import pygal
7
- from flask import session , url_for , render_template
7
+ from flask import session , url_for , render_template , request
8
8
from flask_wtf import FlaskForm
9
9
from werkzeug .routing import BuildError
10
10
from wtforms import SelectMultipleField , SubmitField
18
18
from dashboard .routings .measurements import get_heatmap
19
19
20
20
21
- @blueprint .route ('/result/<end>/<int:index>' )
21
+ @blueprint .route ('/result/<end>/<int:index>' , methods = [ 'GET' , 'POST' ] )
22
22
@secure
23
23
def result (end , index = 0 ):
24
24
rule = get_monitor_rule (end )
@@ -36,13 +36,15 @@ def result(end, index=0):
36
36
37
37
# returns a page with the time per version per user
38
38
elif index == 3 :
39
- page = 'endpoint/endpoint_pygal.html'
40
- graph , _ = get_time_per_version_per_user (end , get_versions (end ))
39
+ graph , form = get_time_per_version_per_user (end , get_versions (end ))
40
+ return render_template ('endpoint/endpoint_with_selection.html' , link = config .link , session = session , rule = rule ,
41
+ url = url , graph = graph , end = end , index = index , form = form )
41
42
42
43
# returns a page with the time per version per ip
43
44
elif index == 4 :
44
- page = 'endpoint/endpoint_pygal.html'
45
- graph , _ = get_time_per_version_per_ip (end , get_versions (end ))
45
+ graph , form = get_time_per_version_per_ip (end , get_versions (end ))
46
+ return render_template ('endpoint/endpoint_with_selection.html' , link = config .link , session = session , rule = rule ,
47
+ url = url , graph = graph , end = end , index = index , form = form )
46
48
47
49
# returns a page with the time per version
48
50
elif index == 5 :
@@ -150,20 +152,22 @@ def get_time_per_version_per_user(end, versions):
150
152
for v in versions :
151
153
user_data [d ][v .version ] = 0
152
154
153
- # create a form to select several users
155
+ # create a form to select users
154
156
choices = []
155
157
for d in list (user_data ):
156
158
choices .append ((d , d ))
157
- print (choices )
158
159
159
- class UserForm (FlaskForm ):
160
- users = SelectMultipleField (
160
+ class SelectionForm (FlaskForm ):
161
+ selection = SelectMultipleField (
161
162
'Pick Things!' ,
162
163
choices = choices ,
163
164
)
164
165
submit = SubmitField ('Render graph' )
165
166
166
- user_form = UserForm ()
167
+ form = SelectionForm (request .form )
168
+ selection = []
169
+ if request .method == 'POST' :
170
+ selection = [str (item ) for item in form .data ['selection' ]]
167
171
168
172
# fill the rows with data
169
173
for d in get_endpoint_results (end , FunctionCall .group_by ):
@@ -176,10 +180,12 @@ class UserForm(FlaskForm):
176
180
# add rows to the charts
177
181
for d in [str (c .group_by ) for c in get_endpoint_column (end , FunctionCall .group_by )]:
178
182
data = []
179
- for v in versions :
180
- data .append (user_data [d ][v .version ])
181
- graph .add (d , data , formatter = formatter )
182
- return graph .render_data_uri (), user_form
183
+ # render full graph if no selection is made, else render only the users that are selected
184
+ if selection == [] or d in selection :
185
+ for v in versions :
186
+ data .append (user_data [d ][v .version ])
187
+ graph .add (d , data , formatter = formatter )
188
+ return graph .render_data_uri (), form
183
189
184
190
185
191
def get_time_per_version_per_ip (end , versions ):
@@ -189,20 +195,22 @@ def get_time_per_version_per_ip(end, versions):
189
195
for v in versions :
190
196
ip_data [d ][v .version ] = 0
191
197
192
- # create a form to select several ips
198
+ # create a form to select users
193
199
choices = []
194
200
for d in list (ip_data ):
195
201
choices .append ((d , d ))
196
- print (choices )
197
202
198
- class UserForm (FlaskForm ):
199
- users = SelectMultipleField (
203
+ class SelectionForm (FlaskForm ):
204
+ selection = SelectMultipleField (
200
205
'Pick Things!' ,
201
206
choices = choices ,
202
207
)
203
208
submit = SubmitField ('Render graph' )
204
209
205
- user_form = UserForm ()
210
+ form = SelectionForm (request .form )
211
+ selection = []
212
+ if request .method == 'POST' :
213
+ selection = [str (item ) for item in form .data ['selection' ]]
206
214
207
215
# fill the rows with data
208
216
for d in get_endpoint_results (end , FunctionCall .ip ):
@@ -215,10 +223,12 @@ class UserForm(FlaskForm):
215
223
# add rows to the charts
216
224
for d in [str (c .ip ) for c in get_endpoint_column (end , FunctionCall .ip )]:
217
225
data = []
218
- for v in versions :
219
- data .append (ip_data [d ][v .version ])
220
- graph .add (d , data , formatter = formatter )
221
- return graph .render_data_uri (), user_form
226
+ # render full graph if no selection is made, else render only the users that are selected
227
+ if selection == [] or d in selection :
228
+ for v in versions :
229
+ data .append (ip_data [d ][v .version ])
230
+ graph .add (d , data , formatter = formatter )
231
+ return graph .render_data_uri (), form
222
232
223
233
224
234
def get_time_per_version (end , versions ):
0 commit comments